From e33b8ebc53c2cef48bc3e75a56a7b8bbb919afe3 Mon Sep 17 00:00:00 2001 From: Purpur <43528123+Pemigrade@users.noreply.github.com> Date: Sat, 30 Jan 2021 21:26:35 -0600 Subject: [PATCH 01/16] Delete linking_updater_panel.py --- cogs/linking_updater_panel.py | 115 ---------------------------------- 1 file changed, 115 deletions(-) delete mode 100644 cogs/linking_updater_panel.py diff --git a/cogs/linking_updater_panel.py b/cogs/linking_updater_panel.py deleted file mode 100644 index 9f61b86..0000000 --- a/cogs/linking_updater_panel.py +++ /dev/null @@ -1,115 +0,0 @@ -import os -import discord -import requests -import json -import logging -from discord.ext import commands, tasks -from discord.ext.commands import has_permissions, MissingPermissions -from dotenv import load_dotenv -import aiohttp -import asyncio - -class Linking_updater(commands.Cog): - - def __init__(self, bot): - self.bot = bot - self.guild_id = int(os.getenv('guild_id')) - self.crabwings_role_id = int(os.getenv('crabwings_role_id')) - self.duckfeet_role_id = int(os.getenv('duckfeet_role_id')) - self.elktail_role_id = int(os.getenv('elktail_role_id')) - self.client_role_id = int(os.getenv('client_role_id')) - self.subuser_role_id = int(os.getenv('subuser_role_id')) - self.verified_role_id = int(os.getenv('verified_role_id')) - - @tasks.loop(minutes=10) - async def linking_updater(self): - logging.info("Synchronizing roles") - file = open('users.json', 'r') - data = json.load(file) - file.close() - guild = self.bot.get_guild(self.guild_id) - i = -1 - for client in data['users']: - i += 1 - member = guild.get_member(client['discord_id']) - if member: - api_key = client['client_api_key'] - url = "https://panel.birdflop.com/api/client" - headers = { - 'Accept': 'application/json', - 'Authorization': 'Bearer ' + api_key, - } - async with aiohttp.ClientSession() as session: - async with session.get(url, headers=headers) as response: - if response.status == 200: - # Formats response for servers in JSON format - servers_json_response = await response.json() - - user_client = False - user_subuser = False - user_crabwings = False - user_duckfeet = False - user_elktail = False - for server in servers_json_response['data']: - server_owner = server['attributes']['server_owner'] - if server_owner == True: - user_client = True - elif server_owner == False: - user_subuser = True - server_node = server['attributes']['node'] - if server_node == "Crabwings - NYC": - user_crabwings = True - elif server_node == "Duckfeet - EU": - user_duckfeet = True - elif server_node == "Elktail - EU": - user_elktail = True - role = discord.utils.get(guild.roles, id=self.client_role_id) - if user_client == True: - await member.add_roles(role) - else: - await member.remove_roles(role) - role = discord.utils.get(guild.roles, id=self.subuser_role_id) - if user_subuser == True: - await member.add_roles(role) - else: - await member.remove_roles(role) - role = discord.utils.get(guild.roles, id=self.crabwings_role_id) - if user_crabwings == True: - await member.add_roles(role) - else: - await member.remove_roles(role) - role = discord.utils.get(guild.roles, id=self.duckfeet_role_id) - if user_duckfeet == True: - await member.add_roles(role) - else: - await member.remove_roles(role) - role = discord.utils.get(guild.roles, id=self.elktail_role_id) - if user_elktail == True: - await member.add_roles(role) - else: - await member.remove_roles(role) - else: - data['users'].pop(i) - json_dumps = json.dumps(data, indent=2) - file = open('users.json', 'w') - file.write(json_dumps) - file.close() - await member.edit(roles=[]) - logging.info("removed discord_id " + str(client['discord_id']) + " with client_id " + str( - client['client_id']) + " and INVALID client_api_key " + client['client_api_key']) - else: - data['users'].pop(i) - json_dumps = json.dumps(data, indent=2) - file = open('users.json', 'w') - file.write(json_dumps) - file.close() - logging.info("removed discord_id " + str(client['discord_id']) + " with client_id " + str( - client['client_id']) + " and client_api_key " + client['client_api_key']) - - @linking_updater.before_loop - async def before_linking_updater(self): - logging.info('waiting to enter loop') - await self.bot.wait_until_ready() - -def setup(bot): - bot.add_cog(Linking_updater(bot)) From e82571873a671195e9b1d8a9a58babea4862977a Mon Sep 17 00:00:00 2001 From: Purpur <43528123+Pemigrade@users.noreply.github.com> Date: Sat, 30 Jan 2021 21:26:43 -0600 Subject: [PATCH 02/16] Delete linking_panel.py --- cogs/linking_panel.py | 174 ------------------------------------------ 1 file changed, 174 deletions(-) delete mode 100644 cogs/linking_panel.py diff --git a/cogs/linking_panel.py b/cogs/linking_panel.py deleted file mode 100644 index 6f966b6..0000000 --- a/cogs/linking_panel.py +++ /dev/null @@ -1,174 +0,0 @@ -import os -import discord -import requests -import json -import logging -import sys -from discord.ext import commands, tasks -from discord.ext.commands import has_permissions, MissingPermissions -from dotenv import load_dotenv -import aiohttp -import asyncio - - -class Linking(commands.Cog): - - def __init__(self, bot): - self.bot = bot - self.guild_id = int(os.getenv('guild_id')) - self.crabwings_role_id = int(os.getenv('crabwings_role_id')) - self.duckfeet_role_id = int(os.getenv('duckfeet_role_id')) - self.elktail_role_id = int(os.getenv('elktail_role_id')) - self.client_role_id = int(os.getenv('client_role_id')) - self.subuser_role_id = int(os.getenv('subuser_role_id')) - self.verified_role_id = int(os.getenv('verified_role_id')) - - @commands.Cog.listener() - async def on_message(self, message): - self.guild = self.bot.get_guild(self.guild_id) - if message.author != self.bot.user and message.guild is None and self.guild.get_member(message.author.id) is not None: - if "://" in message.content: - return - if self.guild in message.author.guilds: - channel = message.channel - await channel.send("Processing, please wait...") - # Potential API key, so tries it out - if len(message.content) == 48: - url = "https://panel.birdflop.com/api/client/account" - - headers = { - 'Accept': 'application/json', - 'Content-Type': 'application/json', - 'Authorization': 'Bearer ' + message.content, - } - - # response = requests.get(url, headers=headers) - - async with aiohttp.ClientSession() as session: - async with session.get(url, headers=headers) as response: - - # If API token is verified to be correct: - if response.status == 200: - - # Formats response of account in JSON format - json_response = await response.json() - - # Loads contents of users.json - file = open('users.json', 'r') - data = json.load(file) - file.close() - - # Checks if user exists. If so, skips adding them to users.json - client_id_already_exists = False - discord_id_already_exists = False - for user in data['users']: - if user['client_id'] == json_response['attributes']['id']: - client_id_already_exists = True - logging.info("Client ID already exists") - if user['discord_id'] == message.author.id: - discord_id_already_exists = True - logging.info("Discord ID already exists") - if not client_id_already_exists and not discord_id_already_exists: - data['users'].append({ - 'discord_id': message.author.id, - 'client_id': json_response['attributes']['id'], - 'client_api_key': message.content - }) - json_dumps = json.dumps(data, indent=2) - # Adds user to users.json - file = open('users.json', 'w') - file.write(json_dumps) - file.close() - - member = self.guild.get_member(message.author.id) - if member: - - url = "https://panel.birdflop.com/api/client" - - headers = { - 'Accept': 'application/json', - 'Authorization': 'Bearer ' + message.content, - } - - async with aiohttp.ClientSession() as session: - async with session.get(url, headers=headers) as response: - - # If API token is verified to be correct, continues - if response.status == 200: - - # Formats response for servers in JSON format - servers_json_response = await response.json() - - user_client = False - user_subuser = False - user_crabwings = False - user_duckfeet = False - user_elktail = False - for server in servers_json_response['data']: - server_owner = server['attributes']['server_owner'] - if server_owner: - user_client = True - elif not server_owner: - user_subuser = True - server_node = server['attributes']['node'] - if server_node == "Crabwings - NYC": - user_crabwings = True - elif server_node == "Duckfeet - EU": - user_duckfeet = True - elif server_node == "Elktail - EU": - user_elktail = True - if user_client: - role = discord.utils.get(self.guild.roles, id=self.client_role_id) - await member.add_roles(role) - if user_subuser: - role = discord.utils.get(self.guild.roles, id=self.subuser_role_id) - await member.add_roles(role) - if user_crabwings: - role = discord.utils.get(self.guild.roles, id=self.crabwings_role_id) - await member.add_roles(role) - if user_duckfeet: - role = discord.utils.get(self.guild.roles, id=self.duckfeet_role_id) - await member.add_roles(role) - if user_elktail: - role = discord.utils.get(self.guild.roles, id=self.elktail_role_id) - await member.add_roles(role) - role = discord.utils.get(self.guild.roles, id=self.verified_role_id) - await member.add_roles(role) - - await channel.send( - 'Your Discord account has been linked to your panel account! You may unlink your Discord and panel accounts by reacting in the #verification channel or by deleting your Verification API key.') - logging.info("Success message sent to " + message.author.name + "#" + str( - message.author.discriminator) + " (" + str( - message.author.id) + ")" + ". User linked to API key " + message.content + " and client_id " + str( - json_response['attributes']['id'])) - elif discord_id_already_exists: - await channel.send( - 'Sorry, your Discord account is already linked to a panel account. If you would like to link your Discord account to a different panel account, please unlink your Discord account first by reacting in the #verification channel.') - logging.info("Duplicate Discord message sent to " + message.author.name + "#" + str( - message.author.discriminator) + " (" + str( - message.author.id) + ")" + " for using API key " + message.content + " linked to client_id " + str( - json_response['attributes']['id'])) - elif client_id_already_exists: - await channel.send( - 'Sorry, your panel account is already linked to a Discord account. If you would like to link your panel account to a different Discord account, please unlink your panel account first by deleting its Verification API key and waiting up to 10 minutes.') - logging.info("Duplicate panel message sent to " + message.author.name + "#" + str( - message.author.discriminator) + " (" + str( - message.author.id) + ")" + " for using API key " + message.content + " linked to client_id " + str( - json_response['attributes']['id'])) - else: - # Says if API key is the corect # of characters but invalid - await channel.send("Sorry, that appears to be an invalid API key.") - logging.info( - 'invalid sent to ' + message.author.name + "#" + str( - message.author.discriminator) + " (" + str( - message.author.id) + ")") - else: - # Says this if API key is incorrect # of characters - await channel.send( - 'Sorry, that doesn\'t appear to be an API token. An API token should be a long string resembling this: ```yQSB12ik6YRcmE4d8tIEj5gkQqDs6jQuZwVOo4ZjSGl28d46```') - logging.info("obvious incorrect sent to " + message.author.name + "#" + str( - message.author.discriminator) + " (" + str(message.author.id) + ")") - - -def setup(bot): - bot.add_cog(Linking(bot)) From 8ec133370f0aaecc542e06e2f864b4be9de37266 Mon Sep 17 00:00:00 2001 From: Purpur <43528123+Pemigrade@users.noreply.github.com> Date: Sat, 30 Jan 2021 21:59:37 -0600 Subject: [PATCH 03/16] Removed unnecessary features that only work if running_on_panel=True --- bot.py | 110 ++++++++++++++++++--------------------------------------- 1 file changed, 35 insertions(+), 75 deletions(-) diff --git a/bot.py b/bot.py index 80e6055..236f34f 100644 --- a/bot.py +++ b/bot.py @@ -7,9 +7,6 @@ import sys from discord.ext import commands, tasks from discord.ext.commands import has_permissions, MissingPermissions from dotenv import load_dotenv -import aiohttp -import asyncio -import paramiko # import subprocess @@ -18,26 +15,7 @@ bot = commands.Bot(command_prefix=".", intents=discord.Intents.default(), load_dotenv() token = os.getenv('token') -crabwings_role_id = int(os.getenv('crabwings_role_id')) -duckfeet_role_id = int(os.getenv('duckfeet_role_id')) -elktail_role_id = int(os.getenv('elktail_role_id')) -client_role_id = int(os.getenv('client_role_id')) -subuser_role_id = int(os.getenv('subuser_role_id')) -verified_role_id = int(os.getenv('verified_role_id')) guild_id = int(os.getenv('guild_id')) -verification_channel = int(os.getenv('verification_channel')) -verification_message = int(os.getenv('verification_message')) -application_api_key = os.getenv('application_api_key') -running_on_panel = str(os.getenv('running_on_panel')) -crabwings_ip = os.getenv('crabwings_ip') -crabwings_port = int(os.getenv('crabwings_port')) -crabwings_username = os.getenv('crabwings_username') -crabwings_password = os.getenv('crabwings_password') - -if running_on_panel == "False": - running_on_panel = False -else: - running_on_panel = True logging.basicConfig(filename='console.log', level=logging.INFO, @@ -54,69 +32,51 @@ async def on_ready(): @bot.event async def on_message(message): - if not running_on_panel: - # Binflop - if len(message.attachments) > 0: - if not message.attachments[0].url.endswith( - ('.png', '.jpg', '.jpeg', '.mp4', '.mov', '.avi', '.gif', '.image')): - 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 = "\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) + # Binflop + if len(message.attachments) > 0: + if not message.attachments[0].url.endswith( + ('.png', '.jpg', '.jpeg', '.mp4', '.mov', '.avi', '.gif', '.image')): + 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 = "\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) timings = bot.get_cog('Timings') await timings.analyze_timings(message) await bot.process_commands(message) @bot.command() async def ping(ctx): - if running_on_panel: - if guild_id == ctx.guild.id: - await ctx.send(f'Private bot ping is {round(bot.latency * 1000)}ms') - if not running_on_panel: - await ctx.send(f'Public bot ping is {round(bot.latency * 1000)}ms') + await ctx.send(f'Botflop\'s ping is {round(bot.latency * 1000)}ms') @bot.command(name="react", pass_context=True) @has_permissions(administrator=True) async def react(ctx, url, reaction): - if not running_on_panel: - channel = await bot.fetch_channel(int(url.split("/")[5])) - message = await channel.fetch_message(int(url.split("/")[6])) - await message.add_reaction(reaction) - logging.info('reacted to ' + url + ' with ' + reaction) - - -if running_on_panel: - for file_name in os.listdir('./cogs'): - if file_name.endswith('_panel.py'): - bot.load_extension(f'cogs.{file_name[:-3]}') -else: - for file_name in os.listdir('./cogs'): - if file_name.endswith('_public.py'): - bot.load_extension(f'cogs.{file_name[:-3]}') - -if running_on_panel: - print("running on panel, starting loops") - updater.start() - linking_updater = bot.get_cog('Linking_updater') - linking_updater.linking_updater.start() + channel = await bot.fetch_channel(int(url.split("/")[5])) + message = await channel.fetch_message(int(url.split("/")[6])) + await message.add_reaction(reaction) + logging.info('reacted to ' + url + ' with ' + reaction) + +for file_name in os.listdir('./cogs'): + if file_name.endswith('.py'): + bot.load_extension(f'cogs.{file_name[:-3]}') bot.run(token) From 1b162deff42e72f4f6e32217b13334c16753fd48 Mon Sep 17 00:00:00 2001 From: Purpur <43528123+Pemigrade@users.noreply.github.com> Date: Sat, 30 Jan 2021 22:00:14 -0600 Subject: [PATCH 04/16] Removed unnecessary junk --- cogs/{timings_public.py => timings.py} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename cogs/{timings_public.py => timings.py} (100%) diff --git a/cogs/timings_public.py b/cogs/timings.py similarity index 100% rename from cogs/timings_public.py rename to cogs/timings.py From f359d9e36acb2a16e6f6475b8d9a650da2650912 Mon Sep 17 00:00:00 2001 From: Purpur <43528123+Pemigrade@users.noreply.github.com> Date: Sat, 30 Jan 2021 22:03:49 -0600 Subject: [PATCH 05/16] Rename timings.py to timings_panel.py --- cogs/{timings.py => timings_panel.py} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename cogs/{timings.py => timings_panel.py} (100%) diff --git a/cogs/timings.py b/cogs/timings_panel.py similarity index 100% rename from cogs/timings.py rename to cogs/timings_panel.py From 3bd26c0663ab8c9aac608289a87ef80d447f0505 Mon Sep 17 00:00:00 2001 From: Purpur <43528123+Pemigrade@users.noreply.github.com> Date: Sat, 30 Jan 2021 22:04:54 -0600 Subject: [PATCH 06/16] Update bot.py --- bot.py | 107 ++++++++++++++++++++++++++++++++++++++------------------- 1 file changed, 72 insertions(+), 35 deletions(-) diff --git a/bot.py b/bot.py index 236f34f..3fcc07e 100644 --- a/bot.py +++ b/bot.py @@ -15,7 +15,26 @@ bot = commands.Bot(command_prefix=".", intents=discord.Intents.default(), load_dotenv() token = os.getenv('token') +crabwings_role_id = int(os.getenv('crabwings_role_id')) +duckfeet_role_id = int(os.getenv('duckfeet_role_id')) +elktail_role_id = int(os.getenv('elktail_role_id')) +client_role_id = int(os.getenv('client_role_id')) +subuser_role_id = int(os.getenv('subuser_role_id')) +verified_role_id = int(os.getenv('verified_role_id')) guild_id = int(os.getenv('guild_id')) +verification_channel = int(os.getenv('verification_channel')) +verification_message = int(os.getenv('verification_message')) +application_api_key = os.getenv('application_api_key') +running_on_panel = str(os.getenv('running_on_panel')) +crabwings_ip = os.getenv('crabwings_ip') +crabwings_port = int(os.getenv('crabwings_port')) +crabwings_username = os.getenv('crabwings_username') +crabwings_password = os.getenv('crabwings_password') + +if running_on_panel == "False": + running_on_panel = False +else: + running_on_panel = True logging.basicConfig(filename='console.log', level=logging.INFO, @@ -32,51 +51,69 @@ async def on_ready(): @bot.event async def on_message(message): - # Binflop - if len(message.attachments) > 0: - if not message.attachments[0].url.endswith( - ('.png', '.jpg', '.jpeg', '.mp4', '.mov', '.avi', '.gif', '.image')): - 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 = "\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) + if not running_on_panel: + # Binflop + if len(message.attachments) > 0: + if not message.attachments[0].url.endswith( + ('.png', '.jpg', '.jpeg', '.mp4', '.mov', '.avi', '.gif', '.image')): + 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 = "\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) timings = bot.get_cog('Timings') await timings.analyze_timings(message) await bot.process_commands(message) @bot.command() async def ping(ctx): - await ctx.send(f'Botflop\'s ping is {round(bot.latency * 1000)}ms') + if running_on_panel: + if guild_id == ctx.guild.id: + await ctx.send(f'Private bot ping is {round(bot.latency * 1000)}ms') + if not running_on_panel: + await ctx.send(f'Public bot ping is {round(bot.latency * 1000)}ms') @bot.command(name="react", pass_context=True) @has_permissions(administrator=True) async def react(ctx, url, reaction): - channel = await bot.fetch_channel(int(url.split("/")[5])) - message = await channel.fetch_message(int(url.split("/")[6])) - await message.add_reaction(reaction) - logging.info('reacted to ' + url + ' with ' + reaction) - -for file_name in os.listdir('./cogs'): - if file_name.endswith('.py'): - bot.load_extension(f'cogs.{file_name[:-3]}') + if not running_on_panel: + channel = await bot.fetch_channel(int(url.split("/")[5])) + message = await channel.fetch_message(int(url.split("/")[6])) + await message.add_reaction(reaction) + logging.info('reacted to ' + url + ' with ' + reaction) + + +if running_on_panel: + for file_name in os.listdir('./cogs'): + if file_name.endswith('_panel.py'): + bot.load_extension(f'cogs.{file_name[:-3]}') +else: + for file_name in os.listdir('./cogs'): + if file_name.endswith('_public.py'): + bot.load_extension(f'cogs.{file_name[:-3]}') + +if running_on_panel: + print("running on panel, starting loops") + updater.start() + linking_updater = bot.get_cog('Linking_updater') + linking_updater.linking_updater.start() bot.run(token) From 3c3983548d3b32041e7e5d5c91e71620cf5dc699 Mon Sep 17 00:00:00 2001 From: Purpur <43528123+Pemigrade@users.noreply.github.com> Date: Sat, 30 Jan 2021 22:06:30 -0600 Subject: [PATCH 07/16] Update bot.py --- bot.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/bot.py b/bot.py index 3fcc07e..80e6055 100644 --- a/bot.py +++ b/bot.py @@ -7,6 +7,9 @@ import sys from discord.ext import commands, tasks from discord.ext.commands import has_permissions, MissingPermissions from dotenv import load_dotenv +import aiohttp +import asyncio +import paramiko # import subprocess From e8ba96a77e0dcb2c53d2a87131f36d0faeac9274 Mon Sep 17 00:00:00 2001 From: Purpur <43528123+Pemigrade@users.noreply.github.com> Date: Sat, 30 Jan 2021 22:07:41 -0600 Subject: [PATCH 08/16] Rename timings_panel.py to timings_public.py --- cogs/{timings_panel.py => timings_public.py} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename cogs/{timings_panel.py => timings_public.py} (100%) diff --git a/cogs/timings_panel.py b/cogs/timings_public.py similarity index 100% rename from cogs/timings_panel.py rename to cogs/timings_public.py From ea757c412d01da4cd324c46c7908df001d13ec05 Mon Sep 17 00:00:00 2001 From: Purpur <43528123+Pemigrade@users.noreply.github.com> Date: Sun, 31 Jan 2021 00:16:50 -0600 Subject: [PATCH 09/16] Remove a bunch of junk, convert text to utf-8 before uploading to binflop --- bot.py | 115 +++++++++++++++++++-------------------------------------- 1 file changed, 39 insertions(+), 76 deletions(-) diff --git a/bot.py b/bot.py index 80e6055..509ea70 100644 --- a/bot.py +++ b/bot.py @@ -8,36 +8,15 @@ from discord.ext import commands, tasks from discord.ext.commands import has_permissions, MissingPermissions from dotenv import load_dotenv import aiohttp -import asyncio -import paramiko +from unidecode import unidecode # import subprocess bot = commands.Bot(command_prefix=".", intents=discord.Intents.default(), case_insensitive=True) -load_dotenv() +load_dotenv() token = os.getenv('token') -crabwings_role_id = int(os.getenv('crabwings_role_id')) -duckfeet_role_id = int(os.getenv('duckfeet_role_id')) -elktail_role_id = int(os.getenv('elktail_role_id')) -client_role_id = int(os.getenv('client_role_id')) -subuser_role_id = int(os.getenv('subuser_role_id')) -verified_role_id = int(os.getenv('verified_role_id')) -guild_id = int(os.getenv('guild_id')) -verification_channel = int(os.getenv('verification_channel')) -verification_message = int(os.getenv('verification_message')) -application_api_key = os.getenv('application_api_key') -running_on_panel = str(os.getenv('running_on_panel')) -crabwings_ip = os.getenv('crabwings_ip') -crabwings_port = int(os.getenv('crabwings_port')) -crabwings_username = os.getenv('crabwings_username') -crabwings_password = os.getenv('crabwings_password') - -if running_on_panel == "False": - running_on_panel = False -else: - running_on_panel = True logging.basicConfig(filename='console.log', level=logging.INFO, @@ -54,69 +33,53 @@ async def on_ready(): @bot.event async def on_message(message): - if not running_on_panel: - # Binflop - if len(message.attachments) > 0: - if not message.attachments[0].url.endswith( - ('.png', '.jpg', '.jpeg', '.mp4', '.mov', '.avi', '.gif', '.image')): - 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 = "\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) - timings = bot.get_cog('Timings') - await timings.analyze_timings(message) + # Binflop + if len(message.attachments) > 0: + if not message.attachments[0].url.endswith( + ('.png', '.jpg', '.jpeg', '.mp4', '.mov', '.avi', '.gif', '.image')): + 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) + timings = bot.get_cog('Timings') + await timings.analyze_timings(message) await bot.process_commands(message) @bot.command() async def ping(ctx): - if running_on_panel: - if guild_id == ctx.guild.id: - await ctx.send(f'Private bot ping is {round(bot.latency * 1000)}ms') - if not running_on_panel: - await ctx.send(f'Public bot ping is {round(bot.latency * 1000)}ms') + await ctx.send(f'Birdflop bot ping is {round(bot.latency * 1000)}ms') @bot.command(name="react", pass_context=True) @has_permissions(administrator=True) async def react(ctx, url, reaction): - if not running_on_panel: - channel = await bot.fetch_channel(int(url.split("/")[5])) - message = await channel.fetch_message(int(url.split("/")[6])) - await message.add_reaction(reaction) - logging.info('reacted to ' + url + ' with ' + reaction) - + channel = await bot.fetch_channel(int(url.split("/")[5])) + message = await channel.fetch_message(int(url.split("/")[6])) + await message.add_reaction(reaction) + logging.info('reacted to ' + url + ' with ' + reaction) -if running_on_panel: - for file_name in os.listdir('./cogs'): - if file_name.endswith('_panel.py'): - bot.load_extension(f'cogs.{file_name[:-3]}') -else: - for file_name in os.listdir('./cogs'): - if file_name.endswith('_public.py'): - bot.load_extension(f'cogs.{file_name[:-3]}') +for file_name in os.listdir('./cogs'): + if file_name.endswith('.py'): + bot.load_extension(f'cogs.{file_name[:-3]}') -if running_on_panel: - print("running on panel, starting loops") - updater.start() - linking_updater = bot.get_cog('Linking_updater') - linking_updater.linking_updater.start() bot.run(token) From b830a9134615a497bc2521ab21114557b4b09e67 Mon Sep 17 00:00:00 2001 From: Purpur <43528123+Pemigrade@users.noreply.github.com> Date: Sun, 31 Jan 2021 00:20:39 -0600 Subject: [PATCH 10/16] everything now public, so rename file to remove public --- cogs/{timings_public.py => timings.py} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename cogs/{timings_public.py => timings.py} (100%) diff --git a/cogs/timings_public.py b/cogs/timings.py similarity index 100% rename from cogs/timings_public.py rename to cogs/timings.py From 348b88956a5e1f59a311dfef01b51093b16506b8 Mon Sep 17 00:00:00 2001 From: Purpur <43528123+Pemigrade@users.noreply.github.com> Date: Sun, 31 Jan 2021 00:27:15 -0600 Subject: [PATCH 11/16] Add .react info --- README.md | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 27fe4af..126937f 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# Botflop +# Birdflop Bot (Affectionately "Botflop") [Click here](https://discord.com/api/oauth2/authorize?client_id=787929894616825867&permissions=0&scope=bot) to invite Botflop to your server # Current abilities @@ -15,10 +15,6 @@ Botflop converts text files into bin links. You can try it out yourself on our [ ![latest.log](https://i.imgur.com/AoZGQRi.png) ![config.yml](https://i.imgur.com/qovRot8.png) -## Pterodactyl linking -* Links Pterodactyl panel and Discord accounts -* Ensures backups even when running with Blesta - -## In Progress -* `.update` command to update either all available plugins to the latest version or just one plugin -* ability to fix all timings recommendations with one click or one click per recommendation +## React +Botflop reacts to messages if you want a bot to react to the message. +![reaction](https://i.imgur.com/o1swgZw.png) From eb811f0fa34012444a9f8785784ccb13d82a5771 Mon Sep 17 00:00:00 2001 From: Purpur <43528123+Pemigrade@users.noreply.github.com> Date: Sun, 31 Jan 2021 00:27:37 -0600 Subject: [PATCH 12/16] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 126937f..8fa9b6e 100644 --- a/README.md +++ b/README.md @@ -16,5 +16,5 @@ Botflop converts text files into bin links. You can try it out yourself on our [ ![config.yml](https://i.imgur.com/qovRot8.png) ## React -Botflop reacts to messages if you want a bot to react to the message. +Botflop reacts to messages (requires Administrator permission). ![reaction](https://i.imgur.com/o1swgZw.png) From 389fa95969f0d635e9182b1c8a9893dd2366e566 Mon Sep 17 00:00:00 2001 From: Purpur <43528123+Pemigrade@users.noreply.github.com> Date: Sun, 31 Jan 2021 00:31:35 -0600 Subject: [PATCH 13/16] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 8fa9b6e..6c03535 100644 --- a/README.md +++ b/README.md @@ -5,8 +5,8 @@ ## Analyze timings reports Paste a timings report to review an in-depth description of potential optimizations. You can try it out yourself on our [Discord](https://discord.gg/zsz3PzT) -![Timings 1](https://i.imgur.com/MT6ScnL.png) -![Timings 2](https://i.imgur.com/2ApteF5.png) +![Timings 1](https://i.imgur.com/nt6EUVN.png) +![Timings 2](https://i.imgur.com/BTfed8r.png) ## Hastebin upload Botflop converts text files into bin links. You can try it out yourself on our [Discord](https://discord.gg/zsz3PzT) From 4ac917f54ba1d50d93e57982c59b2868fcd77520 Mon Sep 17 00:00:00 2001 From: Purpur <43528123+Pemigrade@users.noreply.github.com> Date: Sun, 31 Jan 2021 00:31:58 -0600 Subject: [PATCH 14/16] Update README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 6c03535..af675dd 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,5 @@ -# Birdflop Bot (Affectionately "Botflop") +# Birdflop Bot +#### (Affectionately "Botflop") [Click here](https://discord.com/api/oauth2/authorize?client_id=787929894616825867&permissions=0&scope=bot) to invite Botflop to your server # Current abilities From 035e2bf0b535f06675e9c496cf7487757d4a483e Mon Sep 17 00:00:00 2001 From: Purpur <43528123+Pemigrade@users.noreply.github.com> Date: Sun, 31 Jan 2021 00:32:16 -0600 Subject: [PATCH 15/16] Update README.md --- README.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/README.md b/README.md index af675dd..4e6a289 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,4 @@ -# Birdflop Bot -#### (Affectionately "Botflop") +# "Botflop" [Click here](https://discord.com/api/oauth2/authorize?client_id=787929894616825867&permissions=0&scope=bot) to invite Botflop to your server # Current abilities From af4cfd7d619ffc2d93e343e9f79ac28cd1b5aa08 Mon Sep 17 00:00:00 2001 From: Purpur <43528123+Pemigrade@users.noreply.github.com> Date: Sun, 31 Jan 2021 00:33:03 -0600 Subject: [PATCH 16/16] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 4e6a289..94910d8 100644 --- a/README.md +++ b/README.md @@ -16,5 +16,5 @@ Botflop converts text files into bin links. You can try it out yourself on our [ ![config.yml](https://i.imgur.com/qovRot8.png) ## React -Botflop reacts to messages (requires Administrator permission). +Botflop reacts to messages (requires Administrator permission) ![reaction](https://i.imgur.com/o1swgZw.png)