MemoryCache Reference

This is the default cache for the package. You shouldn’t need to implement it yourself.

Furthermore, refer to antispam.abc.Cache for protocol implementation.

class antispam.caches.MemoryCache(handler)
__init__(handler)
async add_message(message: antispam.dataclasses.message.Message) None

Adds a Message to the relevant Member, creating the Guild/Member if they don’t exist

Parameters

message (Message) – The Message to add to the internal cache

Notes

This should silently create any Guild’s/Member’s required to fulfil this transaction

async delete_guild(guild_id: int) None

Removes a guild from the cache. This should also remove all members.

Parameters

guild_id (int) – The id of the guild we wish to remove

Notes

This fails silently.

async delete_member(member_id: int, guild_id: int) None

Removes a member from the cache.

Parameters
  • member_id (int) – The id of the member we wish to remove

  • guild_id (int) – The guild this member is in

Notes

This fails silently.

async drop() None

Drops the entire cache, deleting everything contained within.

get_all_guilds() AsyncIterable[antispam.dataclasses.guild.Guild]

Returns a generator containing all cached guilds

Yields

Guild – A generator of all stored guilds

get_all_members(guild_id: int) AsyncIterable[antispam.dataclasses.member.Member]

Fetches all members within a guild and returns them within a generator

Parameters

guild_id (int) – The guild we want members in

Yields

Member – All members in the given guild

Raises

GuildNotFound – The given guild was not found

async get_guild(guild_id: int) antispam.dataclasses.guild.Guild

Fetch a Guild dataclass populated with members

Parameters

guild_id (int) – The id of the Guild to retrieve from cache

Raises

GuildNotFound – A Guild could not be found in the cache with the given id

async get_member(member_id: int, guild_id: int) antispam.dataclasses.member.Member

Fetch a Member dataclass populated with messages

Parameters
  • member_id (int) – The id of the member to fetch from cache

  • guild_id (int) – The id of the guild this member is associated with

Raises
  • MemberNotFound – This Member could not be found on the associated Guild within the internal cache

  • GuildNotFound – The relevant guild could not be found

async initialize(*args, **kwargs) None

This method gets called once when the AntiSpamHandler init() method gets called to allow for setting up connections, etc

Notes

This is not required.

async reset_member_count(member_id: int, guild_id: int, reset_type: antispam.enums.reset_type.ResetType) None

Reset the chosen enum type back to the default value

Parameters
  • member_id (int) – The Member to reset

  • guild_id (int) – The guild this member is in

  • reset_type (ResetType) – An enum denoting the type of reset

Notes

This shouldn’t raise an error if the member doesn’t exist.

async set_guild(guild: antispam.dataclasses.guild.Guild) None

Stores a Guild in the cache

This is essentially a UPSERT operation

Parameters

guild (Guild) – The Guild that needs to be stored

Warning

This method should be idempotent.

The passed guild object should not experience a change to the callee.

async set_member(member: antispam.dataclasses.member.Member) None

Stores a Member internally and attaches them to a Guild, creating the Guild silently if required

Essentially an UPSERT operation

Parameters

member (Member) – The Member we want to cache

Warning

This method should be idempotent.

The passed member object should not experience a change to the callee.