diff --git a/README.md b/README.md index 7d2ae20..7ba277a 100644 --- a/README.md +++ b/README.md @@ -11,16 +11,17 @@ There is no API key needed, no local art files needed, & no reason to not setup * [chardet](https://pypi.org/project/chardet/) *(`pip install chardet`)* ## Commands -| Command | Description | -| ------------------------ | --------------------------------------------------------- | -| `@scroll` | information about scroll | -| `.ascii ` | play the \ art file | -| `.ascii dirs` | list of art directories | -| `.ascii list` | list of art filenames | -| `.ascii random [dir]` | play random art, optionally from the [dir] directory only | -| `.ascii search ` | search for art diles that match \ | -| `.ascii stop` | stop playing art | -| `.ascii sync` | sync the ascii database to pump the newest art | +| Command | Description | +| ------------------------ | ---------------------------------------------------------- | +| `@scroll` | information about scroll | +| `.ascii ` | play the \ art file | +| `.ascii dirs` | list of art directories | +| `.ascii list` | list of art filenames | +| `.ascii play ` | play the contents of \ *(must be a raw pastebin url)* | +| `.ascii random [dir]` | play random art, optionally from the [dir] directory only | +| `.ascii search ` | search for art diles that match \ | +| `.ascii stop` | stop playing art | +| `.ascii sync` | sync the ascii database to pump the newest art | **NOTE**: You can do `.ascii help` to play the [help.txt](https://github.com/ircart/ircart/blob/master/ircart/doc/help.txt) file in your channel. diff --git a/scroll.py b/scroll.py index bb4677f..a4e05c6 100644 --- a/scroll.py +++ b/scroll.py @@ -29,6 +29,7 @@ class throttle: max_lines = 300 # maximum number of lines in art file to be played outside of #scroll message = 0.03 # delay between each line sent results = 25 # maximum number of results returned from search + pastes = True # toggle the .ascii play command # Formatting Control Characters / Color Codes bold = '\x02' @@ -141,10 +142,12 @@ class Bot(): finally: self.db = cache - async def play(self, chan, name): + async def play(self, chan, name, paste=None): try: - print(name) - ascii = urllib.request.urlopen(f'https://raw.githubusercontent.com/ircart/ircart/master/ircart/{name}.txt', timeout=10) + if paste: + ascii = urllib.request.urlopen(name), timeout=10) + else: + ascii = urllib.request.urlopen(f'https://raw.githubusercontent.com/ircart/ircart/master/ircart/{name}.txt', timeout=10) if ascii.getcode() == 200: ascii = ascii.readlines() if len(ascii) > throttle.max_lines and chan != '#scroll': @@ -232,6 +235,12 @@ class Bot(): elif msg == '.ascii sync': await self.sync() await self.sendmsg(chan, bold + color('database synced', light_green)) + elif args[1] == 'play' and len(args) == 3 and throttle.pastes: + url = args[2] + if url.startswith('https://pastebin.com/raw/') and len(url.split('raw/')) > 1: + self.loops[chan] = asyncio.create_task(self.play(chan, url, paste=True)) + else: + await self.irc_error(chan 'invalid pastebin url', paste) elif args[1] == 'random' and len(args) == 3: dir = args[2] if dir in self.db: