def receive_info(bot, trigger): if trigger.sender != 'NickServ': return account = Identifier(trigger.group(2)) nick = Identifier(trigger.group(1)) try: bot.db.alias_nick(account, nick) except ValueError as e: try: bot.db.alias_nick(nick, account) except ValueError as e: if nick in force: bot.db.merge_nick_groups(account, nick) first_id = bot.db.get_nick_id(Identifier(account)) second_id = bot.db.get_nick_id(Identifier(nick)) bot.db.execute( 'UPDATE nicknames SET nick_id = ? WHERE nick_id = ?', [first_id, second_id]) bot.msg(nick, 'Merged {0} and {1}. If conflicting values were found' \ ' between accounts, values from {0} were used.'.format(account, nick)) del force[nick] else: extra = '' if nick.lower() != account.lower(): extra = 'If you wish to merge data' \ ' from {0} to {1}, you may do so by using `.alias merge`. Please note that doing so' \ ' will overwrite conflicting values with those found in {0}. '.format(account, nick) bot.msg(nick, 'Sorry, I was unable to alias your nick' \ ' to your account -- it might have already been aliased. {1}({0})'.format(e.message, extra)) return bot.msg(nick, 'Successfully aliased ' + nick + ' to account ' + account)
def receive_info(bot, trigger): if trigger.sender != 'NickServ': return account = Identifier(trigger.group(2)) nick = Identifier(trigger.group(1)) try: bot.db.alias_nick(account, nick) except ValueError as e: try: bot.db.alias_nick(nick, account) except ValueError as e: if nick in force: bot.db.merge_nick_groups(account, nick) first_id = bot.db.get_nick_id(Identifier(account)) second_id = bot.db.get_nick_id(Identifier(nick)) bot.db.execute('UPDATE nicknames SET nick_id = ? WHERE nick_id = ?', [first_id, second_id]) bot.msg(nick, 'Merged {0} and {1}. If conflicting values were found' \ ' between accounts, values from {0} were used.'.format(account, nick)) del force[nick] else: extra = '' if nick.lower() != account.lower(): extra = 'If you wish to merge data' \ ' from {0} to {1}, you may do so by using `.alias merge`. Please note that doing so' \ ' will overwrite conflicting values with those found in {0}. '.format(account, nick) bot.msg(nick, 'Sorry, I was unable to alias your nick' \ ' to your account -- it might have already been aliased. {1}({0})'.format(e.message, extra)) return bot.msg(nick, 'Successfully aliased ' + nick + ' to account ' + account)
def start(bot, trigger): """ Put a bomb in the specified user's pants. They will be kicked if they don't guess the right wire fast enough. """ if not trigger.group(3): bot.say("Who do you want to bomb?") return NOLIMIT if bot.db.get_channel_value(trigger.sender, 'bombs_disabled'): bot.notice("An admin has disabled bombing in %s." % trigger.sender, trigger.nick) return NOLIMIT since_last = time_since_bomb(bot, trigger.nick) if since_last < TIMEOUT and not trigger.admin: bot.notice("You must wait %.0f seconds before you can bomb someone again." % (TIMEOUT - since_last), trigger.nick) return global BOMBS target = Identifier(trigger.group(3)) target_unbombable = bot.db.get_nick_value(target, 'unbombable') if target == bot.nick: bot.say("You thought you could trick me into bombing myself?!") return NOLIMIT if target == trigger.nick: bot.say("%s pls. Bomb a friend if you have to!" % trigger.nick) return NOLIMIT if target.lower() not in bot.privileges[trigger.sender.lower()]: bot.say("You can't bomb imaginary people!") return NOLIMIT if target_unbombable and not trigger.admin: bot.say("I'm not allowed to bomb %s, sorry." % target) return NOLIMIT if bot.db.get_nick_value(trigger.nick, 'unbombable'): bot.say("Try again when you're bombable yourself, %s." % trigger.nick) return NOLIMIT with lock: if target.lower() in BOMBS: bot.say("I can't fit another bomb in %s's pants!" % target) return NOLIMIT wires = [COLORS[i] for i in sorted(sample(xrange(len(COLORS)), randrange(3, 5)))] num_wires = len(wires) wires_list = [formatting.color(str(wire), str(wire)) for wire in wires] wires_list = ", ".join(wires_list[:-2] + [" and ".join(wires_list[-2:])]).replace('Light_', '') wires = [wire.replace('Light_', '') for wire in wires] color = choice(wires) bot.say("Hey, %s! I think there's a bomb in your pants. %s timer, %d wires: %s. " "Which wire would you like to cut? (respond with %scutwire color)" % (target, FUSE_TEXT, num_wires, wires_list, bot.config.core.help_prefix or '.')) bot.notice("Hey, don't tell %s, but it's the %s wire." % (target, color), trigger.nick) if target_unbombable: bot.notice("Just so you know, %s is marked as unbombable." % target, trigger.nick) timer = Timer(FUSE, explode, (bot, trigger)) BOMBS[target.lower()] = (wires, color, timer, target) timer.start() bombs_planted = bot.db.get_nick_value(trigger.nick, 'bombs_planted') or 0 bot.db.set_nick_value(trigger.nick, 'bombs_planted', bombs_planted + 1) bot.db.set_nick_value(trigger.nick, 'bomb_last_planted', time.time())
def bomb_glue(bot, trigger): old = trigger.nick new = Identifier(trigger) with lock: if old.lower() in BOMBS: BOMBS[new.lower()] = BOMBS.pop(old.lower()) bot.notice("There's still a bomb in your pants, %s!" % new, new)
def explode(bot, trigger): target = Identifier(trigger.group(3)) orig_target = target with lock: if target.lower() not in BOMBS: # nick change happened for nick in BOMBS.keys(): if BOMBS[nick][3] == target: target = Identifier(nick) break bot.say("%s pls, you could've at least picked one! Now you're dead. You see that? " "Guts, all over the place. (You should've picked the %s wire.)" % (target, BOMBS[target.lower()][1])) kickboom(bot, trigger, target) BOMBS.pop(target.lower()) timeouts = bot.db.get_nick_value(orig_target, 'bomb_timeouts') or 0 bot.db.set_nick_value(orig_target, 'bomb_timeouts', timeouts + 1)
def get_nick_value(self, nick, key): """Retrieves the value for a given key associated with a nick.""" nick = Identifier(nick) result = self.execute( 'SELECT value FROM nicknames, nick_values WHERE slug = ? AND key = ?', [nick.lower(), key]).fetchone() if result is not None: result = result[0] return _deserialize(result)
def get_nick_value(self, nick, key): """Retrieves the value for a given key associated with a nick.""" nick = Identifier(nick) result = self.execute( 'SELECT value FROM nicknames, nick_values WHERE slug = ? AND key = ?', [nick.lower(), key] ).fetchone() if result is not None: result = result[0] return _deserialize(result)
def unalias_nick(self, alias): """Removes an alias. Raises ValueError if there is not at least one other nick in the group. To delete an entire group, use `delete_group`. """ alias = Identifier(alias) nick_id = self.get_nick_id(alias, False) count = self.execute("SELECT COUNT(*) FROM nicknames WHERE nick_id = ?", [nick_id]).fetchone()[0] if count == 0: raise ValueError("Given alias is the only entry in its group.") self.execute("DELETE FROM nicknames WHERE slug = ?", [alias.lower()])
def cutwire(bot, trigger): """ Tells willie to cut a wire when you've been bombed. """ global BOMBS target = Identifier(trigger.nick) with lock: if target.lower() != bot.nick.lower() and target.lower() not in BOMBS: bot.say("You can't cut a wire until someone bombs you, %s." % target) return if not trigger.group(3): bot.say("You have to choose a wire to cut.") return # Remove target from bomb list temporarily wires, color, timer, orig_target = BOMBS.pop(target.lower()) wirecut = trigger.group(3) if wirecut.lower() in ('all', 'all!'): timer.cancel() # defuse timer, execute premature detonation bot.say("Cutting ALL the wires! (You should've picked the %s wire.)" % color) kickboom(bot, trigger, target) alls = bot.db.get_nick_value(orig_target, 'bomb_alls') or 0 bot.db.set_nick_value(orig_target, 'bomb_alls', alls + 1) elif wirecut.capitalize() not in wires: bot.say("That wire isn't here, %s! You sure you're picking the right one?" % target) # Add the target back onto the bomb list BOMBS[target.lower()] = (wires, color, timer, orig_target) elif wirecut.capitalize() == color: bot.say("You did it, %s! I'll be honest, I thought you were dead. " "But nope, you did it. You picked the right one. Well done." % target) timer.cancel() # defuse bomb defuses = bot.db.get_nick_value(orig_target, 'bomb_defuses') or 0 bot.db.set_nick_value(orig_target, 'bomb_defuses', defuses + 1) else: timer.cancel() # defuse timer, execute premature detonation bot.say("Nope, wrong wire! Aww, now you've gone and killed yourself. " "Wow. Sorry. (You should've picked the %s wire.)" % color) kickboom(bot, trigger, target) wrongs = bot.db.get_nick_value(orig_target, 'bomb_wrongs') or 0 bot.db.set_nick_value(orig_target, 'bomb_wrongs', wrongs + 1)
def unalias_nick(self, alias): """Removes an alias. Raises ValueError if there is not at least one other nick in the group. To delete an entire group, use `delete_group`. """ alias = Identifier(alias) nick_id = self.get_nick_id(alias, False) count = self.execute('SELECT COUNT(*) FROM nicknames WHERE nick_id = ?', [nick_id]).fetchone()[0] if count == 0: raise ValueError('Given alias is the only entry in its group.') self.execute('DELETE FROM nicknames WHERE slug = ?', [alias.lower()])
def alias_nick(self, nick, alias): """Create an alias for a nick. Raises ValueError if the alias already exists. If nick does not already exist, it will be added along with the alias.""" nick = Identifier(nick) alias = Identifier(alias) nick_id = self.get_nick_id(nick) sql = "INSERT INTO nicknames (nick_id, slug, canonical) VALUES (?, ?, ?)" values = [nick_id, alias.lower(), alias] try: self.execute(sql, values) except sqlite3.IntegrityError as e: raise ValueError("Alias already exists.")
def alias_nick(self, nick, alias): """Create an alias for a nick. Raises ValueError if the alias already exists. If nick does not already exist, it will be added along with the alias.""" nick = Identifier(nick) alias = Identifier(alias) nick_id = self.get_nick_id(nick) sql = 'INSERT INTO nicknames (nick_id, slug, canonical) VALUES (?, ?, ?)' values = [nick_id, alias.lower(), alias] try: self.execute(sql, values) except sqlite3.IntegrityError as e: raise ValueError('Alias already exists.')