Skip to content

Commit

Permalink
refactor(bot): log additional steps in on_ready
Browse files Browse the repository at this point in the history
  • Loading branch information
natelandau committed Sep 10, 2023
1 parent eabc720 commit c5267bd
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 9 deletions.
9 changes: 4 additions & 5 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@ default_stages: [commit, manual]
fail_fast: true
repos:
- repo: "https://github.com/commitizen-tools/commitizen"
rev: 3.8.1
rev: 3.8.2
hooks:
- id: commitizen
- id: commitizen-branch
stages:
- post-commit
- push
# - id: commitizen-branch
# stages:
# - push

- repo: "https://github.com/pre-commit/pygrep-hooks"
rev: v1.10.0
Expand Down
9 changes: 8 additions & 1 deletion src/valentina/models/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,11 @@ async def on_ready(self) -> None:
# Setup Guilds
# #######################

logger.debug(f"Connected Guilds: {self.guilds=}")

for guild in self.guilds:
logger.info(f"CONNECT: Provision {guild.name} ({guild.id})")

# Create roles
storyteller = await bot_hooks.create_storyteller_role(guild)
player = await bot_hooks.create_player_role(guild)
Expand All @@ -99,14 +103,17 @@ async def on_ready(self) -> None:
storyteller: 2,
} # penultimate role
await guild.edit_role_positions(positions=positions) # type: ignore [arg-type]
logger.debug("CONNECT: Confirm role positions")

# Add guild to database
logger.debug("CONNECT: Add/update guild in database")
self.guild_svc.update_or_add(guild=guild)
logger.info(f"CONNECT: Playing on {guild.name} ({guild.id})")

# Send welcome message
await bot_hooks.send_changelog(self, guild)

logger.info(f"CONNECT: Playing on {guild.name} ({guild.id})")

# Update all character default values in case something changed
self.char_svc.set_character_default_values()

Expand Down
1 change: 1 addition & 0 deletions src/valentina/models/characters.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ def custom_section_update_or_add(

def set_character_default_values(self) -> None:
"""Set default values for all characters in the database."""
logger.info("DATABASE: Set default values for all characters")
characters = Character.select()
for character in characters:
character.set_default_data_values()
Expand Down
6 changes: 4 additions & 2 deletions src/valentina/utils/bot_hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ async def send_changelog(bot: commands.Bot, guild: discord.Guild) -> None:
Returns:
None
"""
logger.debug(f"CONNECT: Sending changelog to {guild.name} if needed")

# If the guild does not have a changelog channel, return
db_guild = Guild.get_by_id(guild.id)
db_changelog_channel_id = db_guild.data.get("changelog_channel_id", None)
Expand Down Expand Up @@ -146,7 +148,7 @@ async def create_storyteller_role(guild: discord.Guild) -> discord.Role:
view_channel=True,
)
await storyteller.edit(reason=None, permissions=perms)
logger.debug(f"CONNECT: {storyteller.name} role created")
logger.debug(f"CONNECT: {storyteller.name} role created/updated on {guild.name}")

return storyteller

Expand Down Expand Up @@ -191,7 +193,7 @@ async def create_player_role(guild: discord.Guild) -> discord.Role:
view_channel=True,
)
await player.edit(reason=None, permissions=perms)
logger.debug(f"CONNECT: {player.name} role created")
logger.debug(f"CONNECT: {player.name} role created/updated on {guild.name}")

return player

Expand Down
2 changes: 1 addition & 1 deletion src/valentina/views/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ def _home_embed(self) -> pages.PageGroup:
f"Update trait values: {PermissionsEditTrait(self.current_settings['permissions_edit_trait']).name.title()}",
"# Channel Settings:",
f"Changelog channel : {changelog_channel.name}"
if storyteller_channel is not None
if changelog_channel is not None
else "Changelog channel : Not set",
f"Storyteller channel: {storyteller_channel.name}"
if storyteller_channel is not None
Expand Down

0 comments on commit c5267bd

Please sign in to comment.