modbot.connection.pubsub_client.WebSocketClientAsync

class modbot.connection.pubsub_client.WebSocketClientAsync(run_config)[source]

Bases: Logging, BaseSocketClientAsync

Class to handle PubSub connection

Methods

EXTRA_VERBOSE_LOGGER(message, *args, **kws)

Chat log level

INFO_LOGGER(message, *args, **kws)

Chat log level

VERBOSE_LOGGER(message, *args, **kws)

Chat log level

append_log(line)

Add entry to log

build_action_log_entry(action, user, ...)

Build action log entry from message content

build_chat_log_entry(info)

Build standard chat message log entry

connect()

Report initial connection

connect_fail(e)

Response to connection failure

generate_nonce()

Generate nonce value.

get_info_from_pubsub(msg_dict)

Get info from PubSub message for logging

get_user_id(user)

Get moderator user id

get_value(key, dictionary)

Search nested dictionary for key

handle_message(message)

Handle moderation decisions based on PubSub message

heartbeat()

Keep PubSub connection alive

initialize_logger(run_config)

Initialize private logger

listen_forever()

Listen for socket connection

quit()

Close pubsub connection

receive_fail(e)

Response to message receive failure

receive_message()

Recieve PubSub message

send_ping()

Send ping to keep connection alive

Attributes

USER_LOG

Log handling class

channel_id

ID for channel to moderate

moderator_id

ID for bot username

EXTRA_VERBOSE_LOGGER(message, *args, **kws)

Chat log level

INFO_LOGGER(message, *args, **kws)

Chat log level

USER_LOG = {}

Log handling class

VERBOSE_LOGGER(message, *args, **kws)

Chat log level

append_log(line)

Add entry to log

Parameters

line (str) – Line to write to log after some sanitizing

static build_action_log_entry(action, user, moderator, msg, secs, msg_id)

Build action log entry from message content

Parameters
  • action (str) – Moderation action. e.g ban, timeout, delete

  • user (str) – Username

  • moderator (str) – Moderator username who performed action

  • msg (str) – The message which preceeded the mod action

  • secs (str) – Timeout length in seconds

  • msg_id (str) – Message id

Returns

Log entry containing moderation action info

Return type

str

static build_chat_log_entry(info)

Build standard chat message log entry

Parameters

info (dict) – Dictionary of info from IRC message

Returns

Chat log entry to write to log

Return type

str

property channel_id

ID for channel to moderate

async connect()[source]

Report initial connection

connect_fail(e)

Response to connection failure

static generate_nonce()[source]

Generate nonce value. Needed for PubSub connection.

get_info_from_pubsub(msg_dict)

Get info from PubSub message for logging

Parameters

msg_dict (dict) – Dictionary containing PubSub message info

Returns

  • action (str) – Moderation action. e.g ban, timeout, delete

  • user (str) – Username

  • moderator (str) – Moderator username who performed action

  • msg (str) – The message which preceeded the mod action

  • secs (str) – Timeout length in seconds

  • msg_id (str) – Message id

get_user_id(user)[source]

Get moderator user id

Parameters

user (str) – User for which to get id

Returns

User id

Return type

str

static get_value(key, dictionary)

Search nested dictionary for key

Parameters
  • key (str) – Key to search dictionary for

  • dictionary (dict) – Dictionary to search key for

Returns

Value in dictionary corresponding to key, or empty string if not found

Return type

str

async handle_message(message)[source]

Handle moderation decisions based on PubSub message

Parameters

message (str) – String containing PubSub message

async heartbeat()[source]

Keep PubSub connection alive

initialize_logger(run_config)

Initialize private logger

Parameters

run_config (RunConfig) – RunConfig class storing run time configuration parameters

Returns

Private logger used to write chat messages and mod actions

Return type

logger

async listen_forever()

Listen for socket connection

property moderator_id

ID for bot username

async quit()[source]

Close pubsub connection

receive_fail(e)

Response to message receive failure

async receive_message()[source]

Recieve PubSub message

async send_ping()[source]

Send ping to keep connection alive