Skip to content

Commit

Permalink
Fix GameSession namings (#40)
Browse files Browse the repository at this point in the history
  • Loading branch information
antonkomarev authored Aug 21, 2022
1 parent 95a71b4 commit 123f701
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 16 deletions.
20 changes: 12 additions & 8 deletions app/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,25 +59,27 @@ async def on_help_command(chat: Chat, match):
@bot.command("(?s)/poker\s+(.+)$")
@bot.command("/(poker)$")
async def on_poker_command(chat: Chat, match):
topic_message_id = str(chat.message["message_id"])
chat_id = chat.id
facilitator_message_id = str(chat.message["message_id"])
topic = match.group(1)
facilitator = chat.sender

if topic == "poker":
topic = "(no topic)"

game_id = 0

game_session = GameSession(game_id, chat.id, topic_message_id, chat.sender, topic)
game_session = GameSession(game_id, chat_id, facilitator_message_id, topic, facilitator)
await create_game_session(chat, game_session)


@bot.callback(r"discussion-vote-click-(.*?)-(.*?)$")
async def on_discussion_vote_click(chat: Chat, callback_query: CallbackQuery, match):
logbook.info("{}", callback_query)
topic_message_id = int(match.group(1))
facilitator_message_id = int(match.group(1))
vote = match.group(2)
result = "Vote `{}` accepted".format(vote)
game_session = await game_registry.find_active_game_session(chat.id, topic_message_id)
game_session = await game_registry.find_active_game_session(chat.id, facilitator_message_id)

if not game_session:
return await callback_query.answer(text="No such game session")
Expand All @@ -96,10 +98,11 @@ async def on_discussion_vote_click(chat: Chat, callback_query: CallbackQuery, ma
@bot.callback(r"estimation-vote-click-(.*?)-(.*?)$")
async def on_estimation_vote_click(chat: Chat, callback_query: CallbackQuery, match):
logbook.info("{}", callback_query)
topic_message_id = int(match.group(1))
chat_id = chat.id
facilitator_message_id = int(match.group(1))
vote = match.group(2)
result = "Vote `{}` accepted".format(vote)
game_session = await game_registry.find_active_game_session(chat.id, topic_message_id)
game_session = await game_registry.find_active_game_session(chat_id, facilitator_message_id)

if not game_session:
return await callback_query.answer(text="No such game session")
Expand All @@ -118,8 +121,9 @@ async def on_estimation_vote_click(chat: Chat, callback_query: CallbackQuery, ma
@bot.callback(r"({})-click-(.*?)$".format("|".join(FACILITATOR_OPERATIONS)))
async def on_facilitator_operation_click(chat: Chat, callback_query: CallbackQuery, match):
operation = match.group(1)
topic_message_id = int(match.group(2))
game_session = await game_registry.find_active_game_session(chat.id, topic_message_id)
chat_id = chat.id
facilitator_message_id = int(match.group(2))
game_session = await game_registry.find_active_game_session(chat_id, facilitator_message_id)

if not game_session:
return await callback_query.answer(text="No such game session")
Expand Down
22 changes: 14 additions & 8 deletions app/game_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ class GameSession:
["✂️", "♾️", "❓", "☕"],
]

def __init__(self, game_id, chat_id, topic_message_id, facilitator, topic):
def __init__(self, game_id, chat_id, facilitator_message_id, topic, facilitator):
self.game_id = game_id
self.chat_id = chat_id
self.facilitator_message_id = topic_message_id
self.facilitator_message_id = facilitator_message_id
self.system_message_id = 0
self.phase = self.PHASE_DISCUSSION
self.facilitator = facilitator
self.topic = topic
self.facilitator = facilitator
self.estimation_votes = collections.defaultdict(EstimationVote)
self.discussion_votes = collections.defaultdict(DiscussionVote)

Expand Down Expand Up @@ -207,17 +207,23 @@ def votes_to_json(votes):

def to_dict(self):
return {
"system_message_id": self.system_message_id,
"phase": self.phase,
"system_message_id": self.system_message_id, # TODO: Move out from json
"phase": self.phase, # TODO: Move out from json
"topic": self.topic, # TODO: Move out from json
"facilitator": self.facilitator,
"topic": self.topic,
"discussion_votes": self.votes_to_json(self.discussion_votes),
"estimation_votes": self.votes_to_json(self.estimation_votes),
}

@classmethod
def from_dict(cls, game_id, chat_id, topic_message_id, dict):
result = cls(game_id, chat_id, topic_message_id, dict["facilitator"], dict["topic"])
def from_dict(cls, game_id, chat_id, facilitator_message_id, dict):
result = cls(
game_id,
chat_id,
facilitator_message_id,
dict["topic"],
dict["facilitator"],
)
result.system_message_id = dict["system_message_id"]
result.phase = dict["phase"]

Expand Down

0 comments on commit 123f701

Please sign in to comment.