From d13751faa9d640027a29c58ee46340688e34902f Mon Sep 17 00:00:00 2001 From: snipe_blaze <72265661+notsniped@users.noreply.github.com> Date: Thu, 11 Aug 2022 20:35:47 +0530 Subject: [PATCH] Debloat main code Holy firetruck so much bloat --- Main.py | 64 ++++++++++++++++++++++----------------------------------- 1 file changed, 24 insertions(+), 40 deletions(-) diff --git a/Main.py b/Main.py index a7443a6..5e1770a 100644 --- a/Main.py +++ b/Main.py @@ -7,42 +7,35 @@ # USER CONFIGURATION -prefix = '-' # Default prefix is -, you can replace it with your preferred prefix -owner = 'EMPTY_USERNAME#0000' # Replace 'EMPTY_USERNAME#0000' with your Discord username -bot_token = '' # Add the bot token in this variable. For more info check README.md +prefix = "-" # Default prefix is -, you can replace it with your preferred prefix +owner = "EMPTY_USERNAME#0000" # Replace 'EMPTY_USERNAME#0000' with your Discord username +bot_token = "" # Add the bot token in this variable. For more info check README.md # USER CONFIGURATION END intents = discord.Intents.all() botVer = 'v1.2.1' -if os.name == 'nt': - os.system('cls') -else: - os.system('clear') +if os.name == 'nt': os.system('cls') +else: os.system('clear') client = commands.Bot(command_prefix=str(prefix), intents=intents) # READ COMMENT AT LINE 13 FOR MORE INFO slash = SlashCommand(client, sync_commands=True) global startTime startTime = time.time() client.remove_command('help') homedir = os.getcwd() -config:dict = {} +config = {} -if os.name == 'nt': - with open(f'{homedir}\\config.json', 'r') as f: - config = json.load(f) -else: - with open(f'{homedir}/config.json', 'r') as f: - config = json.load(f) +if os.name == 'nt': + with open(f'{homedir}\\config.json', 'r') as f: config = json.load(f) +else: + with open(f'{homedir}/config.json', 'r') as f: config = json.load(f) snipe_log:bool = config[str("config")][str("logs")]["snipe"] editsnipe_log:bool = config[str("config")][str("logs")]["editsnipe"] - -def randColor(): - return discord.Color.random() @client.command() async def help(ctx): - e = discord.Embed(title='Command Help', description=f'Prefix: `{prefix}`\n\n`{str(prefix)}snipe`: See the most recently deleted message in this channel.\n`{str(prefix)}editsnipe`: See the most recently edited message in this channel.', color=randColor()) + e = discord.Embed(title='Command Help', description=f'Prefix: `{prefix}`\n\n`{str(prefix)}snipe`: See the most recently deleted message in this channel.\n`{str(prefix)}editsnipe`: See the most recently edited message in this channel.', color=discord.Color.random()) await ctx.send(embed=e) @client.event @@ -66,14 +59,11 @@ async def on_ready(): @client.event async def on_message_delete(message): if not message.author.bot: - guild = client.guilds[0] channel = message.channel snipe_message_author[message.channel.id] = message.author snipe_message_content[message.channel.id] = message.content - if bool(snipe_log) == True: - print(f"Message deleted in #{channel.name} ({guild.name}):\n Message content: {message.content}") - else: - pass + if bool(snipe_log): print(f"Message deleted in #{channel} ({message.guild}):\n Message content: {message.content}") + else: pass @client.event async def on_message_edit(message_before, message_after): @@ -83,30 +73,26 @@ async def on_message_edit(message_before, message_after): channel = message_before.channel editsnipe_message_before_content[channel.id] = message_before.content editsnipe_message_after_content[channel.id] = message_after.content - if bool(editsnipe_log) == True: - print(f"Message edited in #{channel.name} ({guild.name}):\n Old message: {message_before.content}\n New message: {message_after.content}") - else: - pass + if bool(editsnipe_log): print(f"Message edited in #{channel} ({message_before.guild}):\n Old message: {message_before.content}\n New message: {message_after.content}") + else: pass @client.command() async def snipe(ctx): channel = ctx.channel try: - em = discord.Embed(name=f"Last deleted message in #{channel.name}", description=snipe_message_content[channel.id], color=randColor()) + em = discord.Embed(name=f"Last deleted message in #{channel.name}", description=snipe_message_content[channel.id], color=discord.Color.random()) em.set_footer(text=f"This message was sent by {snipe_message_author[channel.id]}") await ctx.send(embed=em) - except KeyError: - await ctx.send(f"There are no recently deleted messages in <#{channel.id}>") + except KeyError: await ctx.send(f"There are no recently deleted messages in <#{channel.id}>") @client.command() async def editsnipe(ctx): channel = ctx.channel try: - em = discord.Embed(description=f'**Message before**:```{editsnipe_message_before_content[ctx.channel.id]}```\n**Message after**:```{editsnipe_message_after_content[ctx.channel.id]}```', color=randColor()) + em = discord.Embed(description=f'**Message before**:```{editsnipe_message_before_content[ctx.channel.id]}```\n**Message after**:```{editsnipe_message_after_content[ctx.channel.id]}```', color=discord.Color.random()) em.set_footer(text=f'This message was edited by {editsnipe_message_author[channel.id]}') await ctx.send(embed=em) - except KeyError: - await ctx.reply(f'There are no recently edited messages in <#{ctx.channel.id}>') + except KeyError: await ctx.reply(f'There are no recently edited messages in <#{ctx.channel.id}>') @slash.slash( name="snipe", @@ -115,11 +101,10 @@ async def editsnipe(ctx): async def snipe(ctx: SlashContext): channel = ctx.channel try: - em = discord.Embed(name=f"Last deleted message in #{channel.name}", description=snipe_message_content[channel.id], color=randColor()) + em = discord.Embed(name=f"Last deleted message in #{channel.name}", description=snipe_message_content[channel.id], color=discord.Color.random()) em.set_footer(text=f"This message was sent by {snipe_message_author[channel.id]}") await ctx.send(embed=em) - except KeyError: - await ctx.send(f"There are no recently deleted messages in <#{channel.id}>") + except KeyError: await ctx.send(f"There are no recently deleted messages in <#{channel.id}>") @slash.slash( name="editsnipe", @@ -128,10 +113,9 @@ async def snipe(ctx: SlashContext): async def editsnipe(ctx: SlashContext): channel = ctx.channel try: - em = discord.Embed(description=f'**Message before**:```{editsnipe_message_before_content[ctx.channel.id]}```\n**Message after**:```{editsnipe_message_after_content[ctx.channel.id]}```', color=randColor()) + em = discord.Embed(description=f'**Message before**:```{editsnipe_message_before_content[ctx.channel.id]}```\n**Message after**:```{editsnipe_message_after_content[ctx.channel.id]}```', color=discord.Color.random()) em.set_footer(text=f'This message was edited by {editsnipe_message_author[channel.id]}') await ctx.send(embed=em) - except KeyError: - await ctx.reply(f'There are no recently edited messages in <#{ctx.channel.id}>') + except KeyError: await ctx.reply(f'There are no recently edited messages in <#{ctx.channel.id}>') -client.run(str(bot_token)) +client.run(bot_token)