@@ -91,11 +91,11 @@ async def perform_moderation_action(
9191class ConfirmStrikeMemberView (View ):
9292 """A discord.View containing two buttons to confirm giving the member a strike."""
9393
94- @discord .ui .button ( # type: ignore[arg-type]
94+ @discord .ui .button (
9595 label = "Yes" , style = discord .ButtonStyle .red , custom_id = "yes_strike_member"
9696 )
9797 async def yes_strike_member_button_callback (
98- self , _ : discord .Button , interaction : discord .Interaction
98+ self , _ : discord .ui . Button [ "ConfirmStrikeMemberView" ] , interaction : discord .Interaction
9999 ) -> None :
100100 """
101101 Delete the message associated with the view when the Yes button is pressed.
@@ -110,11 +110,11 @@ async def yes_strike_member_button_callback(
110110 view = None
111111 ) # NOTE: Despite removing the view within the normal command processing loop, the view also needs to be removed here to prevent an Unknown Webhook error
112112
113- @discord .ui .button ( # type: ignore[arg-type]
113+ @discord .ui .button (
114114 label = "No" , style = discord .ButtonStyle .grey , custom_id = "no_strike_member"
115115 )
116116 async def no_strike_member_button_callback (
117- self , _ : discord .Button , interaction : discord .Interaction
117+ self , _ : discord .ui . Button [ "ConfirmStrikeMemberView" ] , interaction : discord .Interaction
118118 ) -> None :
119119 """
120120 Delete the message associated with the view when the No button is pressed.
@@ -133,11 +133,13 @@ async def no_strike_member_button_callback(
133133class ConfirmManualModerationView (View ):
134134 """A discord.View to confirm manually applying a moderation action."""
135135
136- @discord .ui .button ( # type: ignore[arg-type]
136+ @discord .ui .button (
137137 label = "Yes" , style = discord .ButtonStyle .red , custom_id = "yes_manual_moderation_action"
138138 )
139139 async def yes_manual_moderation_action_button_callback (
140- self , _ : discord .Button , interaction : discord .Interaction
140+ self ,
141+ _ : discord .ui .Button ["ConfirmManualModerationView" ],
142+ interaction : discord .Interaction ,
141143 ) -> None :
142144 """
143145 Delete the message associated with the view when the Yes button is pressed.
@@ -153,11 +155,13 @@ async def yes_manual_moderation_action_button_callback(
153155 view = None
154156 ) # NOTE: Despite removing the view within the normal command processing loop, the view also needs to be removed here to prevent an Unknown Webhook error
155157
156- @discord .ui .button ( # type: ignore[arg-type]
158+ @discord .ui .button (
157159 label = "No" , style = discord .ButtonStyle .grey , custom_id = "no_manual_moderation_action"
158160 )
159161 async def no_manual_moderation_action_button_callback (
160- self , _ : discord .Button , interaction : discord .Interaction
162+ self ,
163+ _ : discord .ui .Button ["ConfirmManualModerationView" ],
164+ interaction : discord .Interaction ,
161165 ) -> None :
162166 """
163167 Delete the message associated with the view when the No button is pressed.
@@ -177,11 +181,13 @@ async def no_manual_moderation_action_button_callback(
177181class ConfirmStrikesOutOfSyncWithBanView (View ):
178182 """A discord.View containing two buttons to confirm banning a member with > 3 strikes."""
179183
180- @discord .ui .button ( # type: ignore[arg-type]
184+ @discord .ui .button (
181185 label = "Yes" , style = discord .ButtonStyle .red , custom_id = "yes_out_of_sync_ban_member"
182186 )
183187 async def yes_out_of_sync_ban_member_button_callback (
184- self , _ : discord .Button , interaction : discord .Interaction
188+ self ,
189+ _ : discord .ui .Button ["ConfirmStrikesOutOfSyncWithBanView" ],
190+ interaction : discord .Interaction ,
185191 ) -> None :
186192 """
187193 Delete the message associated with the view when the Yes button is pressed.
@@ -197,11 +203,13 @@ async def yes_out_of_sync_ban_member_button_callback(
197203 view = None
198204 ) # NOTE: Despite removing the view within the normal command processing loop, the view also needs to be removed here to prevent an Unknown Webhook error
199205
200- @discord .ui .button ( # type: ignore[arg-type]
206+ @discord .ui .button (
201207 label = "No" , style = discord .ButtonStyle .grey , custom_id = "no_out_of_sync_ban_member"
202208 )
203209 async def no_out_of_sync_ban_member_button_callback (
204- self , _ : discord .Button , interaction : discord .Interaction
210+ self ,
211+ _ : discord .ui .Button ["ConfirmStrikesOutOfSyncWithBanView" ],
212+ interaction : discord .Interaction ,
205213 ) -> None :
206214 """
207215 Delete the message associated with the view when the No button is pressed.
@@ -229,7 +237,7 @@ class BaseStrikeCog(TeXBotBaseCog):
229237 SUGGESTED_ACTIONS : "Final[Mapping[int, str]]" = {1 : "time-out" , 2 : "kick" , 3 : "ban" } # noqa: RUF012
230238
231239 async def _send_strike_user_message (
232- self , strike_user : discord .User | discord . Member , member_strikes : DiscordMemberStrikes
240+ self , strike_user : discord .abc . Messageable , member_strikes : DiscordMemberStrikes
233241 ) -> None :
234242 try :
235243 await strike_user .send (
@@ -322,7 +330,7 @@ async def _confirm_increase_strike(
322330 * ,
323331 perform_action : bool ,
324332 ) -> None :
325- if perform_action and isinstance (strike_user , discord .User ):
333+ if perform_action and not isinstance (strike_user , discord .Member ):
326334 STRIKE_USER_TYPE_ERROR_MESSAGE : Final [str ] = (
327335 "Cannot perform moderation action on non-guild member."
328336 )
@@ -459,9 +467,9 @@ async def get_confirmation_message_channel(
459467 ) from fetch_log_channel_error
460468
461469 raw_user : discord .User | None = (
462- await self . bot . get_or_fetch ( discord . User , user . id )
463- if isinstance (user , discord .Member )
464- else user
470+ user
471+ if isinstance (user , discord .User )
472+ else await self . bot . get_or_fetch ( discord . User , user . id )
465473 )
466474 if not raw_user :
467475 raise StrikeTrackingError
@@ -512,9 +520,12 @@ async def _confirm_manual_add_strike( # noqa: PLR0915
512520 async for _audit_log_entry in main_guild .audit_logs (
513521 after = discord .utils .utcnow () - datetime .timedelta (minutes = 1 ), action = action
514522 )
515- if _audit_log_entry .target
516- and _audit_log_entry .target .id
517- == strike_user .id # NOTE: IDs are checked here rather than the objects themselves as the audit log provides an unusual object type in some cases.
523+ if (
524+ _audit_log_entry .target
525+ and (
526+ _audit_log_entry .target .id == strike_user .id
527+ ) # NOTE: IDs are checked here rather than the objects themselves as the audit log provides an unusual object type in some cases.
528+ )
518529 )
519530 except (StopIteration , StopAsyncIteration ):
520531 logger .debug ("Printing 5 most recent audit logs:" )
@@ -761,15 +772,14 @@ async def on_member_update(self, before: discord.Member, after: discord.Member)
761772
762773 audit_log_entry : discord .AuditLogEntry
763774 async for audit_log_entry in main_guild .audit_logs (limit = 5 ):
764- FOUND_CORRECT_AUDIT_LOG_ENTRY : bool = (
765- ( audit_log_entry .target is not None )
775+ if (
776+ audit_log_entry .target
766777 and (audit_log_entry .target .id == after .id )
767778 and (
768779 audit_log_entry .action
769780 == discord .AuditLogAction .auto_moderation_user_communication_disabled
770781 )
771- )
772- if FOUND_CORRECT_AUDIT_LOG_ENTRY :
782+ ):
773783 await self ._confirm_manual_add_strike (
774784 strike_user = after , action = audit_log_entry .action
775785 )
0 commit comments