Skip to content

Commit

Permalink
✨ | Store rooms informations in rooms.json
Browse files Browse the repository at this point in the history
  • Loading branch information
SayuryKato committed Oct 24, 2022
1 parent dbd9e82 commit 0321d13
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 22 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -160,4 +160,5 @@ cython_debug/
#.idea/

# Local user
test.py
test.py
**/src/json/rooms.json
40 changes: 21 additions & 19 deletions calax/model/instances/calax/__init__.py
Original file line number Diff line number Diff line change
@@ -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')
Expand All @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions calax/model/service/calax/commands/help/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
7 changes: 7 additions & 0 deletions calax/src/json/rooms.example.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[
{
"bot_master": "",
"id_text_channel": "",
"id_voice_channel": ""
}
]

0 comments on commit 0321d13

Please sign in to comment.