hook.alerts#

class immp.hook.alerts.MentionsHook(name, config, host, virtual=False)#

Bases: AlertHookBase

Hook to send mention alerts via private channels.

match(mention, members)#

Identify users relevant to a mention.

Parameters:
  • mention (str) – Raw mention text, e.g. @fred.

  • members (.User list) – List of members in the channel where the mention took place.

Returns:

All applicable members to be notified.

Return type:

.User set

async before_receive(sent, source, primary)#

Modify an incoming message before it’s pushed to other hooks. The sent object must be returned, so hooks may modify in-place or return a different object. This method is called for each hook, one after another, so any time-consuming tasks should be deferred to process() (which is run for all hooks in parallel).

Hooks may also suppress a message (e.g. if their actions caused it, but it bears no value to the rest of the system) by returning None.

Parameters:
  • sent (.SentMessage) – Raw message received from another plug.

  • source (.Message) – Original message data used to generate the raw message, if sent via the plug (e.g. from another hook), equivalent to msg if the source is otherwise unknown.

  • primary (bool) – False for supplementary messages if the source message required multiple raw messages in order to represent it (e.g. messages with multiple attachments where the underlying network doesn’t support it), otherwise True.

Returns:

The augmented or replacement message, or None to suppress this message.

Return type:

.SentMessage

async on_receive(sent, source, primary)#

Handle an incoming message received by any plug.

Parameters:
  • sent (.SentMessage) – Raw message received from another plug.

  • source (.Message) – Original message data used to generate the raw message, if sent via the plug (e.g. from another hook), equivalent to msg if the source is otherwise unknown.

  • primary (bool) – False for supplementary messages if the source message required multiple raw messages in order to represent it (e.g. messages with multiple attachments where the underlying network doesn’t support it), otherwise True.

class immp.hook.alerts.SubscriptionsHook(name, config, host)#

Bases: AlertHookBase

Hook to send trigger word alerts via private channels.

on_load()#

Perform any additional one-time setup that requires other plugs or hooks to be loaded.

async static match(text, channel, present)#

Identify users subscribed to text snippets in a message.

Parameters:
  • text (str) – Cleaned message text.

  • channel (.Channel) – Channel where the subscriptions were triggered.

  • present (((str, str), .User) dict) – Mapping from network/user IDs to members of the source channel.

Returns:

Mapping from applicable users to their filtered triggers.

Return type:

(.User, str set) dict

async channel_migrate(old, new)#

Move any private data between channels on admin request. This is intended to cover data keyed by channel sources and plug network identifiers.

Parameters:
  • old (.Channel) – Existing channel with local data.

  • new (.Channel) – Target replacement channel to migrate data to.

Returns:

True if any data was migrated for the requested channel.

Return type:

bool

async on_receive(sent, source, primary)#

Handle an incoming message received by any plug.

Parameters:
  • sent (.SentMessage) – Raw message received from another plug.

  • source (.Message) – Original message data used to generate the raw message, if sent via the plug (e.g. from another hook), equivalent to msg if the source is otherwise unknown.

  • primary (bool) – False for supplementary messages if the source message required multiple raw messages in order to represent it (e.g. messages with multiple attachments where the underlying network doesn’t support it), otherwise True.