Skip to content

Commit 6a4b9bc

Browse files
Merge main into docs-updates
2 parents 8920378 + 18e3a26 commit 6a4b9bc

1 file changed

Lines changed: 72 additions & 45 deletions

File tree

cogs/strike.py

Lines changed: 72 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,18 @@ async def get_confirmation_message_channel(
457457
if not raw_user:
458458
raise StrikeTrackingError
459459

460-
dm_confirmation_message_channel: discord.DMChannel = await raw_user.create_dm()
460+
try:
461+
dm_confirmation_message_channel: discord.DMChannel = await raw_user.create_dm()
462+
except discord.Forbidden:
463+
logger.warning("Failed to create DM channel with %s", raw_user)
464+
465+
try:
466+
return await self.bot.fetch_log_channel()
467+
except RuntimeError as fetch_log_channel_error:
468+
raise StrikeTrackingError(
469+
str(fetch_log_channel_error)
470+
) from fetch_log_channel_error
471+
461472
if not dm_confirmation_message_channel.recipient:
462473
dm_confirmation_message_channel.recipient = raw_user
463474

@@ -479,7 +490,7 @@ async def get_confirmation_message_channel(
479490
return guild_confirmation_message_channel
480491

481492
@capture_strike_tracking_error
482-
async def _confirm_manual_add_strike(
493+
async def _confirm_manual_add_strike( # noqa: PLR0915
483494
self, strike_user: discord.User | discord.Member, action: discord.AuditLogAction
484495
) -> None:
485496
# NOTE: Shortcut accessors are placed at the top of the function, so that the exceptions they raise are displayed before any further errors may be sent
@@ -540,28 +551,37 @@ async def _confirm_manual_add_strike(
540551
or (action == discord.AuditLogAction.ban and member_strikes.strikes > 3)
541552
)
542553
if STRIKES_OUT_OF_SYNC_WITH_BAN:
543-
out_of_sync_ban_confirmation_message: discord.Message = await confirmation_message_channel.send( # noqa: E501
544-
content=(
545-
f"""Hi {
546-
applied_action_user.display_name
547-
if not applied_action_user.bot and applied_action_user != strike_user
548-
else committee_role.mention
549-
}, """
550-
f"""I just noticed that {
551-
"you"
552-
if not applied_action_user.bot
553-
else f"one of your other bots (namely {applied_action_user.mention})"
554-
} {FORMATTED_MODERATION_ACTIONS[action]} {strike_user.mention}. """
555-
"Because this moderation action was done manually "
556-
"(rather than using my `/strike` command), I could not automatically "
557-
f"keep track of the moderation action to apply. "
558-
f"My records show that {strike_user.mention} previously had 3 strikes. "
559-
f"This suggests that {strike_user.mention} should be banned. "
560-
"Would you like me to send them the moderation alert message "
561-
"and perform this action for you?"
562-
),
563-
view=ConfirmStrikesOutOfSyncWithBanView(),
564-
)
554+
try:
555+
out_of_sync_ban_confirmation_message: discord.Message = await confirmation_message_channel.send( # noqa: E501
556+
content=(
557+
f"""Hi {
558+
applied_action_user.display_name
559+
if not applied_action_user.bot
560+
and applied_action_user != strike_user
561+
else committee_role.mention
562+
}, """
563+
f"""I just noticed that {
564+
"you"
565+
if not applied_action_user.bot
566+
else "one of your other bots "
567+
f"(namely {applied_action_user.mention})"
568+
} {FORMATTED_MODERATION_ACTIONS[action]} {strike_user.mention}. """
569+
"Because this moderation action was done manually "
570+
"(rather than using my `/strike` command), I could not automatically "
571+
f"keep track of the moderation action to apply. "
572+
f"My records show that {strike_user.mention} previously had 3 strikes."
573+
f" This suggests that {strike_user.mention} should be banned. "
574+
"Would you like me to send them the moderation alert message "
575+
"and perform this action for you?"
576+
),
577+
view=ConfirmStrikesOutOfSyncWithBanView(),
578+
)
579+
except discord.Forbidden:
580+
logger.warning(
581+
"Failed to send out-of-sync ban confirmation message to %s",
582+
applied_action_user,
583+
)
584+
return
565585

566586
out_of_sync_ban_button_interaction: discord.Interaction = await self.bot.wait_for(
567587
"interaction",
@@ -631,27 +651,34 @@ async def _confirm_manual_add_strike(
631651

632652
raise ValueError
633653

634-
confirmation_message: discord.Message = await confirmation_message_channel.send(
635-
content=(
636-
f"""Hi {
637-
applied_action_user.display_name
638-
if not applied_action_user.bot and applied_action_user != strike_user
639-
else committee_role.mention
640-
}, """
641-
f"""I just noticed that {
642-
"you"
643-
if not applied_action_user.bot
644-
else f"one of your other bots (namely {applied_action_user.mention})"
645-
} {FORMATTED_MODERATION_ACTIONS[action]} {strike_user.mention}. """
646-
"Because this moderation action was done manually "
647-
"(rather than using my `/strike` command), I could not automatically "
648-
f"keep track of the correct moderation action to apply. "
649-
f"Would you like me to increase {strike_user.mention}'s strikes "
650-
f"from {member_strikes.strikes} to {member_strikes.strikes + 1} "
651-
"and send them the moderation alert message?"
652-
),
653-
view=ConfirmManualModerationView(),
654-
)
654+
try:
655+
confirmation_message: discord.Message = await confirmation_message_channel.send(
656+
content=(
657+
f"""Hi {
658+
applied_action_user.display_name
659+
if not applied_action_user.bot and applied_action_user != strike_user
660+
else committee_role.mention
661+
}, """
662+
f"""I just noticed that {
663+
"you"
664+
if not applied_action_user.bot
665+
else f"one of your other bots (namely {applied_action_user.mention})"
666+
} {FORMATTED_MODERATION_ACTIONS[action]} {strike_user.mention}. """
667+
"Because this moderation action was done manually "
668+
"(rather than using my `/strike` command), I could not automatically "
669+
f"keep track of the correct moderation action to apply. "
670+
f"Would you like me to increase {strike_user.mention}'s strikes "
671+
f"from {member_strikes.strikes} to {member_strikes.strikes + 1} "
672+
"and send them the moderation alert message?"
673+
),
674+
view=ConfirmManualModerationView(),
675+
)
676+
except discord.Forbidden:
677+
logger.warning(
678+
"Failed to send manual moderation confirmation message to %s",
679+
applied_action_user,
680+
)
681+
return
655682

656683
button_interaction: discord.Interaction = await self.bot.wait_for(
657684
"interaction",

0 commit comments

Comments
 (0)