예제 #1
0
    async def test_set_member_keyerror(self):
        """A test to test set_member_data throws a keyerror"""
        plugin_cache = PluginCache(AntiSpamHandler(commands.Bot("!")), MockClass())
        await plugin_cache.set_guild_data(1, "A test")
        with pytest.raises(MemberNotFound):
            await plugin_cache.get_member_data(1, 1)

        await plugin_cache.set_member_data(1, 1, "A member test")
예제 #2
0
    async def test_set_guild_data_dictionaries(self, arg):
        """Test the cache sets guild addon's correct using lists of datetimes"""
        plugin_cache = PluginCache(AntiSpamHandler(commands.Bot("!")), MockClass())

        with pytest.raises(GuildNotFound):
            await plugin_cache.get_guild_data(1)

        await plugin_cache.set_guild_data(1, arg)

        assert await plugin_cache.get_guild_data(1) == arg
예제 #3
0
    async def test_set_member_data_text(self, arg):
        """Test the cache sets member addon's correct using text"""
        plugin_cache = PluginCache(AntiSpamHandler(commands.Bot("!")), MockClass())

        with pytest.raises(GuildNotFound):
            await plugin_cache.get_member_data(1, 1)

        await plugin_cache.set_member_data(1, 1, arg)

        assert await plugin_cache.get_member_data(1, 1) == arg
예제 #4
0
    async def test_set_member_data_dictionaries(self):
        """Test the cache sets member addon's correct"""
        plugin_cache = PluginCache(AntiSpamHandler(commands.Bot("!")), MockClass())
        arg = {"test": "tester"}

        with pytest.raises(GuildNotFound):
            await plugin_cache.get_member_data(1, 1)

        await plugin_cache.set_member_data(1, 1, arg)

        assert await plugin_cache.get_member_data(1, 1) == arg
예제 #5
0
    async def test_set_guild_data_text(self):
        """Test the cache sets guild addon's correct using text"""
        plugin_cache = PluginCache(AntiSpamHandler(commands.Bot("!")), MockClass())

        arg = "Hello world"

        with pytest.raises(GuildNotFound):
            await plugin_cache.get_guild_data(1)

        await plugin_cache.set_guild_data(1, arg)

        assert await plugin_cache.get_guild_data(1) == arg
예제 #6
0
    def __init__(
        self,
        bot,
        handler: AntiSpamHandler,
        *,
        total_mentions_before_punishment: int = 10,
        time_period: int = 15000,
        min_mentions_per_message: int = 5,
    ):
        """

        Parameters
        ----------
        bot
            Our bot instance
        handler : AntiSpamHandler
            Our AntiSpamHandler instance
        total_mentions_before_punishment : int
            How many mentions within the time period
            before we punish the user
            *Inclusive*
        time_period : int
            The time period valid for mentions
            *Is in milliseconds*
        min_mentions_per_message : int
            The minimum amount of mentions in a message
            before a punishment is issued
            *Inclusive*
        """
        super().__init__()
        if min_mentions_per_message > total_mentions_before_punishment:
            raise ValueError(
                "Expected `min_mentions_per_message` to be less then or equal to `total_mentions_before_punishment`"
            )

        if time_period < 1:
            raise ValueError("Expected `time_period` to be positive")

        self.bot = bot
        self.handler = handler
        self.data = PluginCache(handler, caller=self)

        self.min_mentions_per_message = min_mentions_per_message
        self.total_mentions_before_punishment = total_mentions_before_punishment
        self.time_period = time_period

        log.info("Plugin ready for usage")
예제 #7
0
def create_plugin_cache(create_handler):
    """Creates a PluginCache instance"""
    return PluginCache(create_handler, MockClass())