def __init__(self, connector, config_section): """ Create a new Motivator responder. :param connector: The communicator used to communicate with the chatbox. :param config_section: A dictionary of configuration values for this module. """ Module.__init__(self, connector, config_section) if config_section is None: config_section = {} config = configparser.ConfigParser() with open(config_section["config file"], "r") as f: config.read_file(f) self.verbs_to_categories_to_motivators = {} for (verb, section) in config.items(): if verb == "DEFAULT": continue categories_to_motivators = {} for (category, motivators_string) in section.items(): motivators = set() for line in motivators_string.split("\n"): motivator = line.strip() if len(motivator) == 0: continue motivators.add(motivator) categories_to_motivators[category.lower()] = motivators self.verbs_to_categories_to_motivators[verb.lower()] = categories_to_motivators self.random = random.Random()
def __init__(self, connector, config_section=None): """ Create a new no-devil-banana responder. :param connector: The communicator used to communicate with the chatbox. :type connector: vbcbbot.chatbox_connector.ChatboxConnector :param config_section: The configuration section for this module. """ Module.__init__(self, connector, config_section) if config_section is None: config_section = {} smiley_to_nope = {} for line in config_section["smiley to nope"].split("\n"): key_val = line.split(" ") if len(key_val) != 2: continue smiley_to_nope[key_val[0]] = key_val[1] self.nap_time = 30 self.stop_now = False self.nope_queue = queue.Queue(maxsize=128) self.nope_mapping = {} for (smiley, yes_url) in connector.smiley_codes_to_urls.items(): if smiley in smiley_to_nope: self.nope_mapping[yes_url] = smiley_to_nope[smiley] self.nope_sender_thread = threading.Thread(None, self.nope_sender, "NopeSmileys sender")
def __init__(self, connector, config_section): """ Create a new STFU responder. :param connector: The communicator used to communicate with the chatbox. :param config_section: A dictionary of configuration values for this module. """ Module.__init__(self, connector, config_section) if config_section is None: config_section = {} self.stfu_duration = 30*60 if "duration" in config_section: self.stfu_duration = int(config_section["duration"]) self.database = None if "database" in config_section: self.database = sqlite3.connect(config_section["database"], check_same_thread=False) else: self.database = sqlite3.connect(":memory:", check_same_thread=False) self.snark = [] if "snark" in config_section: for line in config_section["snark"].split("\n"): stripped_line = line.strip() if len(stripped_line) == 0: continue self.snark.append(stripped_line) self.admins = set() if "admins" in config_section: for line in config_section["admins"].split("\n"): stripped_line = line.strip() if len(stripped_line) == 0: continue self.admins.add(stripped_line) self.random = random.Random() self.who_shut_me_up_last = None cursor = self.database.cursor() cursor.execute(""" CREATE TABLE IF NOT EXISTS running_bans ( banned_user TEXT NOT NULL, deadline INT, banner TEXT NOT NULL, PRIMARY KEY (banned_user) ) """) self.database.commit() # clear out old bans cursor = self.database.cursor() cursor.execute( "DELETE FROM running_bans WHERE deadline < ?", (time.time(),) ) self.database.commit()
def __init__(self, connector, config_section): """ Create a new MA48 responder. :param connector: The communicator used to communicate with the chatbox. :param config_section: A dictionary of configuration values for this module. """ Module.__init__(self, connector, config_section) if config_section is None: config_section = {}
def __init__(self, connector, config_section): Module.__init__(self, connector, config_section) self.backlog_size = 20 self.trigger_count = 3 if "backlog size" in config_section: self.backlog_size = int(config_section["backlog size"]) if "trigger count" in config_section: self.trigger_count = int(config_section["trigger count"]) self.backlog = []
def __init__(self, connector, config_section): """ Create a new HTTP interface. :param connector: The communicator used to communicate with the chatbox. :param config_section: A dictionary of configuration values for this module. """ Module.__init__(self, connector, config_section) if config_section is None: config_section = {} port = 8099 if "port" in config_section: port = int(config_section["port"]) self.backlog = 50 if "backlog" in config_section: self.backlog = int(config_section["backlog"]) self.allowed_files = {"http_static/style.css", "http_static/common.js"} if "allowed files" in config_section: for f in config_section["allowed files"].split(): self.allowed_files.add(f.strip()) self.quick_messages = [] if "quick messages" in config_section: for msg_line in config_section["quick messages"].split("\n"): msg = msg_line.strip() if len(msg) == 0: continue self.quick_messages.append(msg) self.quick_messages.sort() with open(config_section["page template"], "r") as f: self.page_template = f.read() with open(config_section["post template"], "r") as f: self.post_template = f.read() with open(config_section["editor template"], "r") as f: self.editor_template = f.read() self.username = config_section["username"] self.password = config_section["password"] self.messages = [] self.message_lock = threading.RLock() self.stop_now = False self.server_thread = threading.Thread(None, self.server_proc, "HttpInterface") RequestHandler.http_interface = self self.server = http.server.HTTPServer(('', port), RequestHandler)
def __init__(self, connector, config_section): """ Create a new grinselink responder. :param connector: The communicator used to communicate with the chatbox. :param config_section: A dictionary of configuration values for this module. """ Module.__init__(self, connector, config_section) if config_section is None: config_section = {} self.username_to_monitor = config_section["username to monitor"] self.message_to_post = config_section["message to post"] self.message_to_post_stealth = config_section["message to post stealth"] self.known_grinselink_ids = set()
def __init__(self, connector, config_section): """ Create a new messaging responder. :param connector: The communicator used to communicate with the chatbox. :param config_section: A dictionary of configuration values for this module. """ Module.__init__(self, connector, config_section) if config_section is None: config_section = {} self.database = None if "database" in config_section: self.database = sqlite3.connect(config_section["database"], check_same_thread=False) else: self.database = sqlite3.connect(":memory:", check_same_thread=False) self.spymasters = set() if "spymasters" in config_section: for line in config_section["spymasters"].split("\n"): stripped_line = line.strip() if len(stripped_line) == 0: continue self.spymasters.add(stripped_line) cursor = self.database.cursor() cursor.execute(""" CREATE TABLE IF NOT EXISTS triggers ( trigger_id INTEGER PRIMARY KEY AUTOINCREMENT, target_name_lower TEXT NOT NULL, regex TEXT NOT NULL, spymaster_name TEXT NOT NULL ) """) cursor.execute(""" CREATE TABLE IF NOT EXISTS incidents ( incident_id INTEGER PRIMARY KEY AUTOINCREMENT, trigger_id INTEGER NOT NULL REFERENCES triggers (trigger_id), message_id INTEGER NOT NULL, timestamp INTEGER NOT NULL ) """) cursor.execute("CREATE INDEX IF NOT EXISTS index_target_name_lower ON triggers (target_name_lower)") self.database.commit() cursor.close() self.reload_triggers()
def __init__(self, connector, config_section=None): Module.__init__(self, connector, config_section) if config_section is None: config_section = {} self.sockets_to_clients = [] socket_path = config_section["socket path"] self.username = config_section["username"] self.password = config_section["password"] self.socket = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM, 0) self.socket.bind(socket_path) self.socket.listen(5) self.acceptor_thread = threading.Thread(None, self.acceptor_proc, "UnixSocket acceptor") self.stop_now = False
def __init__(self, connector, config_section): """ Create a new Bin Admin responder. :param connector: The communicator used to communicate with the chatbox. :param config_section: A dictionary of configuration values for this module. """ Module.__init__(self, connector, config_section) if config_section is None: config_section = {} self.database = None if "database" in config_section: self.database = sqlite3.connect(config_section["database"], check_same_thread=False) else: self.database = sqlite3.connect(":memory:", check_same_thread=False) self.banned = set() if "banned" in config_section: for nick_line in config_section["banned"].split("\n"): nick = nick_line.strip() self.banned.add(nick) cursor = self.database.cursor() cursor.execute(""" CREATE TABLE IF NOT EXISTS bins ( bin TEXT NOT NULL, PRIMARY KEY (bin) ) """) cursor.execute(""" CREATE TABLE IF NOT EXISTS bin_items ( bin TEXT NOT NULL REFERENCES bins (bin), item TEXT NOT NULL, arrow TEXT NOT NULL, thrower TEXT NOT NULL, timestamp TEXT NOT NULL, PRIMARY KEY (bin, item) ) """) self.database.commit()
def __init__(self, connector, config_section): """ Create a new messaging responder. :param connector: The communicator used to communicate with the chatbox. :param config_section: A dictionary of configuration values for this module. """ Module.__init__(self, connector, config_section) if config_section is None: config_section = {} self.database = None if "database" in config_section: self.database = sqlite3.connect(config_section["database"], check_same_thread=False) else: self.database = sqlite3.connect(":memory:", check_same_thread=False) self.most_grateful_count = 5 self.most_grateful_count_text = "five" if "most grateful count" in config_section: self.most_grateful_count = int(config_section["most grateful count"]) self.most_grateful_count_text = "{0}".format(self.most_grateful_count) if "most grateful count text" in config_section: self.most_grateful_count_text = config_section["most grateful count text"] self.most_thanked_count = 5 if "most thanked count" in config_section: self.most_thanked_count = int(config_section["most thanked count"]) cursor = self.database.cursor() cursor.execute(""" CREATE TABLE IF NOT EXISTS thanks ( thanker TEXT NOT NULL, thankee_folded TEXT NOT NULL, thank_count INT NOT NULL, PRIMARY KEY (thanker, thankee_folded) ) """) cursor.execute("CREATE INDEX IF NOT EXISTS idx_thanks_thankee ON thanks (thankee_folded)") self.database.commit()
def __init__(self, connector, config_section): """ Create a new messaging responder. :param connector: The communicator used to communicate with the chatbox. :param config_section: A dictionary of configuration values for this module. """ Module.__init__(self, connector, config_section) if config_section is None: config_section = {} self.api_url = config_section["api url"] self.api_username = "" if "username" in config_section: self.api_username = config_section["username"] self.api_password = "" if "password" in config_section: self.api_password = config_section["password"] self.archive_link_template = None if "archive link template" in config_section: self.archive_link_template = config_section["archive link template"]
def __init__(self, connector, config_section): """ Create a new messaging responder. :param connector: The communicator used to communicate with the chatbox. :param config_section: A dictionary of configuration values for this module. """ Module.__init__(self, connector, config_section) if config_section is None: config_section = {} self.api_url = config_section["api url"] self.down_messages = ["[noparse]{sender}[/noparse]: TUWEL is down since {since}. (Last checked {last_update}.)"] if "down messages" in config_section: self.down_messages = parse_messages(config_section["down messages"]) self.up_messages = ["[noparse]{sender}[/noparse]: TUWEL is up since {since}. (Last checked {last_update}.)"] if "up messages" in config_section: self.up_messages = parse_messages(config_section["up messages"]) self.unknown_messages = ["[noparse]{sender}[/noparse]: I don\u2019 know either..."] if "unknown messages" in config_section: self.unknown_messages = parse_messages(config_section["unknown messages"])
def __init__(self, connector, config_section=None): """ Create a new no-devil-banana responder. :param connector: The communicator used to communicate with the chatbox. :param config_section: The configuration section for this module. """ Module.__init__(self, connector, config_section) if config_section is None: config_section = {} self.no_devil_banana_url = config_section['no devil banana url'] self.devil_banana_urls = config_section['devil banana urls'] self.addenda_banana_edited_in = config_section['addenda banana edited in'].split("\n") self.nap_time = 10 self.stop_now = False self.last_nodb_message = -1 self.last_banana_message = -1 self.last_banana_message_due_to_edit = False self.last_lock = threading.Lock() self.randomizer = random.Random() self.nodb_sender_thread = threading.Thread(None, self.nodb_sender, "NoDevilBanana sender")
def __init__(self, connector, config_section): """ Create a new messaging responder. :param connector: The communicator used to communicate with the chatbox. :param config_section: A dictionary of configuration values for this module. """ Module.__init__(self, connector, config_section) if config_section is None: config_section = {} self.database = None if "database" in config_section: self.database = sqlite3.connect(config_section["database"], check_same_thread=False) else: self.database = sqlite3.connect(":memory:", check_same_thread=False) self.too_many_messages = 10 if "too many messages" in config_section: self.too_many_messages = int(config_section["too many messages"]) self.timestamp_link = None if "timestamp link" in config_section: self.timestamp_link = config_section["timestamp link"] self.max_messages_to_replay = 10 if "max messages to replay" in config_section: self.max_messages_to_replay = int(config_section["max messages to replay"]) cursor = self.database.cursor() cursor.execute(""" CREATE TABLE IF NOT EXISTS messages ( message_id INT NOT NULL PRIMARY KEY, timestamp INT NOT NULL, sender_original TEXT NOT NULL, recipient_folded TEXT NOT NULL, body TEXT NOT NULL ) """) cursor.execute(""" CREATE TABLE IF NOT EXISTS messages_on_retainer ( message_id INT NOT NULL PRIMARY KEY, timestamp INT NOT NULL, sender_original TEXT NOT NULL, recipient_folded TEXT NOT NULL, body TEXT NOT NULL ) """) cursor.execute(""" CREATE TABLE IF NOT EXISTS replayable_messages ( message_id INT NOT NULL PRIMARY KEY, timestamp INT NOT NULL, sender_original TEXT NOT NULL, recipient_folded TEXT NOT NULL, body TEXT NOT NULL ) """) cursor.execute(""" CREATE TABLE IF NOT EXISTS ignore_list ( sender_folded TEXT NOT NULL, recipient_folded TEXT NOT NULL, PRIMARY KEY (sender_folded, recipient_folded) ) """) cursor.execute(""" CREATE INDEX IF NOT EXISTS idx_messages_recipient_timestamp ON messages (recipient_folded, message_id ASC) """) cursor.execute(""" CREATE INDEX IF NOT EXISTS idx_messages_on_retainer_recipient_timestamp ON messages_on_retainer (recipient_folded, message_id ASC) """) cursor.execute(""" CREATE INDEX IF NOT EXISTS idx_replayable_messages_recipient_timestamp ON replayable_messages (recipient_folded, message_id ASC) """) self.database.commit()