modbot.moderation.Moderation

class modbot.moderation.Moderation(run_config)[source]

Bases: Permitting, Nuking

Class to handle moderation actions and decisions

Methods

add_permit(user, length)

Add user to permit queue for a given length of time

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_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

has_permit(user)

Check if user has a permit

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

print_info(info)

Print info attributes to console

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_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

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

del_permit(user)

Delete user from permit queue

Parameters

user (str) – Username

filter_words(texts)[source]

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)[source]

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)[source]

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_prob(msg)[source]

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)[source]

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

has_permit(user)

Check if user has a permit

Parameters

user (str) – Username

Return type

bool

static initialize_model(run_config)[source]

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)[source]

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)[source]

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

static print_info(info)[source]

Print info attributes to console

Parameters

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

remove_allowed_phrases(line)[source]

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)[source]

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)[source]

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)[source]

Send nuke to stream

Parameters

stream_writer (StreamWriter) – StreamWriter for IRC stream

send_reply(stream_writer, info)[source]

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