diff --git a/README.md b/README.md index 0ce6601..baee8e7 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,21 @@ -# heihachi +# Heihachi A discord bot to receive Tekken 8 frame data primary from [wavu.wiki](https://wavu.wiki/t/Wavu:Tekken_8) + +## Instruction + +Clone this to a linux server that has Python 3.10.0+ and install the dependencies with: +```py +pip install -r requirements.txt +``` + +You need your own discord bot ([instructions](https://github.com/reactiflux/discord-irc/wiki/Creating-a-discord-bot-&-getting-a-token)) and have the tokens in the `src/resources/config.json`. You can add a feedback channel there also. + + +The executable is `src/main.py`. + +## Commands +``` +Slash Command +/fd - get frame data of a move from a character + +``` \ No newline at end of file diff --git a/src/main.py b/src/main.py index 1c58857..d25a849 100644 --- a/src/main.py +++ b/src/main.py @@ -1,7 +1,7 @@ import json, datetime, logging, os, discord, sched, time from typing import List -from src.module import character_importer +from src.module import wavu_importer from src.module import configurator from src.module import json_movelist_reader from src.module import embed @@ -49,40 +49,41 @@ async def self(interaction: discord.Interaction, character_name: str, move: str) character_name = util.correct_character_name(character_name.lower()) character = util.get_character_by_name(character_name, character_list) - move_list = json_movelist_reader.get_movelist_from_json(character_name) + move_list = json_movelist_reader.get_movelist(character_name) character_move = json_movelist_reader.get_move(move, move_list) move_embed = embed.move_embed(character, character_move) await interaction.response.send_message(embed=move_embed, ephemeral=False) -def create_all_character_json(character_list_path: str) -> List[character.Character]: +def create_json_movelists(character_list_path: str) -> List[character.Character]: with open(character_list_path) as file: - characters = json.load(file) + all_characters = json.load(file) character_list = [] - for character_meta in characters: - character = character_importer.import_character(character_meta) + for character_meta in all_characters: + character = wavu_importer.import_character(character_meta) character.export_movelist_as_json() character_list.append(character) return character_list -def schedule_create_all_characters(character_list_path: str, scheduler): +def schedule_create_json_movelists(character_list_path: str, scheduler): try: - create_all_character_json(character_list_path) - scheduler.enter(3600,1,create_all_character_json, (character_list_path,scheduler,)) + create_json_movelists(character_list_path) + scheduler.enter(3600, 1, create_json_movelists, (character_list_path, scheduler,)) except Exception as e: raise Exception("Error when importing character from wavu" + str(e)) try: - ## Repeat creating character json once an hour - character_list = create_all_character_json(character_list_path) + character_list = create_json_movelists(character_list_path) print("Character jsons are successfully created") scheduler = sched.scheduler(time.time, time.sleep) - scheduler.enter(3600,1,schedule_create_all_characters, (character_list_path,scheduler,)) + + ## Repeat importing move list of all character from wavu.wiki once an hour + scheduler.enter(3600, 1, schedule_create_json_movelists, (character_list_path, scheduler,)) Thread(target=scheduler.run).start() client.run(discord_token) diff --git a/src/module/json_movelist_reader.py b/src/module/json_movelist_reader.py index d40e586..0579593 100644 --- a/src/module/json_movelist_reader.py +++ b/src/module/json_movelist_reader.py @@ -4,7 +4,7 @@ base_path = os.path.dirname(__file__) -def get_movelist_from_json(character_name: str) -> dict: +def get_movelist(character_name: str) -> dict: os.path.abspath(os.path.join(base_path, "..", "json_movelist", character_name + ".json")) filepath = os.path.abspath(os.path.join(base_path, "..", "json_movelist", character_name + ".json")) with open(filepath) as move_file: diff --git a/src/module/test/test_character_importer.py b/src/module/test/test_character_importer.py index 4adfb5d..61c6719 100644 --- a/src/module/test/test_character_importer.py +++ b/src/module/test/test_character_importer.py @@ -1,5 +1,5 @@ import unittest, json, os -from src.module import character_importer +from src.module import wavu_importer dir_path = os.path.dirname(os.path.realpath(__file__)) @@ -10,5 +10,5 @@ def test_character_importer(self): azu_json = dir_path + "/azu.json" with open(azu_json) as azu: azu_meta = json.load(azu) - azucena = character_importer.import_character(azu_meta) + azucena = wavu_importer.import_character(azu_meta) self.assertEqual(azucena.name, "Azucena") diff --git a/src/module/test/test_json_movelist_reader.py b/src/module/test/test_json_movelist_reader.py index a5b9eff..1ef187a 100644 --- a/src/module/test/test_json_movelist_reader.py +++ b/src/module/test/test_json_movelist_reader.py @@ -5,13 +5,13 @@ class MyTestCase(unittest.TestCase): def test_get_movelist_from_json(self): - result = json_movelist_reader.get_movelist_from_json("azucena") + result = json_movelist_reader.get_movelist("azucena") self.assertEqual(result[0]["id"],"Azucena-1") def test_get_move(self): - azu_move_list = json_movelist_reader.get_movelist_from_json("azucena") + azu_move_list = json_movelist_reader.get_movelist("azucena") move = json_movelist_reader.get_move("d/f+1",azu_move_list) self.assertEqual(move["id"],"Azucena-df+1") diff --git a/src/module/character_importer.py b/src/module/wavu_importer.py similarity index 100% rename from src/module/character_importer.py rename to src/module/wavu_importer.py