1515from bot .exts .filtering ._filter_context import FilterContext
1616from bot .exts .filtering ._settings_types .settings_entry import ActionEntry
1717from bot .exts .filtering ._utils import CustomIOField , FakeContext
18+ from bot .exts .moderation .infraction import _utils as infraction_utils
1819from bot .utils .time import humanize_delta , parse_duration_string , relativedelta_to_timedelta
1920
2021log = get_logger (__name__ )
@@ -87,14 +88,14 @@ async def invoke(
8788 alerts_channel : discord .TextChannel ,
8889 duration : InfractionDuration ,
8990 reason : str
90- ) -> None :
91+ ) -> str | None :
9192 """Invokes the command matching the infraction name."""
9293 command_name = self .name .lower ()
9394 command = bot_module .instance .get_command (command_name )
9495 if not command :
9596 await alerts_channel .send (f":warning: Could not apply { command_name } to { user .mention } : command not found." )
9697 log .warning (f":warning: Could not apply { command_name } to { user .mention } : command not found." )
97- return
98+ return None
9899
99100 if isinstance (user , discord .User ): # For example because a message was sent in a DM.
100101 member = await get_or_fetch_member (channel .guild , user .id )
@@ -105,14 +106,20 @@ async def invoke(
105106 f"The user { user } were set to receive an automatic { command_name } , "
106107 "but they were not found in the guild."
107108 )
108- return
109+ return None
109110
110111 ctx = FakeContext (message , channel , command )
112+ if self is Infraction .BAN :
113+ active_infraction = await infraction_utils .get_active_infraction (ctx , user , "ban" , send_msg = False )
114+ if active_infraction :
115+ return "already banned"
116+
111117 if self .name in ("KICK" , "WARNING" , "WATCH" , "NOTE" ):
112118 await command (ctx , user , reason = reason or None )
113119 else :
114120 duration = arrow .utcnow ().datetime + duration .value if duration .value else None
115121 await command (ctx , user , duration , reason = reason or None )
122+ return passive_form [self .name ]
116123
117124
118125class InfractionAndNotification (ActionEntry ):
@@ -203,10 +210,11 @@ async def action(self, ctx: FilterContext) -> None:
203210 log .error (f"Unable to apply infraction as the context channel { channel } can't be found." )
204211 return
205212
206- await self .infraction_type .invoke (
213+ infraction_action = await self .infraction_type .invoke (
207214 ctx .author , ctx .message , channel , alerts_channel , self .infraction_duration , self .infraction_reason
208215 )
209- ctx .action_descriptions .append (passive_form [self .infraction_type .name ])
216+ if infraction_action :
217+ ctx .action_descriptions .append (infraction_action )
210218
211219 def union (self , other : Self ) -> Self :
212220 """
0 commit comments