def test_init(self, create_handler): create_handler.options.no_punish = True # Code coverage AntiSpamTracker(create_handler, 1) create_handler.options.no_punish = False AntiSpamTracker(create_handler, 1, valid_timestamp_interval=1) AntiSpamTracker(create_handler, 1, valid_timestamp_interval=1.0) tracker = AntiSpamTracker(create_handler, 5, 15) assert tracker.valid_global_interval == 15 assert tracker.punish_min_amount == 5 assert isinstance(tracker.member_tracking, PluginCache)
def test_init_raises(self, create_handler): with pytest.raises(ValueError): AntiSpamTracker(create_handler, None) with pytest.raises(TypeError): AntiSpamTracker(None, 1) with pytest.raises(TypeError): AntiSpamTracker(MockClass, 1) with pytest.raises(ValueError): AntiSpamTracker(create_handler, 1, valid_timestamp_interval="lol") with pytest.raises(TypeError): AntiSpamTracker(create_handler, 1, valid_timestamp_interval=MockClass)
def create_anti_spam_tracker(create_handler): return AntiSpamTracker(create_handler, 3)
from antispam.enums import Library from jsonLoader import read_json from antispam import AntiSpamHandler, Options from antispam.plugins import AntiSpamTracker bot = commands.Bot(command_prefix="!", intents=discord.Intents.all()) file = read_json("token") bot.handler = AntiSpamHandler( bot, library=Library.YOUR_LIBRARY_HERE, options=Options(no_punish=True, message_duplicate_count=3), ) bot.tracker = AntiSpamTracker(bot.handler, 5) bot.handler.register_plugin(bot.tracker) """ For every message after (and including your third duplicate message) it adds one to your tracked count When its hits 5 'spammed' messages, it triggers. Which is 7 messages overall. """ @bot.event async def on_ready(): # On ready, print some details to standard out print(f"-----\nLogged in as: {bot.user.name} : {bot.user.id}\n-----") @bot.event async def on_message(message):