-
Notifications
You must be signed in to change notification settings - Fork 4
Added command to list documentation websites #25
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
Closed
Closed
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -30,17 +30,36 @@ async def on_message(self, message: discord.Message): | |
| message.content[0] in COMMANDS | ||
| and message.content[1:] in COMMANDS[message.content[0]] | ||
| ): | ||
| # Grab command info from JSON. | ||
| command = COMMANDS[message.content[0]][message.content[1:]] | ||
| if "duplicate" in command: | ||
| # Handle duplicate commands, | ||
| # grab original defined by `duplicate` | ||
| command = COMMANDS[message.content[0]][command["duplicate"]] | ||
|
|
||
| # Prepare the list of commands to send. | ||
| to_send = [] | ||
| if "commands" in command: | ||
| # Handle multiple commands, | ||
| # grab the list of commands defined by `commands`. | ||
| commands_list = command["commands"].split(", ") | ||
| for current_command in commands_list: | ||
| if current_command in COMMANDS[message.content[0]]: | ||
| to_send.append( | ||
| COMMANDS[message.content[0]][current_command] | ||
| ) | ||
| else: | ||
| to_send.append(command) | ||
|
|
||
| logger.info(f"Executing response command: {message.content}") | ||
|
|
||
| if "embed" in command: | ||
| await message.channel.send( | ||
| embed=discord.Embed.from_dict(command["embed"]) | ||
| ) | ||
| elif "content" in command: | ||
| await message.channel.send(content=command["content"]) | ||
| # Send messages. | ||
| for command_to_send in to_send: | ||
| final_cmd = command_to_send | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. just use |
||
| if "duplicate" in final_cmd: | ||
| # Handle duplicate commands, | ||
| # grab original defined by `duplicate`. | ||
| final_cmd = COMMANDS[message.content[0]][ | ||
| final_cmd["duplicate"]] | ||
| if "embed" in final_cmd: | ||
| await message.channel.send( | ||
| embed=discord.Embed.from_dict(final_cmd["embed"]) | ||
| ) | ||
| elif "content" in final_cmd: | ||
| await message.channel.send(content=final_cmd["content"]) | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not the biggest fan of having two for loops here, especially when the ultimate action is to send message on parsing of a command anyway.
This should be able to be reduced down and combined with the other for loop, and just send message as they are popped and validated.
Or better yet, reduce complexity all together with helper functions to make this entirely more readable.