Personalities

Personalities describe behavior for a subset of signal_bot_framework.aliases.Context.

class signal_bot_framework.personality.Personality(contexts=())

Bases: PersonalityProto, ABC

Specific behavior for a subset of signal_bot_framework.aliases.Context.

matches_context(context)

Whether or not a given Context is valid for this Personality.

Parameters:

context (Context) – The Context in question.

Return type:

bool

abstract handle_callback_exception(exception, cb)

Handle an exception that occured in a callback.

Parameters:
  • exception (BaseException) – The exception that occurred.

  • cb (AnyCb) – The callback the exception occurred in.

Return type:

bool

Returns:

If the callback is a Cron hook, the return value determines whether the Cron will be rescheduled.

start_crons(signal)

Start any registered Cron callbacks.

Called by SignalBot.

Parameters:

signal (SignalBot) – The current SignalBot instance.

stop_crons()

Stop any sleeping Cron callbacks.

Return type:

None

async personality_handle_message(signal, context, message)

Handle a single Signal message that has been approved for this Personality.

Determines if the message is handled by any of the existing hooks, and if so stops processing.

Parameters:
  • signal (SignalBot) – The current SignalBot instance.

  • context (Context) – The context the message was received in.

  • message (DataMessage) – The message that was received.

Return type:

bool

Returns:

True if the message was handled by a hook - otherwise the message will be sent to the next Personality in line.

on_message(cb)

Register a callback to be called on any DataMessage.

Parameters:

cb (MessageCb) – The function to call.

remove_message_callback(callback)
on_prefix(prefix, cb)

Register a callback to be called on any DataMessage matching a given prefix (exact match).

Parameters:
  • prefix (str) – The exact-match prefix to trigger on.

  • cb (MessageCb) – The function to call.

remove_prefix(prefix)
on_keyword(keyword, cb, case_sensitive=False, whole_word=True)

Register a callback to be called when DataMessage contains a keyword.

Parameters:
  • keyword (str) – The keyword to trigger on.

  • cb (MessageCb) – The function to call.

  • case_sensitive (bool) – Whether the match is case-sensitive.

  • whole_word (bool) – Whether to match whole words only.

remove_keyword(key)
on_mention(mention, cb)

Register a callback to be called when a given AccountNumber/AccountUUID is @-mentioned.

Parameters:
remove_mention(mention)
on_cron(schedule, cb)

Register a callback to be called on a Cron schedule.

Parameters:
  • schedule (str) – The Cron schedule to trigger on.

  • cb (MessageCb) – The function to call.

Return type:

CronItem

remove_cron(item)