|
@ -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,29 +36,25 @@ 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 = "\n".join(text.splitlines()) |
|
|
|
|
|
if '�' not in text: # If it's not an image/gif |
|
|
|
|
|
truncated = False |
|
|
|
|
|
if len(text) > 100000: |
|
|
|
|
|
text = text[:99999] |
|
|
|
|
|
truncated = True |
|
|
|
|
|
req = requests.post('https://bin.birdflop.com/documents', data=text) |
|
|
|
|
|
key = json.loads(req.content)['key'] |
|
|
|
|
|
response = "" |
|
|
|
|
|
response = response + "https://bin.birdflop.com/" + key |
|
|
|
|
|
response = response + "\nRequested by " + message.author.mention |
|
|
|
|
|
if truncated: |
|
|
|
|
|
response = response + "\n(file was truncated because it was too long.)" |
|
|
|
|
|
embed_var = discord.Embed(title="Please use a paste service", color=0x1D83D4) |
|
|
|
|
|
embed_var.description = response |
|
|
|
|
|
await message.channel.send(embed=embed_var) |
|
|
|
|
|
|
|
|
text = await discord.Attachment.read(message.attachments[0], use_cached=False) |
|
|
|
|
|
text = text.decode('Latin-1') |
|
|
|
|
|
text = "\n".join(text.splitlines()) |
|
|
|
|
|
if '�' not in text: # If it's not an image/gif |
|
|
|
|
|
truncated = False |
|
|
|
|
|
if len(text) > 100000: |
|
|
|
|
|
text = text[:99999] |
|
|
|
|
|
truncated = True |
|
|
|
|
|
req = requests.post('https://bin.birdflop.com/documents', data=text) |
|
|
|
|
|
key = json.loads(req.content)['key'] |
|
|
|
|
|
response = "" |
|
|
|
|
|
response = response + "https://bin.birdflop.com/" + key |
|
|
|
|
|
response = response + "\nRequested by " + message.author.mention |
|
|
|
|
|
if truncated: |
|
|
|
|
|
response = response + "\n(file was truncated because it was too long.)" |
|
|
|
|
|
embed_var = discord.Embed(title="Please use a paste service", color=0x1D83D4) |
|
|
|
|
|
embed_var.description = response |
|
|
|
|
|
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) |
|
|