Skip to content

Commit

Permalink
Merge pull request #84 from lesteenman/add-logging
Browse files Browse the repository at this point in the history
Add some more info-level logging
  • Loading branch information
lesteenman authored Nov 15, 2022
2 parents 48a4d58 + 483ca09 commit 8f4ecb6
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import re

from loguru import logger

from eternal_guesses.app.component_ids import ComponentIds
from eternal_guesses.model.discord.discord_event import DiscordEvent
from eternal_guesses.model.discord.discord_response import DiscordResponse
Expand Down Expand Up @@ -34,6 +36,10 @@ async def call(self, event: DiscordEvent) -> DiscordResponse:
fr"{ComponentIds.component_button_close_game_prefix}(.*)",
event.component_action.component_custom_id
).group(1)

logger.info(f"guild {guild_id}, user {event.member.user_id}, closing "
f"game {game_id}")

await self.games_service.close(
guild_id=guild_id,
game_id=game_id,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import re

from loguru import logger

from eternal_guesses.app.component_ids import ComponentIds
from eternal_guesses.model.discord.discord_event import DiscordEvent
from eternal_guesses.model.discord.discord_response import DiscordResponse
Expand Down Expand Up @@ -34,6 +36,10 @@ async def call(self, event: DiscordEvent) -> DiscordResponse:
fr"{ComponentIds.component_button_reopen_game_prefix}(.*)",
event.component_action.component_custom_id
).group(1)

logger.info(f"guild {event.guild_id}, user {event.member.user_id}, "
f"reopening game {game_id}")

await self.games_service.reopen(
guild_id=guild_id,
game_id=game_id,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import re

from loguru import logger

from eternal_guesses.model.discord.discord_event import DiscordEvent
from eternal_guesses.model.discord.discord_response import DiscordResponse
from eternal_guesses.routes.route import Route
Expand Down Expand Up @@ -37,6 +39,9 @@ async def call(self, event: DiscordEvent) -> DiscordResponse:

channel_id = int(event.component_action.values[0])

logger.info(f"guild {event.guild_id}, user {event.member.user_id}, "
f"posting game {game_id} to channel {channel_id}")

await self.games_service.post(
guild_id=event.guild_id,
game_id=game_id,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import re
from datetime import datetime

from loguru import logger

from eternal_guesses.model.data.game import Game
from eternal_guesses.model.discord.discord_component import ActionRow, \
DiscordComponent
Expand Down Expand Up @@ -38,6 +40,8 @@ async def call(self, event: DiscordEvent) -> DiscordResponse:
inputs[ComponentIds.submit_create_input_game_id]
)

logger.info(f"user {event.member.user_id} creating game {game_id}")

title = inputs[ComponentIds.submit_create_input_title]
description = inputs[ComponentIds.submit_create_input_description]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
import typing
from abc import ABC

from loguru import logger

from eternal_guesses.app.component_ids import ComponentIds
from eternal_guesses.model.discord.discord_event import DiscordEvent
from eternal_guesses.model.discord.discord_response import DiscordResponse
Expand Down Expand Up @@ -42,6 +44,10 @@ async def call(self, event: DiscordEvent) -> DiscordResponse:
if self.is_numeric:
new_value = int(new_value)

logger.info(f"guild_id={event.guild_id}, user {event.member.user_id} "
f"editing game, field {self.input_id}, new value is"
f"{new_value}")

await self.game_update_func(event.guild_id, game_id, new_value)

return DiscordResponse.ephemeral_channel_message(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import re

from loguru import logger

from eternal_guesses.model.discord.discord_event import DiscordEvent
from eternal_guesses.model.discord.discord_response import DiscordResponse
from eternal_guesses.routes.route import Route
Expand Down Expand Up @@ -35,6 +37,10 @@ async def call(self, event: DiscordEvent) -> DiscordResponse:
member_id = int(matches.group(2))
new_guess = modal_submit.inputs[ComponentIds.edit_guess_modal_input_id]

logger.info(f"guild_id={event.guild_id}, user {event.member.user_id} "
f"editing guess by member {member_id} in "
f"game {game_id} to guess '{new_guess}'")

await self.guesses_service.edit(
guild_id=event.guild_id,
game_id=game_id,
Expand Down
Empty file.
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import re
from datetime import datetime

from loguru import logger

from eternal_guesses.model.data.game import Game
from eternal_guesses.model.data.game_guess import GameGuess
from eternal_guesses.model.discord.discord_event import DiscordEvent
Expand Down Expand Up @@ -43,6 +45,10 @@ async def call(self, event: DiscordEvent) -> DiscordResponse:
).group(1)
guess = event.modal_submit.inputs[ComponentIds.submit_guess_input_value]

logger.info(f"guild_id={guild_id}, user {user_id} "
f"(nick='{user_nickname}') placed guess {guess} "
f"on game {game_id}")

game = self.games_repository.get(guild_id, game_id)
if game is None:
error_message = self.message_provider.error_game_not_found(game_id)
Expand Down
4 changes: 2 additions & 2 deletions discord_app/eternal_guesses/services/guesses_service.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from eternal_guesses.app.game_post_manager import GamePostManager
from eternal_guesses.exceptions import GuessNotFoundError, GameNotFoundError
from eternal_guesses.repositories.games_repository import GamesRepository
from eternal_guesses.app.game_post_manager import GamePostManager


class GuessesService:
Expand All @@ -16,7 +16,7 @@ async def edit(self, guild_id: int, game_id: str, member: int, guess: str):
game = self.games_repository.get(guild_id=guild_id, game_id=game_id)

if game is None:
raise GameNotFoundError(f"could not foind game {game_id}")
raise GameNotFoundError(f"could not find game {game_id}")

if member not in game.guesses:
raise GuessNotFoundError(
Expand Down

0 comments on commit 8f4ecb6

Please sign in to comment.