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 branch to dev #22

Merged
merged 71 commits into from
Dec 28, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
71 commits
Select commit Hold shift + click to select a range
a554ede
Starting to refactor Utility.py
MujyKun Dec 26, 2020
db3893f
Lastfm refactor
A-Phamfam Dec 26, 2020
5359cee
fixed issue with static method referencing Utility object
MujyKun Dec 26, 2020
a6954bc
Refactor patreon
A-Phamfam Dec 26, 2020
634a5ef
Refactor moderator
A-Phamfam Dec 26, 2020
77af4ee
Refactor customcommands
A-Phamfam Dec 26, 2020
e89d968
Refactor Biasgame
A-Phamfam Dec 26, 2020
766fde1
Refactor datadog
A-Phamfam Dec 26, 2020
f41da4d
Finished Refactoring Cache Util
MujyKun Dec 26, 2020
0aab956
Finished Refactoring Cache Util
MujyKun Dec 26, 2020
86419fd
Finished Refactoring Currency Util
MujyKun Dec 26, 2020
6719b24
Refactor weverse
A-Phamfam Dec 26, 2020
3fe154f
Refactor self assign roles
A-Phamfam Dec 26, 2020
7a192e7
Refactor reminder
A-Phamfam Dec 26, 2020
c6cdb5d
Refactor twitter
A-Phamfam Dec 26, 2020
5c0ceb2
Finished Refactoring Miscellaneous Util
MujyKun Dec 26, 2020
3113a1e
Refactor logging
A-Phamfam Dec 26, 2020
7c35245
Finished Refactoring BlackJack Util
MujyKun Dec 26, 2020
fe4fc01
Finished Refactoring Levels Util
MujyKun Dec 26, 2020
0c99d21
Refactor groupmembers
A-Phamfam Dec 26, 2020
1e77641
Merge pull request #3 from MujyKun/database
MujyKun Dec 26, 2020
de3c6a6
Merge pull request #4 from MujyKun/cache
MujyKun Dec 26, 2020
0822d64
Merge branch 'refactor' into currency
MujyKun Dec 26, 2020
14eb905
Merge pull request #5 from MujyKun/currency
MujyKun Dec 26, 2020
e794037
Merge branch 'refactor' into miscellaneous
MujyKun Dec 26, 2020
9f3a766
Merge pull request #6 from MujyKun/miscellaneous
MujyKun Dec 26, 2020
08e96f0
Merge branch 'refactor' into GroupMembers
MujyKun Dec 26, 2020
9712d44
Merge pull request #7 from MujyKun/GroupMembers
MujyKun Dec 26, 2020
4f37d0d
Merge branch 'refactor' into Logging
MujyKun Dec 26, 2020
7293ed2
Merge pull request #8 from MujyKun/Logging
MujyKun Dec 26, 2020
f3dfe03
Merge pull request #9 from MujyKun/Twitter
MujyKun Dec 26, 2020
694d6b2
Merge branch 'refactor' into Reminder
MujyKun Dec 26, 2020
d31cf24
Merge pull request #10 from MujyKun/Reminder
MujyKun Dec 26, 2020
3e52802
Merge branch 'refactor' into blackjack
MujyKun Dec 26, 2020
4945861
Merge pull request #11 from MujyKun/blackjack
MujyKun Dec 26, 2020
1961508
Merge pull request #12 from MujyKun/SelfAssignroles
MujyKun Dec 26, 2020
18f04c2
Merge branch 'refactor' into levels
MujyKun Dec 26, 2020
c80b818
Merge pull request #13 from MujyKun/levels
MujyKun Dec 26, 2020
11aac30
Merge branch 'refactor' into Weverse
MujyKun Dec 26, 2020
a20cb17
Merge pull request #14 from MujyKun/Weverse
MujyKun Dec 26, 2020
e714689
Merge branch 'refactor' into DataDog
MujyKun Dec 26, 2020
e00388c
Merge pull request #15 from MujyKun/DataDog
MujyKun Dec 26, 2020
f05b6dc
Merge pull request #16 from MujyKun/BiasGame
MujyKun Dec 26, 2020
6dc80d3
Merge branch 'refactor' into CustomCommands
MujyKun Dec 26, 2020
e68086c
Merge pull request #17 from MujyKun/CustomCommands
MujyKun Dec 26, 2020
4bd96a4
Merge branch 'refactor' into Moderator
MujyKun Dec 26, 2020
71659ab
Merge pull request #18 from MujyKun/Moderator
MujyKun Dec 26, 2020
60ce101
Merge branch 'refactor' into Patreon
MujyKun Dec 26, 2020
87a924f
Merge pull request #19 from MujyKun/Patreon
MujyKun Dec 26, 2020
db99ac6
Merge pull request #20 from MujyKun/Last_FM
MujyKun Dec 26, 2020
e5e64a5
Merge branch 'dev' into refactor
MujyKun Dec 26, 2020
8ae08ba
Need help fixing stuff
MujyKun Dec 26, 2020
2e5ebde
Refactor to ex.subclass
A-Phamfam Dec 26, 2020
cafa847
ex.subclasses
MujyKun Dec 26, 2020
ce0b1cf
Merge pull request #23 from MujyKun/refactor_p
MujyKun Dec 26, 2020
1547fd7
ex.subclasses
MujyKun Dec 26, 2020
4abdbb7
ex.subclasses
MujyKun Dec 26, 2020
1438d04
Changed so .get_cooldown_time() is being called from the proper subclass
A-Phamfam Dec 26, 2020
6fceb0d
Currently cleaning up warnings
MujyKun Dec 26, 2020
a9eb7aa
Merge branch 'refactor' of https://github.com/MujyKun/IreneBot into r…
MujyKun Dec 26, 2020
65e9e47
Added PyCharm inspection comments, shortened exceptions, and cleared …
MujyKun Dec 27, 2020
aa76edb
Added comments for acceptable Pycharm coding style violations
MujyKun Dec 27, 2020
cf5544e
Made all necessary methods static
MujyKun Dec 27, 2020
d4e7f2e
Added .gitkeep to folders and using .gitignore properly
MujyKun Dec 27, 2020
cbc764f
Removed unused module Cogs.
MujyKun Dec 27, 2020
3fdd556
Added a few comments in Utility
MujyKun Dec 27, 2020
4fd07b5
Added few comments
MujyKun Dec 28, 2020
12a0435
Added flask as a requirement
MujyKun Dec 28, 2020
c1e7c9e
Fixed references to methods that have been moved to util classes
A-Phamfam Dec 28, 2020
0d7c450
Fixed referencing issues with Utility and Utils
MujyKun Dec 28, 2020
0202b36
Merge branch 'refactor' of https://github.com/MujyKun/IreneBot into r…
MujyKun Dec 28, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Refactor customcommands
  • Loading branch information
A-Phamfam committed Dec 26, 2020
commit 77af4eead1423ba6ee84aa6633f9635c0ffd2027
31 changes: 0 additions & 31 deletions Utility.py
Original file line number Diff line number Diff line change
Expand Up @@ -2484,37 +2484,6 @@ async def update_welcome_message(self, server_id, message):
await self.conn.execute("UPDATE general.welcome SET message = $1 WHERE serverid = $2", message, server_id)
self.cache.welcome_messages[server_id]['message'] = message

########################
# ## CUSTOM COMMANDS## #
########################

async def check_custom_command_name_exists(self, server_id, command_name):
if server_id:
custom_commands = self.cache.custom_commands.get(server_id)
if custom_commands:
if command_name.lower() in custom_commands:
return True
return False

async def add_custom_command(self, server_id, command_name, message):
await self.conn.execute("INSERT INTO general.customcommands(serverid, commandname, message) VALUES ($1, $2, $3)", server_id, command_name, message)
custom_commands = self.cache.custom_commands.get(server_id)
if custom_commands:
custom_commands[command_name] = message
else:
self.cache.custom_commands[server_id] = {command_name: message}

async def remove_custom_command(self, server_id, command_name):
await self.conn.execute("DELETE FROM general.customcommands WHERE serverid = $1 AND commandname = $2", server_id, command_name)
custom_commands = self.cache.custom_commands.get(server_id)
try:
custom_commands.pop(command_name)
except Exception as e:
log.console(e)

async def get_custom_command(self, server_id, command_name):
commands = self.cache.custom_commands.get(server_id)
return commands.get(command_name)
###################
# ## BIAS GAME ## #
###################
Expand Down
10 changes: 5 additions & 5 deletions module/CustomCommands.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ async def process_custom_commands(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.check_custom_command_name_exists(guild_id, message_without_prefix):
await message.channel.send(await ex.get_custom_command(guild_id, message_without_prefix))
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 All @@ -25,10 +25,10 @@ async def createcommand(self, ctx, command_name, *, message):
msg_is_cmd = await ex.check_message_is_command(command_name, is_command_name=True)
if msg_is_cmd:
return await ctx.send(f"> {command_name} is already a bot command and can not be added.")
if await ex.check_custom_command_name_exists(ctx.guild.id, command_name):
if await ex.u_custom_commands.check_custom_command_name_exists(ctx.guild.id, command_name):
return await ctx.send(f"> {command_name} is already a custom command and can not be added.")
else:
await ex.add_custom_command(ctx.guild.id, command_name, message)
await ex.u_custom_commands.add_custom_command(ctx.guild.id, command_name, message)
return await ctx.send(f"> {command_name} has been added as a command.")
except Exception as e:
await ctx.send(f"> An unexpected error occurred -> {e}. Please {await ex.get_server_prefix_by_context(ctx)}report it.")
Expand All @@ -39,7 +39,7 @@ async def createcommand(self, ctx, command_name, *, message):
async def deletecommand(self, ctx, command_name):
"""Delete a custom command. [Format: %deletecommand (command name)]"""
try:
await ex.remove_custom_command(ctx.guild.id, command_name.lower())
await ex.u_custom_commands.remove_custom_command(ctx.guild.id, command_name.lower())
return await ctx.send(f"> If the `{command_name}` exists, it was removed.")
except Exception as e:
await ctx.send(f"> An unexpected error occurred -> {e}. Please {await ex.get_server_prefix_by_context(ctx)}report it.")
Expand Down
27 changes: 26 additions & 1 deletion util/customcommands.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,30 @@


class CustomCommands(Utility):
pass
async def check_custom_command_name_exists(self, server_id, command_name):
if server_id:
custom_commands = self.cache.custom_commands.get(server_id)
if custom_commands:
if command_name.lower() in custom_commands:
return True
return False

async def add_custom_command(self, server_id, command_name, message):
await self.conn.execute("INSERT INTO general.customcommands(serverid, commandname, message) VALUES ($1, $2, $3)", server_id, command_name, message)
custom_commands = self.cache.custom_commands.get(server_id)
if custom_commands:
custom_commands[command_name] = message
else:
self.cache.custom_commands[server_id] = {command_name: message}

async def remove_custom_command(self, server_id, command_name):
await self.conn.execute("DELETE FROM general.customcommands WHERE serverid = $1 AND commandname = $2", server_id, command_name)
custom_commands = self.cache.custom_commands.get(server_id)
try:
custom_commands.pop(command_name)
except Exception as e:
log.console(e)

async def get_custom_command(self, server_id, command_name):
commands = self.cache.custom_commands.get(server_id)
return commands.get(command_name)