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 cleanInitialize this class and simply use the bool
is_spamming()
and do punishments based off thatInitialize 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 setspam_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 counteris_spamming
-> Checks if the User’s internal counter meetsspam_amount_to_punish
and returns a bool- member_tracking
The underlying cache mechanism for data storage
- Type
- __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 member 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
TypeError – Invalid Arg Type
ValueError – Invalid Arg Type
- anti_spam_handler
- async do_punishment(message, *args, **kwargs) None
This only exists for if the member wishes to subclass this class and implement there own logic for punishments here.
- Parameters
message – The message to extract the guild and member from
Notes
This does nothing unless you subclass and implement it yourself.
- async get_member_count(message) int
Returns how many messages that are still ‘valid’ (counted as spam) a certain member has
- Parameters
message – The message from which to extract member
- Returns
How many times this member has sent a message that has been marked as ‘punishment worthy’ by AntiSpamHandler within the valid interval time period
- Return type
- Raises
MemberNotFound – The User for the
message
could not be found
- async is_spamming(message) bool
Given a message, deduce and return if a member is classed as ‘spamming’ or not based on
punish_min_amount
- Parameters
message – The message to extract guild and member from
- Returns
True if the User is spamming else False
- Return type
- member_tracking
- async 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
- async remove_outdated_timestamps(data: List, 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 member
- async remove_punishments(message)
After you punish someone, call this method to ‘clean up’ there punishments.
- Parameters
message – The message to extract member from
- Raises
TypeError – Invalid arg
Notes
This will actually create a member internally if one doesn’t already exist for simplicities sake
- async 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