Browse Source

improve binflop file encoding & improve logging

master
Purpur 4 years ago
committed by GitHub
parent
commit
85e7ed15ef
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 11
      bot.py

11
bot.py

@ -8,7 +8,6 @@ from discord.ext import commands, tasks
from discord.ext.commands import has_permissions, MissingPermissions from discord.ext.commands import has_permissions, MissingPermissions
from dotenv import load_dotenv from dotenv import load_dotenv
import aiohttp import aiohttp
from unidecode import unidecode
# import subprocess # import subprocess
@ -37,13 +36,8 @@ async def on_message(message):
if len(message.attachments) > 0: if len(message.attachments) > 0:
if not message.attachments[0].url.endswith( if not message.attachments[0].url.endswith(
('.png', '.jpg', '.jpeg', '.mp4', '.mov', '.avi', '.gif', '.image', '.svg')): ('.png', '.jpg', '.jpeg', '.mp4', '.mov', '.avi', '.gif', '.image', '.svg')):
download = message.attachments[0].url
async with aiohttp.ClientSession() as session:
async with session.get(download, allow_redirects=True) as r:
# r = requests.get(download, allow_redirects=True)
text = await r.text()
text = unidecode(text)
text = await discord.Attachment.read(message.attachments[0], use_cached=False)
text = text.decode('Latin-1')
text = "\n".join(text.splitlines()) text = "\n".join(text.splitlines())
if '' not in text: # If it's not an image/gif if '' not in text: # If it's not an image/gif
truncated = False truncated = False
@ -60,6 +54,7 @@ async def on_message(message):
embed_var = discord.Embed(title="Please use a paste service", color=0x1D83D4) embed_var = discord.Embed(title="Please use a paste service", color=0x1D83D4)
embed_var.description = response embed_var.description = response
await message.channel.send(embed=embed_var) await message.channel.send(embed=embed_var)
logging.info(f'File uploaded by {message.author} ({message.author.id}): https://bin.birdflop.com/{key}')
timings = bot.get_cog('Timings') timings = bot.get_cog('Timings')
await timings.analyze_timings(message) await timings.analyze_timings(message)
await bot.process_commands(message) await bot.process_commands(message)

Loading…
Cancel
Save