Statistics Plugin

A simplistic approach to statistics gathering which works by default and requires no further setup.

 1from discord.ext import commands
 2
 3from antispam import AntiSpamHandler
 4from antispam.ext import Stats
 5
 6bot = commands.Bot(command_prefix="!")
 7bot.handler = AntiSpamHandler(bot, no_punish=True)
 8bot.stats = Stats(bot.handler)
 9bot.handler.register_extension(bot.stats)
10
11# We don't want to collect stats on guild 12345
12# So lets ignore it on this plugin
13bot.stats.blacklisted_guilds.add(12345)
14
15
16@bot.event
17async def on_ready():
18    # On ready, print some details to standard out
19    print(f"-----\nLogged in as: {bot.user.name} : {bot.user.id}\n-----")
20
21
22if __name__ == "__main__":
23    bot.run("Bot Token")
class antispam.plugins.Stats(anti_spam_handler: antispam.anti_spam_handler.AntiSpamHandler)

A simplistic approach to aggregating statistics across the anti spam package.

Do note however, it assumes plugins do not error out. If a plugin errors out, this will be inaccurate.

This does play with internals a bit, however, it is distributed within the library I am okay modifying the base package to make this work even better.

__init__(anti_spam_handler: antispam.anti_spam_handler.AntiSpamHandler)
injectable_nonce = 'Issa me, Mario!'
async classmethod load_from_dict(anti_spam_handler: antispam.anti_spam_handler.AntiSpamHandler, data: Dict)
async propagate(message, data: antispam.dataclasses.core.CorePayload) dict

This method is called whenever the base antispam.propagate is called, adhering to self.is_pre_invoke

Parameters
  • message (Union[discord.Message, hikari.messages.Message]) – The message to run propagation on

  • data (Optional[CorePayload]) – Optional input given to after invoke plugins which is the return value from the main propagate()

Returns

A dictionary of useful data to the end user

Return type

dict

async save_to_dict() Dict

Saves the plugins state to a Dict

Returns

The current plugin state as a dictionary.

Return type

Dict