modbot.connection.irc_client.IrcSocketClientAsync

class modbot.connection.irc_client.IrcSocketClientAsync(run_config)[source]

Bases: Logging, Moderation, BaseSocketClientAsync

Class to handle IRC 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

add_permit(user, length)

Add user to permit queue for a given length of time

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

check_joins_and_parts(line)

Check user joins/parts to/from channel

connect()

Initiate IRC connection

connect_fail(e)

Response to connection failure

del_permit(user)

Delete user from permit queue

filter_words(texts)

Check if words which need to be filtered are contained in texts

get_delete(info)

Get delete string to use in moderation response

get_info_from_irc(line)

Populate info dictionary using info from line

get_info_from_pubsub(msg_dict)

Get info from PubSub message for logging

get_info_prob(msg)

Get probability of non-wholesome message

get_permit_time(msg)

Get length of time to permit user from message.

get_permit_user(msg)

Get user name from chat message for user to permit

get_timeout(user, length, msg)

Get timeout string to use in moderation response

get_value(key, dictionary)

Search nested dictionary for key

handle_message(line)

Receive non chat IRC messages

has_permit(user)

Check if user has a permit

heartbeat()

Heartbeat routine for keeping connection alive

initialize_logger(run_config)

Initialize private logger

initialize_model(run_config)

Load trained model used for probability calculations

is_exempt(info)

Determine whether the user is exempt from moderation action

is_prob_exceeded(info)

Check is non-wholesome probability is exceeded for message in info

listen_forever()

Listen for socket connection

print_info(info)

Print info attributes to console

quit()

Close stream handler connection

receive_fail(e)

Response to message receive failure

receive_message()

Receive and handle IRC message

remove_allowed_phrases(line)

Remove exempt phrases from line so probability of non-wholesome message is caculated without exempt phrases

rep_nuke(info)

Handle response to !nuke command.

rep_permit(info)

Handle response to !permit command.

send_action(stream_writer, info)

Send action to IRC stream

send_message(stream_writer[, message, info])

Send message to IRC stream

send_nuke(stream_writer)

Send nuke to stream

send_ping()

Send ping to keep connection alive

send_reply(stream_writer, info)

Make decision based on info and send moderation response

should_nuke(msg)

Check if a nuke is ongoing and if there is a message in chat that needs to be nuked

time_nuke()

End nuke if the nuke time has elapsed

time_permit(user)

Keep track of time a user is permitted and remove them if max time has elapsed

Attributes

USER_LOG

Log handling class

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

add_permit(user, length)

Add user to permit queue for a given length of time

Parameters
  • user (str) – Username

  • length (int) – Length of time in seconds

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

check_joins_and_parts(line)[source]

Check user joins/parts to/from channel

async connect()[source]

Initiate IRC connection

connect_fail(e)

Response to connection failure

del_permit(user)

Delete user from permit queue

Parameters

user (str) – Username

filter_words(texts)

Check if words which need to be filtered are contained in texts

Parameters

texts (list) – List of texts to check for filter words

Return type

bool

static get_delete(info)

Get delete string to use in moderation response

Parameters

info (dict) – dictionary storing attributes of user. e.g. recent message, badges, username, probability of non-wholesome message

Returns

String containing delete command

Return type

str

get_info_from_irc(line)

Populate info dictionary using info from line

Parameters

line (str) – String containing most recent IRC message.

Returns

info – dictionary storing attributes of user. e.g. recent message, badges, username, probability of non-wholesome message

Return type

dict

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_info_prob(msg)

Get probability of non-wholesome message

Parameters

msg (str) – Message to evaluate

Return type

float

get_permit_time(msg)

Get length of time to permit user from message. If message does not include a time then use default time.

Parameters

msg (str) – Message to get permit time from

Returns

Permit time in seconds

Return type

int

static get_permit_user(msg)

Get user name from chat message for user to permit

Parameters

msg (str) – Message to get username from

Returns

Username

Return type

str

static get_timeout(user, length, msg)

Get timeout string to use in moderation response

Parameters
  • user (str) – Username

  • length (int) – Length of timeout in seconds

  • msg (str) – Message to include with timeout

Returns

String containing timeout command

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

handle_message(line)[source]

Receive non chat IRC messages

has_permit(user)

Check if user has a permit

Parameters

user (str) – Username

Return type

bool

async heartbeat()

Heartbeat routine for keeping 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

static initialize_model(run_config)

Load trained model used for probability calculations

Parameters

run_config (RunConfig) – Class storing run time configuration parameters

Returns

model

Return type

LSTM | SVM | CNN

is_exempt(info)

Determine whether the user is exempt from moderation action

Parameters

info (dict) – dictionary storing attributes of user. e.g. recent message, badges, username, probability of non-wholesome message

Return type

bool

is_prob_exceeded(info)

Check is non-wholesome probability is exceeded for message in info

Parameters

info (dict) – dictionary storing attributes of user. e.g. recent message, badges, username, probability of non-wholesome message

Return type

bool

async listen_forever()

Listen for socket connection

static print_info(info)

Print info attributes to console

Parameters

info (dict) – dictionary storing attributes of user. e.g. recent message, badges, username, probability of non-wholesome message

quit()[source]

Close stream handler connection

receive_fail(e)

Response to message receive failure

async receive_message()[source]

Receive and handle IRC message

remove_allowed_phrases(line)

Remove exempt phrases from line so probability of non-wholesome message is caculated without exempt phrases

Parameters

line (str) – String containing most recent IRC message.

rep_nuke(info)

Handle response to !nuke command. Check if we should send nuke.

Parameters

info (dict) – dictionary storing attributes of user. e.g. recent message, badges, username, probability of non-wholesome message

Return type

bool

rep_permit(info)

Handle response to !permit command. Check if we should permit the user in info

Parameters

info (dict) – dictionary storing attributes of user. e.g. recent message, badges, username, probability of non-wholesome message

Return type

bool

send_action(stream_writer, info)

Send action to IRC stream

Parameters
  • stream_writer (StreamWriter) – StreamWriter for IRC stream

  • info (dict) – dictionary storing attributes of user. e.g. recent message, badges, username, probability of non-wholesome message

send_message(stream_writer, message=None, info=None)

Send message to IRC stream

Parameters
  • stream_writer (StreamWriter) – StreamWriter for IRC stream

  • message (str, optional) – Message string, by default None

  • info (dict, optional) – Info dictionary, by default None

send_nuke(stream_writer)

Send nuke to stream

Parameters

stream_writer (StreamWriter) – StreamWriter for IRC stream

send_ping()[source]

Send ping to keep connection alive

send_reply(stream_writer, info)

Make decision based on info and send moderation response

Parameters
  • stream_writer (StreamWriter) – StreamWriter for IRC stream

  • info (dict) – dictionary storing attributes of user. e.g. recent message, badges, username, probability of non-wholesome message

should_nuke(msg)

Check if a nuke is ongoing and if there is a message in chat that needs to be nuked

Parameters

msg (str) – Message to check for whether it should be nuked

Return type

bool

time_nuke()

End nuke if the nuke time has elapsed

time_permit(user)

Keep track of time a user is permitted and remove them if max time has elapsed

Parameters

user (str) – Username to check for whether they have a permit