From ead086922087880bbc601b0f74a62fcf0739ee30 Mon Sep 17 00:00:00 2001 From: lnguy Date: Sat, 3 Feb 2024 11:11:40 +0100 Subject: [PATCH] Add character tree command --- README.md | 2 +- src/main.py | 229 ++++++++++++++++++++++++++++++++++++++++++++- src/module/util.py | 13 +++ 3 files changed, 240 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 980962d..5d86a01 100644 --- a/README.md +++ b/README.md @@ -17,5 +17,5 @@ The executable is `src/main.py`. Don't forget to put this project into your PYTH ``` Slash Command /fd - get frame data of a move from a character - +/ - same as above ``` \ No newline at end of file diff --git a/src/main.py b/src/main.py index 4091f07..c443a30 100644 --- a/src/main.py +++ b/src/main.py @@ -49,7 +49,7 @@ def create_frame_data_embed(name: str, move: str) -> discord.Embed: character_name = util.correct_character_name(name.lower()) if character_name: character = util.get_character_by_name(character_name, character_list) - move_list = json_movelist_reader.get_movelist(character_name,JSON_PATH) + move_list = json_movelist_reader.get_movelist(character_name, JSON_PATH) move_type = util.get_move_type(move) if move_type: @@ -90,6 +90,230 @@ async def self(interaction: discord.Interaction, character_name: str, move: str) await interaction.response.send_message(embed=embed, ephemeral=False) +@tree.command(name="alisa", description="Frame data from alisa") +async def self(interaction: discord.Interaction, move: str): + if not (util.is_user_blacklisted(interaction.user.id) or util.is_author_newly_created(interaction)): + embed = create_frame_data_embed("alisa", move) + await interaction.response.send_message(embed=embed, ephemeral=False) + + +@tree.command(name="asuka", description="Frame data from asuka") +async def self(interaction: discord.Interaction, move: str): + if not (util.is_user_blacklisted(interaction.user.id) or util.is_author_newly_created(interaction)): + embed = create_frame_data_embed("asuka", move) + await interaction.response.send_message(embed=embed, ephemeral=False) + + +@tree.command(name="azucena", description="Frame data from azucena") +async def self(interaction: discord.Interaction, move: str): + if not (util.is_user_blacklisted(interaction.user.id) or util.is_author_newly_created(interaction)): + embed = create_frame_data_embed("azucena", move) + await interaction.response.send_message(embed=embed, ephemeral=False) + + +@tree.command(name="bryan", description="Frame data from bryan") +async def self(interaction: discord.Interaction, move: str): + if not (util.is_user_blacklisted(interaction.user.id) or util.is_author_newly_created(interaction)): + embed = create_frame_data_embed("bryan", move) + await interaction.response.send_message(embed=embed, ephemeral=False) + + +@tree.command(name="claudio", description="Frame data from claudio") +async def self(interaction: discord.Interaction, move: str): + if not (util.is_user_blacklisted(interaction.user.id) or util.is_author_newly_created(interaction)): + embed = create_frame_data_embed("claudio", move) + await interaction.response.send_message(embed=embed, ephemeral=False) + + +@tree.command(name="devil_jin", description="Frame data from devil_jin") +async def self(interaction: discord.Interaction, move: str): + if not (util.is_user_blacklisted(interaction.user.id) or util.is_author_newly_created(interaction)): + embed = create_frame_data_embed("devil_jin", move) + await interaction.response.send_message(embed=embed, ephemeral=False) + + +@tree.command(name="dragunov", description="Frame data from dragunov") +async def self(interaction: discord.Interaction, move: str): + if not (util.is_user_blacklisted(interaction.user.id) or util.is_author_newly_created(interaction)): + embed = create_frame_data_embed("dragunov", move) + await interaction.response.send_message(embed=embed, ephemeral=False) + + +@tree.command(name="feng", description="Frame data from feng") +async def self(interaction: discord.Interaction, move: str): + if not (util.is_user_blacklisted(interaction.user.id) or util.is_author_newly_created(interaction)): + embed = create_frame_data_embed("feng", move) + await interaction.response.send_message(embed=embed, ephemeral=False) + + +@tree.command(name="hwoarang", description="Frame data from hwoarang") +async def self(interaction: discord.Interaction, move: str): + if not (util.is_user_blacklisted(interaction.user.id) or util.is_author_newly_created(interaction)): + embed = create_frame_data_embed("hwoarang", move) + await interaction.response.send_message(embed=embed, ephemeral=False) + + +@tree.command(name="jack-8", description="Frame data from jack-8") +async def self(interaction: discord.Interaction, move: str): + if not (util.is_user_blacklisted(interaction.user.id) or util.is_author_newly_created(interaction)): + embed = create_frame_data_embed("jack-8", move) + await interaction.response.send_message(embed=embed, ephemeral=False) + + +@tree.command(name="jin", description="Frame data from jin") +async def self(interaction: discord.Interaction, move: str): + if not (util.is_user_blacklisted(interaction.user.id) or util.is_author_newly_created(interaction)): + embed = create_frame_data_embed("jin", move) + await interaction.response.send_message(embed=embed, ephemeral=False) + + +@tree.command(name="jun", description="Frame data from jun") +async def self(interaction: discord.Interaction, move: str): + if not (util.is_user_blacklisted(interaction.user.id) or util.is_author_newly_created(interaction)): + embed = create_frame_data_embed("jun", move) + await interaction.response.send_message(embed=embed, ephemeral=False) + + +@tree.command(name="kazuya", description="Frame data from kazuya") +async def self(interaction: discord.Interaction, move: str): + if not (util.is_user_blacklisted(interaction.user.id) or util.is_author_newly_created(interaction)): + embed = create_frame_data_embed("kazuya", move) + await interaction.response.send_message(embed=embed, ephemeral=False) + + +@tree.command(name="king", description="Frame data from king") +async def self(interaction: discord.Interaction, move: str): + if not (util.is_user_blacklisted(interaction.user.id) or util.is_author_newly_created(interaction)): + embed = create_frame_data_embed("king", move) + await interaction.response.send_message(embed=embed, ephemeral=False) + + +@tree.command(name="kuma", description="Frame data from kuma") +async def self(interaction: discord.Interaction, move: str): + if not (util.is_user_blacklisted(interaction.user.id) or util.is_author_newly_created(interaction)): + embed = create_frame_data_embed("kuma", move) + await interaction.response.send_message(embed=embed, ephemeral=False) + + +@tree.command(name="lars", description="Frame data from lars") +async def self(interaction: discord.Interaction, move: str): + if not (util.is_user_blacklisted(interaction.user.id) or util.is_author_newly_created(interaction)): + embed = create_frame_data_embed("lars", move) + await interaction.response.send_message(embed=embed, ephemeral=False) + + +@tree.command(name="law", description="Frame data from law") +async def self(interaction: discord.Interaction, move: str): + if not (util.is_user_blacklisted(interaction.user.id) or util.is_author_newly_created(interaction)): + embed = create_frame_data_embed("law", move) + await interaction.response.send_message(embed=embed, ephemeral=False) + + +@tree.command(name="lee", description="Frame data from lee") +async def self(interaction: discord.Interaction, move: str): + if not (util.is_user_blacklisted(interaction.user.id) or util.is_author_newly_created(interaction)): + embed = create_frame_data_embed("lee", move) + await interaction.response.send_message(embed=embed, ephemeral=False) + + +@tree.command(name="leo", description="Frame data from leo") +async def self(interaction: discord.Interaction, move: str): + if not (util.is_user_blacklisted(interaction.user.id) or util.is_author_newly_created(interaction)): + embed = create_frame_data_embed("leo", move) + await interaction.response.send_message(embed=embed, ephemeral=False) + + +@tree.command(name="leroy", description="Frame data from leroy") +async def self(interaction: discord.Interaction, move: str): + if not (util.is_user_blacklisted(interaction.user.id) or util.is_author_newly_created(interaction)): + embed = create_frame_data_embed("leroy", move) + await interaction.response.send_message(embed=embed, ephemeral=False) + + +@tree.command(name="lili", description="Frame data from lili") +async def self(interaction: discord.Interaction, move: str): + if not (util.is_user_blacklisted(interaction.user.id) or util.is_author_newly_created(interaction)): + embed = create_frame_data_embed("lili", move) + await interaction.response.send_message(embed=embed, ephemeral=False) + + +@tree.command(name="nina", description="Frame data from nina") +async def self(interaction: discord.Interaction, move: str): + if not (util.is_user_blacklisted(interaction.user.id) or util.is_author_newly_created(interaction)): + embed = create_frame_data_embed("nina", move) + await interaction.response.send_message(embed=embed, ephemeral=False) + + +@tree.command(name="panda", description="Frame data from panda") +async def self(interaction: discord.Interaction, move: str): + if not (util.is_user_blacklisted(interaction.user.id) or util.is_author_newly_created(interaction)): + embed = create_frame_data_embed("panda", move) + await interaction.response.send_message(embed=embed, ephemeral=False) + + +@tree.command(name="paul", description="Frame data from paul") +async def self(interaction: discord.Interaction, move: str): + if not (util.is_user_blacklisted(interaction.user.id) or util.is_author_newly_created(interaction)): + embed = create_frame_data_embed("paul", move) + await interaction.response.send_message(embed=embed, ephemeral=False) + + +@tree.command(name="raven", description="Frame data from raven") +async def self(interaction: discord.Interaction, move: str): + if not (util.is_user_blacklisted(interaction.user.id) or util.is_author_newly_created(interaction)): + embed = create_frame_data_embed("raven", move) + await interaction.response.send_message(embed=embed, ephemeral=False) + + +@tree.command(name="reina", description="Frame data from reina") +async def self(interaction: discord.Interaction, move: str): + if not (util.is_user_blacklisted(interaction.user.id) or util.is_author_newly_created(interaction)): + embed = create_frame_data_embed("reina", move) + await interaction.response.send_message(embed=embed, ephemeral=False) + + +@tree.command(name="shaheen", description="Frame data from shaheen") +async def self(interaction: discord.Interaction, move: str): + if not (util.is_user_blacklisted(interaction.user.id) or util.is_author_newly_created(interaction)): + embed = create_frame_data_embed("shaheen", move) + await interaction.response.send_message(embed=embed, ephemeral=False) + + +@tree.command(name="steve", description="Frame data from steve") +async def self(interaction: discord.Interaction, move: str): + if not (util.is_user_blacklisted(interaction.user.id) or util.is_author_newly_created(interaction)): + embed = create_frame_data_embed("steve", move) + await interaction.response.send_message(embed=embed, ephemeral=False) + + +@tree.command(name="victor", description="Frame data from victor") +async def self(interaction: discord.Interaction, move: str): + if not (util.is_user_blacklisted(interaction.user.id) or util.is_author_newly_created(interaction)): + embed = create_frame_data_embed("victor", move) + await interaction.response.send_message(embed=embed, ephemeral=False) + + +@tree.command(name="xiaoyu", description="Frame data from xiaoyu") +async def self(interaction: discord.Interaction, move: str): + if not (util.is_user_blacklisted(interaction.user.id) or util.is_author_newly_created(interaction)): + embed = create_frame_data_embed("xiaoyu", move) + await interaction.response.send_message(embed=embed, ephemeral=False) + + +@tree.command(name="yoshimitsu", description="Frame data from yoshimitsu") +async def self(interaction: discord.Interaction, move: str): + if not (util.is_user_blacklisted(interaction.user.id) or util.is_author_newly_created(interaction)): + embed = create_frame_data_embed("yoshimitsu", move) + await interaction.response.send_message(embed=embed, ephemeral=False) + + +@tree.command(name="zafina", description="Frame data from zafina") +async def self(interaction: discord.Interaction, move: str): + if not (util.is_user_blacklisted(interaction.user.id) or util.is_author_newly_created(interaction)): + embed = create_frame_data_embed("zafina", move) + await interaction.response.send_message(embed=embed, ephemeral=False) + + @tree.command(name="feedback", description="Send feedback incase of wrong data") async def self(interaction: discord.Interaction, message: str): if not (util.is_user_blacklisted(interaction.user.id) or util.is_author_newly_created(interaction)): @@ -99,7 +323,7 @@ async def self(interaction: discord.Interaction, message: str): interaction.guild, message) channel = hei.get_channel(feedback_channel_id) actioned_channel = hei.get_channel(actioned_channel_id) - await channel.send(content=feedback_message,view=button.DoneButton(actioned_channel)) + await channel.send(content=feedback_message, view=button.DoneButton(actioned_channel)) result = embed.success_embed("Feedback sent") except Exception as e: result = embed.error_embed("Feedback couldn't be sent caused by: " + e) @@ -115,7 +339,6 @@ async def self(interaction: discord.Interaction, message: str): scheduler_thread = threading.Thread(target=util.periodic_function, args=(scheduler, 3600, util.create_json_movelists, CHARACTER_LIST_PATH)) scheduler_thread.start() - hei.run(discord_token) except Exception as e: diff --git a/src/module/util.py b/src/module/util.py index 741668f..e6e16c0 100644 --- a/src/module/util.py +++ b/src/module/util.py @@ -64,3 +64,16 @@ def periodic_function(scheduler, interval, function, character_list_path: str): while True: scheduler.enter(interval, 1, function, (character_list_path,)) scheduler.run() + + +def create_character_tree_commands(character_list): + f = open("out.txt", "a") + for c in character_list: + fd_command = ("@tree.command(name=\"{}\", description=\"Frame data from {}\") \n async def self(" + "interaction: discord.Interaction, move: str): \n\tif not (util.is_user_blacklisted(" + "interaction.user.id) or util.is_author_newly_created(interaction)): \n\t\tembed = " + "create_frame_data_embed(\"{}\", move) \n\t\tawait interaction.response.send_message(embed=embed," + "ephemeral=False) \n").format(c.name, c.name, c.name) + f.write(fd_command + "\n") + f.close() + print("done")