Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
26 changes: 26 additions & 0 deletions am_bot/cogs/command_responses.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,29 @@
"amcvids": {
"duplicate": "amcv"
},
"docs": {
"embed": {
"author": {
"name": "Documentation Websites",
"icon_url": "https://i.imgur.com/Rt7vu2j.png",
"proxy_icon_url": "https://media.discordapp.net/attachments/1194039176920834120/1461728918531870893/ADKLogo_128.png?ex=696b9ca3&is=696a4b23&hm=a6a7547b5f7b2d1aff9f24f07fe1fd5299cd8f81c4deea5d88b411e075513728&=&format=webp&quality=lossless"
},
"fields": [
{
"name": "===========================",
"value": "[Official modding documentation](https://devkit.studiowildcard.com/)\n[Blog, snippets & tutorials](https://arkmodding.net/)\n[Wiki, general FAQ & tutorials](https://wiki.arkmodding.net/)\n[CurseForge - Ark knowledge base](https://support.curseforge.com/en/support/solutions/folders/9000199294/)\n[CurseForge - Premium mods documentation](https://support.curseforge.com/en/support/solutions/articles/9000235469-ark-premium-mods/)\n[CurseForge - Suggest your premium mod](https://arksa.curseforge.com/#premium)\n[CurseForge - Moderation policies & guidelines](https://support.curseforge.com/en/support/solutions/articles/9000197279-project-and-modpack-moderation-policies)",
"inline": true
}
],
"color": 2921542,
"type": "rich",
"description": "Links to documentation websites, where you can find various info and guides.",
"title": ""
}
},
"links": {
"duplicate": "docs"
},
"gso": {
"content": "__**SAH Discord**__: https://discord.gg/h2k7agJJGS"
},
Expand All @@ -60,6 +83,9 @@
},
"cf": {
"content": "https://discord.gg/Q4bB5zE75f"
},
"tutorials": {
"commands": "docs, wcws, amcv"
}
}
}
Expand Down
39 changes: 29 additions & 10 deletions am_bot/cogs/responses.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Copy link
Contributor

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.

# 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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just use command_to_send, re-declaring as another variable provides nothing here.

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"])
Loading