From 90358ca652d4c47aa5206d63cea8fb38f8602746 Mon Sep 17 00:00:00 2001 From: chanomkaimuk <22185824+chanomkaimuk@users.noreply.github.com> Date: Wed, 9 Aug 2023 22:41:59 +0200 Subject: [PATCH] random shiba apigit checkout -b shiba --- commands/shiba/random_shiba.py | 21 +++++++++++++++++++++ main.py | 8 ++++++-- 2 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 commands/shiba/random_shiba.py diff --git a/commands/shiba/random_shiba.py b/commands/shiba/random_shiba.py new file mode 100644 index 0000000..7711165 --- /dev/null +++ b/commands/shiba/random_shiba.py @@ -0,0 +1,21 @@ +import discord +from ..modules.async_utils import _async_get_json + + +def register_commands(tree, this_guild: discord.Object): + @tree.command( + name="shiba", + description="Shiba", + guild=this_guild, + ) + async def random_shiba( + interaction: discord.Interaction, + ): + shiba_json = await _async_get_json( + "https://dog.ceo/api/breed/shiba/images/random" + ) + if shiba_json is None or shiba_json["status"] != "success": # ): + return await interaction.response.send_message( + "Sorry, we couldn't find any dogs ):" + ) + await interaction.response.send_message(shiba_json["message"]) diff --git a/main.py b/main.py index e0aee92..e0365ab 100644 --- a/main.py +++ b/main.py @@ -14,12 +14,13 @@ from commands.edit_entry import edit_entry_cmd from commands.one_o_one import one_o_one from commands import hgs +from commands.shiba import random_shiba import sys # load environment vars (from .env) load_dotenv() -prod = len(sys.argv) > 1 and sys.argv[1] == 'prod' -TOKEN = os.getenv('DISCORD_TOKEN_DEV' if not prod else 'DISCORD_TOKEN') +prod = len(sys.argv) > 1 and sys.argv[1] == "prod" +TOKEN = os.getenv("DISCORD_TOKEN_DEV" if not prod else "DISCORD_TOKEN") GUILD = os.getenv("DISCORD_GUILD") deployment_date = datetime.datetime.now() @@ -43,6 +44,7 @@ async def test_slash_command(interaction: discord.Interaction): await interaction.response.send_message("https://placetw.com/") + # * simple echo command with param explanation @tree.command( name="echo", @@ -67,6 +69,7 @@ async def test_slash_command(interaction: discord.Interaction): """ await interaction.response.send_message(msg) + # * register commands from other files fetch_entry_cmd.register_commands(tree, this_guild) fetch_entry_ui.register_commands(tree, this_guild) @@ -74,6 +77,7 @@ async def test_slash_command(interaction: discord.Interaction): # edit_entry_modal.register_commands(tree, this_guild, client) edit_entry_cmd.register_commands(tree, this_guild, client) hgs.register_commands(tree, this_guild) +random_shiba.register_commands(tree, this_guild) # sync the slash commands to server