diff --git a/.gitignore b/.gitignore index 48c3f64..cf37b4c 100644 --- a/.gitignore +++ b/.gitignore @@ -160,4 +160,5 @@ cython_debug/ #.idea/ # Local user -test.py \ No newline at end of file +test.py +**/src/json/rooms.json \ No newline at end of file diff --git a/calax/model/instances/calax/__init__.py b/calax/model/instances/calax/__init__.py index c8ec278..7ede835 100644 --- a/calax/model/instances/calax/__init__.py +++ b/calax/model/instances/calax/__init__.py @@ -1,14 +1,21 @@ -# Personal packages +# --------------- BUILT-IN PACKAGES --------------- +from dotenv import load_dotenv +import json +import os + + +# --------------- DISCORD PACKAGES --------------- +import discord +from discord.ext import ( + commands +) + +# --------------- PERSONAL PACKAGES --------------- from model.entities.calax import Calax from model.entities.game import Game from model.entities.room import Room from model.entities.player import Player - -# External packges -import discord -from discord.ext import commands -from dotenv import load_dotenv -import os +from util import ROOT_PATH load_dotenv() TOKEN: str = os.getenv('TOKEN') @@ -33,18 +40,13 @@ bot = bot ) -rooms = [ - { - 'bot_master': '546840612972789782', - 'id_text_channel': '1018594639021875271', - 'id_voice_channel': '910507210906431498' - }, - { - 'bot_master': '772066124052693013', - 'id_text_channel': '1018594664259006504', - 'id_voice_channel': '910518654926475274' - } -] +# Load rooms informations +rooms_path: str = f'{ROOT_PATH}/src/json/rooms.json' +with open( + file = rooms_path, + mode = 'r' + ) as rooms_as_json: + rooms: list[dict[str, str]] = json.load(rooms_as_json) # Add all games to calax for room in rooms: diff --git a/calax/model/service/calax/commands/help/__init__.py b/calax/model/service/calax/commands/help/__init__.py index df6e5ff..d64aca1 100644 --- a/calax/model/service/calax/commands/help/__init__.py +++ b/calax/model/service/calax/commands/help/__init__.py @@ -41,9 +41,9 @@ async def help(context: Context): encoding = 'utf-8' ) as questions_as_json: - questions_as_dict: dict[str, list[str]] = json.load(questions_as_json) + questions: dict[str, list[str]] = json.load(questions_as_json) # It chooses a question - chosen_question = choice(questions_as_dict[room.game.victim.response]) + chosen_question = choice(questions[room.game.victim.response]) await context.send(f'<@{room.game.victim.id}>, {chosen_question}') break diff --git a/calax/src/json/rooms.example.json b/calax/src/json/rooms.example.json new file mode 100644 index 0000000..2ff3b3b --- /dev/null +++ b/calax/src/json/rooms.example.json @@ -0,0 +1,7 @@ +[ + { + "bot_master": "", + "id_text_channel": "", + "id_voice_channel": "" + } +] \ No newline at end of file