@@ -18,9 +18,9 @@ def _make_actions(send_alert: bool) -> ActionSettings:
1818 return actions
1919
2020 @staticmethod
21- def _make_context (* , author_id : int = 1 , channel_id : int = 10 ) -> FilterContext :
21+ def _make_context (* , author_id : int = 1 , channel_id : int = 10 , event : Event = Event . MESSAGE ) -> FilterContext :
2222 return FilterContext (
23- event = Event . MESSAGE ,
23+ event = event ,
2424 author = MockMember (id = author_id ),
2525 channel = MockTextChannel (id = channel_id ),
2626 content = "hello" ,
@@ -42,6 +42,52 @@ def test_different_action_values_are_not_suppressed(self):
4242 self .assertTrue (self .cog ._should_run_actions (ctx , first_actions ))
4343 self .assertTrue (self .cog ._should_run_actions (ctx , second_actions ))
4444
45+ def test_same_action_payload_for_different_events_is_suppressed (self ):
46+ """MESSAGE followed by MESSAGE_EDIT for the same user/channel/action should not double-ban."""
47+ msg_ctx = FilterContext (
48+ event = Event .MESSAGE ,
49+ author = MockMember (id = 1 ),
50+ channel = MockTextChannel (id = 10 ),
51+ content = "hello" ,
52+ message = None ,
53+ )
54+ edit_ctx = FilterContext (
55+ event = Event .MESSAGE_EDIT ,
56+ author = MockMember (id = 1 ),
57+ channel = MockTextChannel (id = 10 ),
58+ content = "hello" ,
59+ message = None ,
60+ )
61+ actions = self ._make_actions (send_alert = True )
62+
63+ self .assertTrue (self .cog ._should_run_actions (msg_ctx , actions ))
64+ self .assertFalse (self .cog ._should_run_actions (edit_ctx , actions ))
65+
66+ def test_differing_additional_actions_are_still_suppressed (self ):
67+ """Second event with no additional_actions (antispam already queued) should still be deduped."""
68+
69+ async def fake_handler (ctx : FilterContext ) -> None :
70+ pass
71+
72+ first_ctx = self ._make_context ()
73+ first_ctx .additional_actions .append (fake_handler )
74+
75+ second_ctx = self ._make_context () # no additional_actions
76+
77+ actions = self ._make_actions (send_alert = True )
78+
79+ self .assertTrue (self .cog ._should_run_actions (first_ctx , actions ))
80+ self .assertFalse (self .cog ._should_run_actions (second_ctx , actions ))
81+
82+ def test_same_action_payload_across_channels_is_suppressed (self ):
83+ """Antispam is cross-channel; same user/action in a different channel should not double-ban."""
84+ first_ctx = self ._make_context (channel_id = 10 )
85+ second_ctx = self ._make_context (channel_id = 20 )
86+ actions = self ._make_actions (send_alert = True )
87+
88+ self .assertTrue (self .cog ._should_run_actions (first_ctx , actions ))
89+ self .assertFalse (self .cog ._should_run_actions (second_ctx , actions ))
90+
4591 def test_same_action_payload_for_different_authors_is_not_suppressed (self ):
4692 first_ctx = self ._make_context (author_id = 1 )
4793 second_ctx = self ._make_context (author_id = 2 )
0 commit comments