Indent fixed and play function fixed

This commit is contained in:
Dionysus 2024-01-02 19:57:24 -05:00
parent 4f4e3446bc
commit 4b2dd58fdc
Signed by: acidvegas
GPG Key ID: EF4B922DB85DC9DE
1 changed files with 34 additions and 34 deletions

View File

@ -161,40 +161,40 @@ class Bot():
finally: finally:
self.db = cache self.db = cache
async def play(self, chan, name, img=False, paste=False): async def play(self, chan, name, img=False, paste=False):
try: try:
if img or paste: if img or paste:
ascii = get_url(name) ascii = get_url(name)
else: else:
ascii = get_url(f'https://raw.githubusercontent.com/ircart/ircart/master/ircart/{name}.txt') ascii = get_url(f'https://raw.githubusercontent.com/ircart/ircart/master/ircart/{name}.txt')
if ascii.getcode() == 200: if ascii.getcode() == 200:
if img: if img:
ascii = img2irc.convert(ascii.read(), img, int(self.settings['png_width']), self.settings['png_palette'], int(self.settings['png_quantize_colors'])) ascii = img2irc.convert(ascii.read(), img, int(self.settings['png_width']), self.settings['png_palette'], int(self.settings['png_quantize_colors']))
else: else:
ascii = ascii.readlines() ascii = ascii.readlines()
if len(ascii) > int(self.settings['lines']) and chan != '#scroll': if len(ascii) > int(self.settings['lines']) and chan != '#scroll':
await self.irc_error(chan, 'file is too big', f'take those {len(ascii):,} lines to #scroll') await self.irc_error(chan, 'file is too big', f'take those {len(ascii):,} lines to #scroll')
else: else:
if not img and not paste: if not img and not paste:
await self.action(chan, 'the ascii gods have chosen... ' + color(name, cyan)) await self.action(chan, 'the ascii gods have chosen... ' + color(name, cyan))
for line in ascii: for line in ascii:
if type(line) == bytes: if type(line) == bytes:
try: try:
line = line.decode() line = line.decode()
except UnicodeError: except UnicodeError:
line = line.decode(chardet.detect(line)['encoding']).encode().decode() # TODO: Do we need to re-encode/decode in UTF-8? line = line.decode(chardet.detect(line)['encoding']).encode().decode() # TODO: Do we need to re-encode/decode in UTF-8?
line = line.replace('\n','').replace('\r','') line = line.replace('\n','').replace('\r','')
await self.sendmsg(chan, line + reset) await self.sendmsg(chan, line + reset)
await asyncio.sleep(self.settings['msg']) await asyncio.sleep(self.settings['msg'])
else: else:
await self.irc_error(chan, 'invalid name', name) if not img and not paste else await self.irc_error(chan, 'invalid url', name) await self.irc_error(chan, 'invalid name', name) if not img and not paste else await self.irc_error(chan, 'invalid url', name)
except Exception as ex: except Exception as ex:
try: try:
await self.irc_error(chan, 'error in play function', ex) await self.irc_error(chan, 'error in play function', ex)
except: except:
error('error in play function', ex) error('error in play function', ex)
finally: finally:
self.playing = False self.playing = False
async def listen(self): async def listen(self):
while True: while True: