Skip to content

Commit

Permalink
refactor(verify): add fallback logging if channels are missing
Browse files Browse the repository at this point in the history
  • Loading branch information
rippleFCL committed Feb 17, 2025
1 parent ed1ea7f commit 55db436
Showing 1 changed file with 32 additions and 9 deletions.
41 changes: 32 additions & 9 deletions verify/verify.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""discord red-bot verify"""

import logging
from datetime import timedelta
from typing import Optional

Expand All @@ -8,6 +9,8 @@
from redbot.core import Config, checks, commands
from redbot.core.utils.mod import is_mod_or_superior

logger = logging.getLogger("red.rhomelab.verify")


class VerifyCog(commands.Cog):
"""Verify Cog"""
Expand Down Expand Up @@ -130,6 +133,8 @@ async def on_member_update(self, before: discord.Member, after: discord.Member):
welcomemsg = welcomemsg.format(user=after.mention)
if channel := self._is_valid_channel(guild.get_channel(welcomechannel)):
await channel.send(welcomemsg)
else:
logger.warning(f"Failed to get welcome channel {welcomechannel}, in guild {guild}")

# Command groups

Expand Down Expand Up @@ -299,7 +304,7 @@ async def _set_fuzziness(self, ctx: commands.GuildContext, fuzziness: int):
await ctx.send(f"Fuzzy matching threshold for verification set to `{fuzziness}%`")

@_verify.command("status")
async def verify_status(self, ctx: commands.GuildContext):
async def verify_status(self, ctx: commands.GuildContext): # noqa: PLR0912, PLR0915
"""Status of the cog.
The bot will display how many users it has verified
since it's inception.
Expand Down Expand Up @@ -335,15 +340,29 @@ async def verify_status(self, ctx: commands.GuildContext):
embed = discord.Embed(colour=(await ctx.embed_colour()))
embed.add_field(name="Verified", value=f"{count} users")

if role_id and (role := ctx.guild.get_role(role_id)):
embed.add_field(name="Role", value=role.mention)

if channel_id and (channel := self._is_valid_channel(ctx.guild.get_channel(channel_id))):
embed.add_field(name="Channel", value=channel.mention)
if role_id:
if role := ctx.guild.get_role(role_id):
embed.add_field(name="Role", value=role.mention)
else:
embed.add_field(name="ERROR: role with ID not found", value=role_id)
else:
embed.add_field(name="ERROR: role ID missing", value="")

if log_id and (log_channel := self._is_valid_channel(ctx.guild.get_channel(log_id))):
embed.add_field(name="Log", value=log_channel.mention)
if channel_id:
if channel := self._is_valid_channel(ctx.guild.get_channel(channel_id)):
embed.add_field(name="Channel", value=channel.mention)
else:
embed.add_field(name="ERROR: Channel with ID not found", value=channel_id)
else:
embed.add_field(name="ERROR: Channel ID missing", value="")

if log_id:
if log_channel := self._is_valid_channel(ctx.guild.get_channel(log_id)):
embed.add_field(name="Log", value=log_channel.mention)
else:
embed.add_field(name="ERROR: Log channel with ID not found", value=log_id)
else:
embed.add_field(name="ERROR: Log channel ID missing", value="")
embed.add_field(name="Min Time", value=f"{mintime} secs")
embed.add_field(name="Message", value=f"`{message}`")
embed.add_field(name="Too Quick Msg", value=f"`{tooquick}`")
Expand All @@ -360,8 +379,10 @@ async def verify_status(self, ctx: commands.GuildContext):
if welcome_ignore_roles:
welcome_ignore = ""
for role in welcome_ignore_roles:
if discord_role := ctx.guild.get_role(role):
if role and (discord_role := ctx.guild.get_role(role)):
welcome_ignore += f"{discord_role.name}, "
else:
await ctx.send(f"ERROR: Welcome ignore role not found: {role}")
embed.add_field(name="Welcome Ignore Roles", value=welcome_ignore.rstrip(", "))

embed.add_field(name="# Users Blocked", value=f"`{len(blocked_users)}`")
Expand Down Expand Up @@ -449,6 +470,8 @@ async def _verify_user(self, guild: discord.Guild, member: discord.Member):
return True
elif log_id and (log_channel := self._is_valid_channel(guild.get_channel(log_id))):
await log_channel.send(f"**User Not Verified Due To Error** - missing verified role. role_id: {role_id}")
else:
logger.warning(f"Failed to get log channel {log_id}, in guild {guild}")
return False

@_verify.group(name="welcomeignore")
Expand Down

0 comments on commit 55db436

Please sign in to comment.