scroll

- irc bot to play ascii art
git clone git://git.acid.vegas/scroll.git
Log | Files | Refs | Archive | README | LICENSE

commit 24a3e1b1fc1d6f1449d7d385c055eb20da702aee
parent a669fec7a58ef5c910f551ea916c7eda01bb9ff2
Author: acidvegas <acid.vegas@acid.vegas>
Date: Wed, 7 Jun 2023 00:17:40 -0400

Added .ascii play <url> command to play art off of Pastebin

Diffstat:
MREADME.md | 21+++++++++++----------
Mscroll.py | 15++++++++++++---

2 files changed, 23 insertions(+), 13 deletions(-)

diff --git 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 <name>`          | play the \<name> 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 <query>`  | search for art diles that match \<query>                  |
-| `.ascii stop`            | stop playing art                                          |
-| `.ascii sync`            | sync the ascii database to pump the newest art            |
+| Command                  | Description                                                |
+| ------------------------ | ---------------------------------------------------------- |
+| `@scroll`                | information about scroll                                   |
+| `.ascii <name>`          | play the \<name> art file                                  |
+| `.ascii dirs`            | list of art directories                                    |
+| `.ascii list`            | list of art filenames                                      |
+| `.ascii play <url>`      | play the contents of \<url> *(must be a raw pastebin url)* |
+| `.ascii random [dir]`    | play random art, optionally from the [dir] directory only  |
+| `.ascii search <query>`  | search for art diles that match \<query>                   |
+| `.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
@@ -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: