mirror of
git://git.acid.vegas/scroll.git
synced 2024-11-22 08:06:39 +00:00
Fixed character decoding (reported by ab3800, cheers)
This commit is contained in:
parent
2d0600dd71
commit
4f4e3446bc
63
scroll.py
63
scroll.py
@ -161,35 +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']))
|
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.read().decode(chardet.detect(ascii.read())['encoding'])
|
ascii = ascii.readlines()
|
||||||
if len(ascii.splitlines()) > 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.splitlines():
|
for line in ascii:
|
||||||
line = line.replace('\n','').replace('\r','') # do we need this
|
if type(line) == bytes:
|
||||||
await self.sendmsg(chan, line + reset)
|
try:
|
||||||
await asyncio.sleep(self.settings['msg'])
|
line = line.decode()
|
||||||
else:
|
except UnicodeError:
|
||||||
await self.irc_error(chan, 'invalid name', name) if not img and not paste else await self.irc_error(chan, 'invalid url', name)
|
line = line.decode(chardet.detect(line)['encoding']).encode().decode() # TODO: Do we need to re-encode/decode in UTF-8?
|
||||||
except Exception as ex:
|
line = line.replace('\n','').replace('\r','')
|
||||||
try:
|
await self.sendmsg(chan, line + reset)
|
||||||
await self.irc_error(chan, 'error in play function', ex)
|
await asyncio.sleep(self.settings['msg'])
|
||||||
except:
|
else:
|
||||||
error('error in play function', ex)
|
await self.irc_error(chan, 'invalid name', name) if not img and not paste else await self.irc_error(chan, 'invalid url', name)
|
||||||
finally:
|
except Exception as ex:
|
||||||
self.playing = False
|
try:
|
||||||
|
await self.irc_error(chan, 'error in play function', ex)
|
||||||
|
except:
|
||||||
|
error('error in play function', ex)
|
||||||
|
finally:
|
||||||
|
self.playing = False
|
||||||
|
|
||||||
async def listen(self):
|
async def listen(self):
|
||||||
while True:
|
while True:
|
||||||
|
Loading…
Reference in New Issue
Block a user