Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor #25

Closed
wants to merge 19 commits into from
Prev Previous commit
Next Next commit
refactor CustomCommands
  • Loading branch information
A-Phamfam committed Dec 29, 2020
commit d55343273ae211b2ab96be61cc06e7a8995298a5
60 changes: 33 additions & 27 deletions module/CustomCommands.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,18 @@ class CustomCommands(commands.Cog):
@staticmethod
async def process_custom_commands(message):
# custom server commands
if message.content and not message.author.bot:
if not await ex.u_miscellaneous.check_if_bot_banned(message.author.id):
guild_id = await ex.get_server_id(message)
current_message_prefix = message.content[0:len(keys.bot_prefix)]
if current_message_prefix == keys.bot_prefix:
message_without_prefix = message.content[len(keys.bot_prefix):len(message.content)].lower()
if await ex.u_custom_commands.check_custom_command_name_exists(guild_id, message_without_prefix):
await message.channel.send(await ex.u_custom_commands.get_custom_command(guild_id, message_without_prefix))
if not message.content and message.author.bot:
return None

if await ex.u_miscellaneous.check_if_bot_banned(message.author.id):
return None

guild_id = await ex.get_server_id(message)
current_message_prefix = message.content[0:len(keys.bot_prefix)]
if current_message_prefix == keys.bot_prefix:
message_without_prefix = message.content[len(keys.bot_prefix):len(message.content)].lower()
if await ex.u_custom_commands.check_custom_command_name_exists(guild_id, message_without_prefix):
await message.channel.send(await ex.u_custom_commands.get_custom_command(guild_id, message_without_prefix))

@commands.command(aliases=['addcommand'])
@commands.has_guild_permissions(manage_messages=True)
Expand Down Expand Up @@ -56,27 +60,29 @@ async def get_new_embed(desc):
custom_commands = ex.cache.custom_commands.get(ctx.guild.id)
embed_list = []
embed_message = ""
if custom_commands:
for command in custom_commands:
added_to_list = False
message = f"**{command}** -> {custom_commands.get(command)}\n"
if len(message) > 1000:
embed_list.append(await get_new_embed(message))
added_to_list = True

if not added_to_list:
embed_message += message
if len(embed_message) >= 950:
embed_list.append(await get_new_embed(embed_message))
embed_message = ""
if embed_message:
embed_list.append(await get_new_embed(embed_message))
if embed_list:
msg = await ctx.send(embed=embed_list[0])
if len(embed_list) > 1:
await ex.check_left_or_right_reaction_embed(msg, embed_list)
else:
if not custom_commands:
return await ctx.send("> There are no custom commands for your server.")

for command in custom_commands:
added_to_list = False
message = f"**{command}** -> {custom_commands.get(command)}\n"
if len(message) > 1000:
embed_list.append(await get_new_embed(message))
added_to_list = True

if not added_to_list:
embed_message += message
if len(embed_message) >= 950:
embed_list.append(await get_new_embed(embed_message))
embed_message = ""
if embed_message:
embed_list.append(await get_new_embed(embed_message))
if embed_list:
msg = await ctx.send(embed=embed_list[0])
if len(embed_list) > 1:
await ex.check_left_or_right_reaction_embed(msg, embed_list)

except Exception as e:
await ctx.send(f"> An unexpected error occurred -> {e}. Please {await ex.get_server_prefix_by_context(ctx)}report it.")
log.console(e)
Expand Down