Skip to content

Commit

Permalink
Merge pull request #28 from yomcube/dmhandler-experiment
Browse files Browse the repository at this point in the history
Enhance DM handler API
  • Loading branch information
Dash-QC authored Dec 15, 2024
2 parents 3b925b8 + c56914a commit dcae2bb
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
10 changes: 10 additions & 0 deletions api/dm_handlers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
handlers_dict = {}
def add_dm_handler(comp, func):
handlers_dict[comp] = func

def init_dm_handlers():
from api.mkwii.mkwii_file_handling import handle_mkwii_files
add_dm_handler("mkw", handle_mkwii_files)

from api.nsmbwii.nsmbwii_file_handling import handle_nsmbwii_files
add_dm_handler("nsmbw", handle_nsmbwii_files)
17 changes: 7 additions & 10 deletions api/submissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from api.db_classes import SubmissionChannel, Userbase, get_session, Submissions, LogChannel, SeekingChannel, Teams
from sqlalchemy import insert, select, or_
from api.utils import get_file_types, get_leader, get_team_size, is_in_team, get_submitter_role, is_task_currently_running
from api.dm_handlers import handlers_dict, init_dm_handlers

load_dotenv()
DEFAULT = os.getenv('DEFAULT')
Expand Down Expand Up @@ -257,15 +258,11 @@ async def handle_dms(message, self):
if len(attachments) > 0:
file_dict = get_file_types(attachments)
try:
# TODO: use a class here?
if DEFAULT == "mkw":
from api.mkwii.mkwii_file_handling import handle_mkwii_files
await handle_mkwii_files(message, attachments, file_dict, self)
elif DEFAULT == "nsmbw":
from api.nsmbwii.nsmbwii_file_handling import handle_nsmbwii_files
await handle_nsmbwii_files(message, attachments, file_dict, self)
else:
pass

await handlers_dict[DEFAULT](message, attachments, file_dict, self)

except KeyError:
print(f"Could not find DM handler for '{DEFAULT}'.")
except TimeoutError:
await channel.send("Could not process Files!")

init_dm_handlers()

0 comments on commit dcae2bb

Please sign in to comment.