TextArt: try/except content decoding

This commit is contained in:
Gordon Shumway 2021-03-31 05:32:25 -04:00 committed by GitHub
parent db51fe1404
commit b1f78a1588
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1119,7 +1119,10 @@ class TextArt(callbacks.Plugin):
log.debug("TextArt: error retrieving data for scroll: {0}".format(e))
return
if "text/plain" in r.headers["content-type"]:
file = r.content.decode().replace("\r\n", "\n")
try:
file = r.content.decode().replace("\r\n", "\n")
except:
file = r.text.replace("\r\n", "\n")
else:
irc.reply("Invalid file type.", private=False, notice=False)
return
@ -1749,7 +1752,10 @@ class TextArt(callbacks.Plugin):
irc.reply("Error: No results found for {0}".format(search))
return
data = requests.get(url.get("href"), headers=header, timeout=10)
output = data.content.decode()
try:
output = data.content.decode()
except:
output = data.text
output = output.splitlines()
asyncio.run(self.reply(irc, output, channel, delay))
irc.reply(url.get("href"))