From b79fb587917050f1715886bd4d69e811b396856b Mon Sep 17 00:00:00 2001 From: Howard Tseng Date: Fri, 3 Nov 2023 18:22:48 -0400 Subject: [PATCH] refractor: basic commands --- commands/basic/basic_commands.py | 38 ++++++++++++++++++++++++++++++++ main.py | 23 +++---------------- 2 files changed, 41 insertions(+), 20 deletions(-) create mode 100644 commands/basic/basic_commands.py diff --git a/commands/basic/basic_commands.py b/commands/basic/basic_commands.py new file mode 100644 index 0000000..a806e49 --- /dev/null +++ b/commands/basic/basic_commands.py @@ -0,0 +1,38 @@ + +from discord import app_commands + +import discord + +def register_commands( + tree: discord.app_commands.CommandTree, + guilds_dict: dict, +): + guilds = [ # TW and Baltics server + discord.Object(id=int(server_id)) + for server_id in guilds_dict.keys() + ] + @tree.command( + name="website", + description="Responds with the placeTW website link", + guilds=guilds, + ) + async def website(interaction: discord.Interaction): + await interaction.response.send_message("https://placetw.com/") + + + @tree.command( + name="invite", + description="Invite this bot to your server!", + guilds=guilds, + ) + async def invite_link(interaction: discord.Interaction): + await interaction.response.send_message("https://discord.com/oauth2/authorize?client_id=1134650883637006407&&permissions=2147484672&scope=bot") + + @tree.command( + name="echo", + description="Echoes whatever string is fed", + guilds=guilds, + ) + @app_commands.describe(given_str="The string you want echoed backed") + async def echo(interaction: discord.Interaction, given_str: str): + await interaction.response.send_message(f"You sent this: `{given_str}`") \ No newline at end of file diff --git a/main.py b/main.py index dd7477b..8e00d47 100644 --- a/main.py +++ b/main.py @@ -8,6 +8,7 @@ import datetime # user commands +from commands.basic import basic_commands from commands.fetch_entry import fetch_entry_cmd from commands.fetch_entry import fetch_entry_ui from commands.edit_entry import edit_entry_cmd @@ -51,31 +52,12 @@ ) # basically refers to this server -@tree.command( - name="website", - description="Responds with the placeTW website link", - guild=placetw_guild, -) -async def test_slash_command(interaction: discord.Interaction): - await interaction.response.send_message("https://placetw.com/") - - -@tree.command( - name="echo", - description="Echoes whatever string is fed", - guild=placetw_guild, -) -@app_commands.describe(given_str="The string you want echoed backed") -async def test_slash_command(interaction: discord.Interaction, given_str: str): - await interaction.response.send_message(f"You sent this: `{given_str}`") - - @tree.command( name="deployment-info", description="Returns information about the bot deployment", guild=placetw_guild, ) -async def test_slash_command(interaction: discord.Interaction): +async def deployment_info(interaction: discord.Interaction): msg = f""" PlaceTW discord bot ({'prod' if prod else 'dev'} deployment) Branch deployed: `{Repo().active_branch.name}` @@ -90,6 +72,7 @@ async def test_slash_command(interaction: discord.Interaction): edit_entry_cmd.register_commands(tree, placetw_guild, client) restart.register_commands(tree, placetw_guild) watching.register_commands(tree, placetw_guild, client) +basic_commands.register_commands(tree, GUILDS_DICT) # * register commands to the other servers