AntiSpamTracker Plugin

A cool plugin designed to assist you with custom punishments.

class antispam.plugins.AntiSpamTracker(anti_spam_handler: antispam.anti_spam_handler.AntiSpamHandler, spam_amount_to_punish, valid_timestamp_interval=None)

A class devoted to people who want to handle punishments themselves.

This class wraps a few things, and handles the logic of ensuring everything exists (or doesnt) among other things such as untracking users after the valid storage interval expires

In order to use this in your code, you can either:

  • Subclass this class and override the do_punishment method and then use it that way to keep it clean
  • Initialize this class and simply use the bool is_spamming() and do punishments based off that
  • Initialize this class and simply use get_user_count() to get the number of times the user should be punished and do your own logic

This mainly just depends on how granular you want to be within your code base.

The way it works, is everytime you call propagate you simply pass the returned data into update_cache and it will update said Members cache if AntiSpamHandler thinks that they should be punished. Now, you set spam_amount_to_punish when creating an instance of this class and that is used to check if YOU think they should be punished, and what punishment to give when they hit that cap.

Basically:

propagate -> update_cache, if the User should be punished we increment internal counter

is_spamming -> Checks if the User’s internal counter meets spam_amount_to_punish and returns a bool

__init__(anti_spam_handler: antispam.anti_spam_handler.AntiSpamHandler, spam_amount_to_punish, valid_timestamp_interval=None) → None

Initialize this class and get it ready for usage.

Parameters:
  • anti_spam_handler (AntiSpamHandler) – Your AntiSpamHandler instance
  • spam_amount_to_punish (int) – A number denoting the minimum value required per user in order trip is_spamming
  • valid_timestamp_interval (int) –

    How long a timestamp should remain ‘valid’ for. Defaults to AntiSpamHandler.options.get("message_interval")

    NOTE this is in milliseconds

Raises:
anti_spam_handler
do_punishment(message, *args, **kwargs) → None

This only exists for if the user wishes to subclass this class and implement there own logic for punishments here.

Parameters:message – The message to extract the guild and user from

Notes

This does nothing unless you subclass and implement it yourself.

get_user_count(message) → int

Returns how many messages that are still ‘valid’ (counted as spam) a certain user has

Parameters:message – The message from which to extract user
Returns:How many times this user has sent a message that has been marked as ‘punishment worthy’ by AntiSpamHandler within the valid interval time period
Return type:int
Raises:MemberNotFound – The User for the message could not be found
is_spamming(message) → bool

Given a message, deduce and return if a user is classed as ‘spamming’ or not based on punish_min_amount

Parameters:message – The message to extract guild and user from
Returns:True if the User is spamming else False
Return type:bool
member_tracking
propagate(message, data: Optional[antispam.dataclasses.core.CorePayload] = None) → dict

Overwrite the base extension to call update_cache internally so it can be used as an extension

punish_min_amount
remove_outdated_timestamps(data: List[T], member_id: int, guild_id: int) → None

This logic works around checking the current time vs a messages creation time. If the message is older by the config amount it can be cleaned up

Generally not called by the end user

Parameters:
  • data (List) – The data to work with
  • member_id (int) – The id of the member to store on
  • guild_id (int) – The id of the guild to store on
remove_punishments(message)

After you punish someone, call this method to ‘clean up’ there punishments.

Parameters:message – The message to extract user from
Raises:TypeError – Invalid arg

Notes

This will actually create a member internally if one doesn’t already exist for simplicities sake

update_cache(message, data: antispam.dataclasses.core.CorePayload) → None

Takes the data returned from propagate and updates this Class’s internal cache

Parameters:
  • message – The message related to data’s propagation
  • data (CorePayload) – The data returned from propagate
valid_global_interval