cslbot.helpers package

Submodules

cslbot.helpers.admin module

cslbot.helpers.admin.set_admin(msg, handler)[source]

Handle admin verification responses from NickServ.

If NickServ tells us that the nick is authed, mark it as verified.

cslbot.helpers.arguments module

class cslbot.helpers.arguments.ArgParser(config=None, **kwargs)[source]

Bases: argparse.ArgumentParser

error(message)[source]
exit(status=0, message=None)[source]
parse_args(msg)[source]
parse_known_args(msg, namespace=None)[source]
exception cslbot.helpers.arguments.ArgumentException[source]

Bases: Exception

class cslbot.helpers.arguments.ChanParser(option_strings, dest, nargs=None, const=None, default=None, type=None, choices=None, required=False, help=None, metavar=None)[source]

Bases: argparse.Action

class cslbot.helpers.arguments.DateParser(option_strings, dest, nargs=None, const=None, default=None, type=None, choices=None, required=False, help=None, metavar=None)[source]

Bases: argparse.Action

class cslbot.helpers.arguments.NickParser(option_strings, dest, nargs=None, const=None, default=None, type=None, choices=None, required=False, help=None, metavar=None)[source]

Bases: argparse.Action

class cslbot.helpers.arguments.TumblrParser(option_strings, dest, nargs=None, const=None, default=None, type=None, choices=None, required=False, help=None, metavar=None)[source]

Bases: argparse.Action

cslbot.helpers.babble module

cslbot.helpers.babble.build_markov(cursor, cmdchar, ctrlchan, speaker=None, initial_run=False, debug=False)[source]

Builds a markov dictionary.

cslbot.helpers.babble.build_rows(cursor, length, markov, initial_run)[source]
cslbot.helpers.babble.clean_msg(msg)[source]
cslbot.helpers.babble.delete_tables(cursor)[source]
cslbot.helpers.babble.generate_markov(cursor, length, messages, initial_run)[source]
cslbot.helpers.babble.get_markov(cursor, length, node, initial_run)[source]
cslbot.helpers.babble.get_messages(cursor, cmdchar, ctrlchan, speaker, newer_than_id)[source]
cslbot.helpers.babble.postgres_hack(cursor, length, data)[source]
cslbot.helpers.babble.update_count(cursor, rows, length, source, target)[source]
cslbot.helpers.babble.update_markov(cursor, config)[source]

cslbot.helpers.backtrace module

cslbot.helpers.backtrace.handle_traceback(ex, c, target, config, source='the bot')[source]
cslbot.helpers.backtrace.output_traceback(ex)[source]

Returns a tuple of a prettyprinted error message and string representation of the error

cslbot.helpers.command module

class cslbot.helpers.command.Command(names, args=[], limit=0, admin=False)[source]

Bases: object

get_doc()[source]
is_limited()[source]
requires_admin()[source]
run(send, msg, args, command, nick, target, handler)[source]
class cslbot.helpers.command.CommandData[source]

Bases: object

disable_command(command)[source]

Adds a command to the disabled commands list.

enable_command(command)[source]

Removes a command from the disabled commands list.

get_command(command_name)[source]
get_disabled_commands()[source]
get_enabled_commands()[source]
get_known_commands()[source]
is_disabled(command)[source]
is_registered(command_name)[source]
register(name, command)[source]
scan_for_commands()[source]

Scans for commands

Return type:list
Returns:A list of modules that failed to reload
cslbot.helpers.command.check_command(cursor, nick, msg, target)[source]
cslbot.helpers.command.record_command(cursor, nick, command, channel)[source]

cslbot.helpers.config module

cslbot.helpers.config.check_admins(admins, nickregex)[source]
cslbot.helpers.config.do_config(config)[source]
cslbot.helpers.config.do_setup(configfile)[source]
cslbot.helpers.config.load_config(config_file, send)[source]
cslbot.helpers.config.migrate_config(config_file, config_obj, send)[source]

cslbot.helpers.control module

cslbot.helpers.control.get_accept_msg(handler, pending, type)[source]
cslbot.helpers.control.get_reject_msg(pending, type)[source]
cslbot.helpers.control.handle_accept(args)[source]
cslbot.helpers.control.handle_chanserv(args)[source]
cslbot.helpers.control.handle_ctrlchan(handler, msg, send)[source]

Handle the control channel.

cslbot.helpers.control.handle_disable(args)[source]
cslbot.helpers.control.handle_enable(args)[source]
cslbot.helpers.control.handle_guard(args)[source]
cslbot.helpers.control.handle_help(args)[source]
cslbot.helpers.control.handle_quote(args)[source]
cslbot.helpers.control.handle_reject(args)[source]
cslbot.helpers.control.handle_show(args)[source]
cslbot.helpers.control.handle_show_pending(args)[source]
cslbot.helpers.control.handle_unguard(args)[source]
cslbot.helpers.control.init_parser(send, handler, db)[source]
cslbot.helpers.control.show_pending(db, admins, send, ping=False)[source]
cslbot.helpers.control.show_pending_items(type, items, send)[source]
cslbot.helpers.control.toggle_logging(level)[source]
cslbot.helpers.control.toggle_module(type, name, enable=True)[source]

cslbot.helpers.core module

class cslbot.helpers.core.IrcBot(confdir)[source]

Bases: irc.bot.SingleServerIRCBot

do_cap(_)[source]
static get_target(e)[source]
get_version()[source]

Get the version.

handle_event(c, e)[source]
handle_msg(c, e)[source]

Handles all messages.

If a exception is thrown, catch it and display a nice traceback instead of crashing.
Do the appropriate processing for each event type.
handle_quit(_, e)[source]
is_reload(e)[source]
reload_handler(c, e)[source]

This handles reloads.

shutdown(*_)[source]
shutdown_mp(clean=True)[source]

Shutdown all the multiprocessing.

Parameters:clean (bool) – Whether to shutdown things cleanly, or force a quick and dirty shutdown.
cslbot.helpers.core.init(confdir='/etc/cslbot')[source]

The bot’s main entry point.

Initialize the bot and start processing messages.

cslbot.helpers.exception module

exception cslbot.helpers.exception.CommandFailedException[source]

Bases: Exception

cslbot.helpers.geoip module

cslbot.helpers.geoip.get_zipcode(db, ip)[source]

cslbot.helpers.handler module

class cslbot.helpers.handler.BotHandler(config, connection, channels, confdir)[source]

Bases: object

abusecheck(send, nick, target, limit, cmd)[source]

Rate-limits commands.

If a nick uses commands with the limit attr set, record the time
at which they were used.
If the command is used more than limit times in a
minute, ignore the nick.
check_mode(mode)[source]
do_args(modargs, send, nick, target, source, name, msgtype)[source]

Handle the various args that modules need.

do_join(cmdargs, nick, msgtype, send, c)[source]

Join a channel.

Checks if bot is already joined to channel.
do_kick(send, target, nick, msg, slogan=True)[source]

Kick users.

If kick is disabled, don’t do anything.
If the bot is not a op, rage at a op.
Kick the user.
do_log(target, nick, msg, msgtype)[source]

Handles logging.

Logs to a sql db.
do_mode(target, msg, nick, send)[source]

reop and handle guard violations

do_part(cmdargs, nick, target, msgtype, send, c)[source]

Leaves a channel.

Prevent user from leaving the primary channel.

do_rejoin(c, e)[source]
do_welcome()[source]

Do setup when connected to server.

Join the primary channel.
Join the control channel.
get_admins()[source]

Check verification for all admins.

get_cmd(msg)[source]
get_data()[source]

Saves the handler’s data for bot.IrcBot.do_reload()

get_filtered_send(cmdargs, send, target)[source]

Parse out any filters.

static get_max_length(target, msgtype)[source]
handle_account(e)[source]
handle_authenticate(e)[source]
handle_cap(e)[source]
handle_event(msg, send, c, e)[source]
handle_hooks(send, nick, target, e, msg)[source]
handle_join(c, e, target, send)[source]
handle_kick(c, e, target, send)[source]
handle_msg(c, e)[source]

The Heart and Soul of IrcBot.

handle_nick(send, e)[source]
handle_welcome()[source]
handle_who(e)[source]
is_admin(send, nick)[source]

Checks if a nick is a admin.

If the nick is not in self.admins then it’s not a admin.
If NickServ hasn’t responded yet, then the admin is unverified,
so assume they aren’t a admin.
is_ignored(nick)[source]
rate_limited_send(mtype, target, msg)[source]
run_cmd(send, nick, target, cmd_name, cmdargs, e)[source]
send(target, nick, msg, msgtype, ignore_length=False, filters=None)[source]

Send a message.

Records the message in the log.

set_data(data)[source]

Called from bot.IrcBot.do_reload() to restore the handler’s data.

update_authstatus(nick)[source]

cslbot.helpers.hook module

class cslbot.helpers.hook.Hook(name, types, args=[])[source]

Bases: object

run(send, msg, msgtype, handler, target, args)[source]
class cslbot.helpers.hook.HookData[source]

Bases: object

disable_hook(hook)[source]

Adds a hook to the disabled hooks list.

enable_hook(hook)[source]

Removes a command from the disabled hooks list.

get_disabled_hooks()[source]
get_enabled_hooks()[source]
get_hook_objects()[source]
get_known_hooks()[source]
is_disabled(hook)[source]
register(hook)[source]
scan_for_hooks()[source]

Scans for hooks

Return type:list
Returns:A list of modules that failed to reload

cslbot.helpers.identity module

cslbot.helpers.identity.do_kick(session, nick)[source]
cslbot.helpers.identity.get_chain(session, nick, limit=0)[source]
cslbot.helpers.identity.handle_nick(handler, e)[source]

cslbot.helpers.misc module

cslbot.helpers.misc.do_nuke(c, nick, target, channel)[source]
cslbot.helpers.misc.do_pull(srcdir=None, repo=None)[source]
cslbot.helpers.misc.get_channels(chanlist, nick)[source]
cslbot.helpers.misc.get_cmdchar(config, connection, msg, msgtype)[source]
cslbot.helpers.misc.get_fortune(msg, name='fortune')[source]
cslbot.helpers.misc.get_users(args)[source]
cslbot.helpers.misc.get_version(srcdir)[source]
cslbot.helpers.misc.ignore(session, nick)[source]
cslbot.helpers.misc.list_fortunes(offensive=False)[source]
cslbot.helpers.misc.parse_header(header, msg)[source]
cslbot.helpers.misc.parse_time(time)[source]
cslbot.helpers.misc.ping(ping_map, c, e, pongtime)[source]
cslbot.helpers.misc.random() → x in the interval [0, 1).
cslbot.helpers.misc.split_msg(msgs, max_len)[source]

Splits as close to the end as possible.

cslbot.helpers.misc.truncate_msg(msg, max_len)[source]

cslbot.helpers.modutils module

cslbot.helpers.modutils.add_to_groups(config, groups, mod_type)[source]
cslbot.helpers.modutils.get_disabled(mod_type)[source]
cslbot.helpers.modutils.get_enabled(mod_type, package='CslBot')[source]
cslbot.helpers.modutils.get_modules(mod_type)[source]
cslbot.helpers.modutils.group_disabled(mod_type, name)[source]
cslbot.helpers.modutils.group_enabled(mod_type, name)[source]
cslbot.helpers.modutils.init_aux(config)[source]
cslbot.helpers.modutils.init_groups(groups, confdir)[source]
cslbot.helpers.modutils.load_groups(confdir)[source]
cslbot.helpers.modutils.loaded(mod_type, name)[source]
cslbot.helpers.modutils.parse_group(cfg)[source]
cslbot.helpers.modutils.safe_load(modname)[source]

Load a module, logging errors instead of dying if it fails to load

Returns:None when import was successful. String is the first line of the error message
cslbot.helpers.modutils.safe_reload(modname)[source]

Catch and log any errors that arise from reimporting a module, but do not die.

Returns:None when import was successful. String is the first line of the error message
cslbot.helpers.modutils.scan_and_reimport(mod_type)[source]

Scans folder for modules.

cslbot.helpers.orm module

class cslbot.helpers.orm.Babble(**kwargs)[source]

Bases: sqlalchemy.ext.declarative.api.Base

freq
id
key
source
target
word
class cslbot.helpers.orm.Babble2(**kwargs)[source]

Bases: sqlalchemy.ext.declarative.api.Base

freq
id
key
source
target
word
class cslbot.helpers.orm.Babble_count(**kwargs)[source]

Bases: sqlalchemy.ext.declarative.api.Base

count
id
key
length
type
class cslbot.helpers.orm.Babble_last(**kwargs)[source]

Bases: sqlalchemy.ext.declarative.api.Base

id
last
class cslbot.helpers.orm.Commands(**kwargs)[source]

Bases: sqlalchemy.ext.declarative.api.Base

channel
command
id
nick
class cslbot.helpers.orm.Ignore(**kwargs)[source]

Bases: sqlalchemy.ext.declarative.api.Base

expire
id
nick
class cslbot.helpers.orm.Issues(**kwargs)[source]

Bases: sqlalchemy.ext.declarative.api.Base

accepted
description
id
source
title
class cslbot.helpers.orm.Log(**kwargs)[source]

Bases: sqlalchemy.ext.declarative.api.Base

flags
id
msg
source
target
time
type
class cslbot.helpers.orm.Notes(**kwargs)[source]

Bases: sqlalchemy.ext.declarative.api.Base

id
nick
note
pending
submitter
time
class cslbot.helpers.orm.Poll_responses(**kwargs)[source]

Bases: sqlalchemy.ext.declarative.api.Base

id
pid
response
voter
class cslbot.helpers.orm.Polls(**kwargs)[source]

Bases: sqlalchemy.ext.declarative.api.Base

accepted
active
deleted
id
question
submitter
class cslbot.helpers.orm.Quotes(**kwargs)[source]

Bases: sqlalchemy.ext.declarative.api.Base

accepted
id
nick
quote
submitter
class cslbot.helpers.orm.Scores(**kwargs)[source]

Bases: sqlalchemy.ext.declarative.api.Base

id
nick
score
class cslbot.helpers.orm.Stopwatches(**kwargs)[source]

Bases: sqlalchemy.ext.declarative.api.Base

active
elapsed
id
time
class cslbot.helpers.orm.Tumblrs(**kwargs)[source]

Bases: sqlalchemy.ext.declarative.api.Base

accepted
blogname
id
post
submitter
class cslbot.helpers.orm.UrbanBlacklist(**kwargs)[source]

Bases: sqlalchemy.ext.declarative.api.Base

id
word
class cslbot.helpers.orm.Urls(**kwargs)[source]

Bases: sqlalchemy.ext.declarative.api.Base

id
nick
time
title
url
class cslbot.helpers.orm.Weather_prefs(**kwargs)[source]

Bases: sqlalchemy.ext.declarative.api.Base

id
location
nick
cslbot.helpers.orm.setup_db(session, botconfig, confdir)[source]

Sets up the database.

cslbot.helpers.reddit module

cslbot.helpers.reddit.check_exists(subreddit)[source]

Make sure that a subreddit actually exists

cslbot.helpers.reddit.random_post(subreddit, apikey)[source]

Gets a random post from a subreddit and returns a title and shortlink to it

cslbot.helpers.reloader module

cslbot.helpers.reloader.do_log(c, target, msg)[source]
cslbot.helpers.reloader.do_reload(bot, target, cmdargs, server_send=None)[source]

The reloading magic.

First, reload handler.py.
Then make copies of all the handler data we want to keep.
Create a new handler and restore all the data.
cslbot.helpers.reloader.load_modules(cfg, confdir, send=<function error>)[source]

cslbot.helpers.server module

class cslbot.helpers.server.BotNetHandler(request, client_address, server)[source]

Bases: socketserver.BaseRequestHandler

get_data()[source]
handle()[source]
handle_cmd(cmd, bot, send)[source]
class cslbot.helpers.server.BotNetServer(server_address, RequestHandlerClass, bind_and_activate=True)[source]

Bases: socketserver.ThreadingMixIn, socketserver.TCPServer

allow_reuse_address = True
cslbot.helpers.server.init_server(bot)[source]

cslbot.helpers.sql module

class cslbot.helpers.sql.Sql(config, confdir)[source]

Bases: object

log(source, target, flags, msg, mtype)[source]

Logs a message to the database

source: The source of the message.
target: The target of the message.
flags: Is the user a operator or voiced?
msg: The text of the message.
msg: The type of message.
time: The current time (Unix Epoch).
session_scope()[source]

Provide a transactional scope around a series of operations.

cslbot.helpers.sql.get_session(config)[source]

cslbot.helpers.textutils module

cslbot.helpers.textutils.append_filters(filters)[source]
cslbot.helpers.textutils.char_to_bin(c)[source]
cslbot.helpers.textutils.gen_binary(text)[source]
cslbot.helpers.textutils.gen_creffett(msg)[source]
cslbot.helpers.textutils.gen_fwilson(x, mode=None)[source]
cslbot.helpers.textutils.gen_gizoogle(msg)[source]
cslbot.helpers.textutils.gen_hashtag(msg)[source]
cslbot.helpers.textutils.gen_insult(user)[source]
cslbot.helpers.textutils.gen_lenny(msg)[source]
cslbot.helpers.textutils.gen_morse(msg)[source]
cslbot.helpers.textutils.gen_praise(msg)[source]
cslbot.helpers.textutils.gen_randfilter(msg)[source]
cslbot.helpers.textutils.gen_random_translate(msg)[source]
cslbot.helpers.textutils.gen_removevowels(msg)[source]
cslbot.helpers.textutils.gen_shakespeare(msg)[source]
cslbot.helpers.textutils.gen_shibe(msg)[source]
cslbot.helpers.textutils.gen_slogan(msg)[source]
cslbot.helpers.textutils.gen_translate(msg, outputlang='en')[source]
cslbot.helpers.textutils.gen_underscore(msg)[source]
cslbot.helpers.textutils.gen_word()[source]
cslbot.helpers.textutils.gen_xkcd_sub(msg, hook=False)[source]
cslbot.helpers.textutils.gen_yoda(msg)[source]
cslbot.helpers.textutils.get_praise()[source]
cslbot.helpers.textutils.random() → x in the interval [0, 1).
cslbot.helpers.textutils.reverse(msg)[source]
cslbot.helpers.textutils.transform_text(msg)[source]

cslbot.helpers.tokens module

class cslbot.helpers.tokens.Token[source]

Bases: object

class cslbot.helpers.tokens.TranslateToken[source]

Bases: cslbot.helpers.tokens.Token

update(config)[source]
cslbot.helpers.tokens.update_all_tokens(config)[source]

cslbot.helpers.urlutils module

cslbot.helpers.urlutils.ensure_prefix(url)[source]
cslbot.helpers.urlutils.get_short(msg, key)[source]
cslbot.helpers.urlutils.get_title(url)[source]

cslbot.helpers.web module

cslbot.helpers.web.create_issue(title, desc, nick, repo, apikey)[source]
cslbot.helpers.web.get_rand_word(session)[source]
cslbot.helpers.web.get_urban(msg, session, key)[source]
cslbot.helpers.web.get_urban_definition(msg, key)[source]
cslbot.helpers.web.post_tumblr(config, blog, body)[source]

cslbot.helpers.workers module

class cslbot.helpers.workers.Event(event, run_on_cancel)

Bases: tuple

event

Alias for field number 0

run_on_cancel

Alias for field number 1

class cslbot.helpers.workers.Workers(handler)[source]

Bases: object

cancel(eventid)[source]
check_active(handler, send)[source]
check_babble(handler, send)[source]
defer(t, run_on_cancel, func, *args)[source]
handle_pending(handler, send)[source]
restart_pool()[source]
run_action(func, args)[source]
run_pool(func, args)[source]
start_thread(func, *args, **kwargs)[source]
stop_workers(clean)[source]

Stop workers and deferred events

update_tokens(handler)[source]
cslbot.helpers.workers.pool_init()[source]

We ignore Ctrl-C in the poll workers, so that we can clean things up properly.

Module contents