Skip to content

Commit

Permalink
Add most basic version of slash command
Browse files Browse the repository at this point in the history
  • Loading branch information
TLNBS2405 committed Nov 21, 2023
1 parent fcc0df0 commit 27d61b2
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 18 deletions.
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -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
10 changes: 0 additions & 10 deletions src/dc/connector.py

This file was deleted.

38 changes: 33 additions & 5 deletions src/main.py
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -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:
Expand All @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions src/module/json_movelist_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}

0 comments on commit 27d61b2

Please sign in to comment.