diff --git a/requirements.txt b/requirements.txt index eea38cf..20e1ca7 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,5 @@ beautifulsoup4==4.11.1 discord.py==2.3.2 pymediawiki==0.7.3 -Requests==2.31.0 +Requests~=2.27.1 +bs4~=0.0.1 \ No newline at end of file diff --git a/src/dc/connector.py b/src/dc/connector.py deleted file mode 100644 index d1a1c72..0000000 --- a/src/dc/connector.py +++ /dev/null @@ -1,10 +0,0 @@ -import discord -from discord import app_commands - - -class Discord_Connector(discord.Client): - def __init__(self, *, intents: discord.Intents): - super().__init__(intents=intents) - self.tree = app_commands.CommandTree(self) - async def on_ready(self): - print('Logged on as', self.user) diff --git a/src/main.py b/src/main.py index 5719c9c..e208085 100644 --- a/src/main.py +++ b/src/main.py @@ -1,9 +1,8 @@ -import json, datetime, logging, os -import discord +import json, datetime, logging, os, discord from src.module import character_importer -from src.dc.connector import Discord_Connector from src.module import configurator +from src.module import json_movelist_reader logger = logging.getLogger(__name__) logger.setLevel(logging.WARNING) @@ -14,6 +13,36 @@ discord_token = config.read_config()['DISCORD_TOKEN'] +class heihachi(discord.Client): + def __init__(self, *, intents: discord.Intents): + super().__init__(intents=intents) + self.synced = False + + async def on_ready(self): + await self.wait_until_ready() + if not self.synced: + await tree.sync(guild=discord.Object(id=645011181739835397)) + self.synced = True + print('Logged on as', self.user) + + +try: + client = heihachi(intents=discord.Intents.default()) + tree = discord.app_commands.CommandTree(client) + +except Exception as e: + time_now = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S") + logger.error(f'{time_now} \n Error: {e}') + + +@tree.command(name="fd", description="Frame data from a character move", guild=discord.Object("645011181739835397")) +async def self(interaction: discord.Interaction, character_name: str, move: str): + character_name = character_name.lower() + move_list = json_movelist_reader.get_movelist_from_json(character_name) + result = json_movelist_reader.get_move(move, move_list) + await interaction.response.send_message(content=result, ephemeral=False) + + def create_all_character_json(character_list_path: str): try: with open(character_list_path) as file: @@ -25,9 +54,8 @@ def create_all_character_json(character_list_path: str): except Exception as e: raise Exception("Error when importing character from wavu" + str(e)) -try: - client = Discord_Connector(intents=discord.Intents.default()) +try: client.run(discord_token) except Exception as e: diff --git a/src/module/json_movelist_reader.py b/src/module/json_movelist_reader.py index c85db3f..514ee63 100644 --- a/src/module/json_movelist_reader.py +++ b/src/module/json_movelist_reader.py @@ -43,12 +43,12 @@ def _simplify_input(input: str) -> str: input = input.lower().replace('wr', 'fff') return input -def get_move(input :str, character_movelist :dict): +def get_move(input: str, character_movelist: dict): result = [entry for entry in character_movelist if _simplify_input(entry["input"]) == _simplify_input(input)] if result: - result[0]['input'] = result[0]['input'].replace("\\","") + result[0]['input'] = result[0]['input'].replace("\\", "") return result[0] else: return {}