def doPrivmsg(self, irc, msg): self.addIRC(irc) channel = msg.args[0] s = msg.args[1] s, args = self.getPrivmsgData(channel, msg.nick, s, self.registryValue('color', channel)) ignoreNicks = [ircutils.toLower(item) for item in \ self.registryValue('nickstoIgnore.nicks', msg.args[0])] if self.registryValue('nickstoIgnore.affectPrivmsgs', msg.args[0]) \ == 1 and ircutils.toLower(msg.nick) in ignoreNicks: #self.log.debug('LinkRelay: %s in nickstoIgnore...' % ircutils.toLower(msg.nick)) #self.log.debug('LinkRelay: List of ignored nicks: %s' % ignoreNicks) return elif channel not in irc.state.channels: # in private # cuts off the end of commands, so that passwords # won't be revealed in relayed PM's if callbacks.addressed(irc.nick, msg): if self.registryValue('color', channel): color = '\x03' + self.registryValue('colors.truncated', channel) match = '(>\017 \w+) .*' else: color = '' match = '(> \w+) .*' s = re.sub(match, '\\1 %s[%s]' % (color, _('truncated')), s) s = '(via PM) %s' % s self.sendToOthers(irc, channel, s, args, isPrivmsg=True)
def rpm(self, irc, msg, args, remoteuser, otherIrc, text): """<remoteUser> <network> <text> Sends a private message to a user on a remote network.""" found = found2 = False if not self.registryValue("remotepm.enable"): irc.error("This command is not enabled; please set 'config plugins.relaylink.remotepm.enable' " "to True.", Raise=True) for relay in self.relays: channels = otherIrc.state.channels for key, channel_ in channels.items(): if ircutils.toLower(relay.targetChannel) \ == ircutils.toLower(key) and remoteuser in channel_.users: found = True break for ch in irc.state.channels: if ircutils.toLower(relay.sourceChannel) == \ ircutils.toLower(ch) and msg.nick in irc.state.channels[ch].users: found2 = True break if found and found2: prefix = msg.prefix if self.registryValue("remotepm.useHostmasks") else msg.nick if self.registryValue("remotepm.useNotice"): otherIrc.queueMsg(ircmsgs.notice(remoteuser, "Message from %s on %s: %s" % (prefix, irc.network, text))) else: otherIrc.queueMsg(ircmsgs.privmsg(remoteuser, "Message from %s on %s: %s" % (prefix, irc.network, text))) else: irc.error("User '%s' does not exist on %s or you are not sharing " "a channel with them." % (remoteuser, otherIrc.network), Raise=True)
def key(self, k): if isinstance(k, str): k = ircutils.toLower(k) elif isinstance(k, tuple): k = tuple([(ircutils.toLower(x) if isinstance(x, str) else x) for x in k]) else: assert False return k
def doMode(self, irc, msg): ignoreNicks = [ircutils.toLower(item) for item in \ self.registryValue('nickstoIgnore.nicks', msg.args[0])] if ircutils.toLower(msg.nick) not in ignoreNicks: self.addIRC(irc) args = {'nick': msg.nick, 'channel': msg.args[0], 'mode': ' '.join(msg.args[1:]), 'color': ''} if self.registryValue('color', msg.args[0]): args['color'] = '\x03%s' % self.registryValue('colors.mode', msg.args[0]) s = '%(color)s' + _('MODE: %(nick)s%(sepTagn)s%(network)s sets mode %(mode)s ' ' on %(channel)s%(sepTagc)s%(network)s') self.sendToOthers(irc, msg.args[0], s, args)
def doQuit(self, irc, msg): ignoreNicks = [ircutils.toLower(item) for item in \ self.registryValue('nickstoIgnore.nicks', msg.args[0])] if ircutils.toLower(msg.nick) not in ignoreNicks: args = {'nick': msg.nick, 'network': irc.network, 'message': msg.args[0], 'color': '', 'userhost': ''} if self.registryValue('color', msg.args[0]): args['color'] = '\x03%s' % self.registryValue('colors.quit', msg.args[0]) s = '%(color)s' + _('QUIT: %(nick)s%(sepTagn)s%(network)s' ' has quit (%(message)s)') self.sendToOthers(irc, None, s, args, msg.nick) self.addIRC(irc)
def doKick(self, irc, msg): """Kill the authentication when user gets kicked.""" channels = self.registryValue("channels").split(";") if msg.args[0] in channels and irc.network == self.registryValue("network"): (channel, nick) = msg.args[:2] if ircutils.toLower(irc.nick) in ircutils.toLower(nick): self.authlog.info("***** clearing authed_users due to self-kick. *****") self.authed_users.clear() else: try: hostmask = irc.state.nickToHostmask(nick) self._unauth(irc, hostmask) except KeyError: pass
def doKick(self, irc, msg): """Kill the authentication when user gets kicked.""" channels = self.registryValue('channels').split(';') if msg.args[0] in channels and irc.network == self.registryValue('network'): (channel, nicks) = msg.args[:2] if ircutils.toLower(irc.nick) in ircutils.toLower(nicks).split(','): self.authed_users.clear() else: for nick in nicks: try: hostmask = irc.state.nickToHostmask(nick) self._unauth(hostmask) except KeyError: pass
def doNick(self, irc, msg): ignoreNicks = [ircutils.toLower(item) for item in \ self.registryValue('nickstoIgnore.nicks', msg.args[0])] if ircutils.toLower(msg.nick) not in ignoreNicks: self.addIRC(irc) args = {'oldnick': msg.nick, 'network': irc.network, 'newnick': msg.args[0], 'color': ''} if self.registryValue('color', msg.args[0]): args['color'] = '\x03%s' % self.registryValue('colors.nick', msg.args[0]) s = '%(color)s' + _('NICK: %(oldnick)s%(sepTagn)s%(network)s' ' changed nick to %(newnick)s') for (channel, c) in irc.state.channels.iteritems(): if msg.args[0] in c.users: self.sendToOthers(irc, channel, s, args)
def doKick(self, irc, msg): """Kill the authentication when user gets kicked.""" channels = self.registryValue('channels').split(';') if msg.args[0] in channels and irc.network == self.registryValue('network'): (channel, nick) = msg.args[:2] if ircutils.toLower(irc.nick) in ircutils.toLower(nick): self.authlog.info("***** clearing authed_users due to self-kick. *****") self.authed_users.clear() else: try: hostmask = irc.state.nickToHostmask(nick) self._unauth(irc, hostmask) except KeyError: pass
def doJoin(self, irc, msg): ignoreNicks = [ircutils.toLower(item) for item in \ self.registryValue('nickstoIgnore.nicks', msg.args[0])] if ircutils.toLower(msg.nick) not in ignoreNicks: self.addIRC(irc) args = {'nick': msg.nick, 'channel': msg.args[0], 'color': '', 'userhost': ''} if self.registryValue('color', msg.args[0]): args['color'] = '\x03%s' % self.registryValue('colors.join', msg.args[0]) if self.registryValue('hostmasks', msg.args[0]): args['userhost'] = ' (%s@%s)' % (msg.user, msg.host) s = '%(color)s' + _('JOIN: %(nick)s%(sepTagn)s%(network)s' '%(userhost)s has joined %(channel)s%(sepTagc)s' '%(network)s') self.sendToOthers(irc, msg.args[0], s, args)
def start(self, irc, msg, args, channel, num): """[<channel>] [<number of questions>] Starts a game of trivia. <channel> is only necessary if the message isn't sent in the channel itself.""" if num == None: num = self.registryValue('defaultRoundLength', channel) #elif num > 100: # irc.reply('sorry, for now, you can\'t start games with more ' # 'than 100 questions :(') # num = 100 channel = ircutils.toLower(channel) if channel in self.games: if not self.games[channel].active: del self.games[channel] try: schedule.removeEvent('next_%s' % channel) except KeyError: pass irc.reply(_('Orphaned trivia game found and removed.')) else: self.games[channel].num += num self.games[channel].total += num irc.reply(_('%d questions added to active game!') % num) else: self.games[channel] = self.Game(irc, channel, num, self) irc.noReply()
def randombomb(self, irc, msg, args, channel, nicks): """takes no arguments Bombs a random person in the channel """ channel = ircutils.toLower(channel) if not self.registryValue('allowBombs', msg.args[0]): irc.reply('Timebombs aren\'t allowed in this channel. Set plugins.Timebomb.allowBombs to true if you want them.') return try: if self.bombs[channel].active: irc.reply('There\'s already an active bomb, in %s\'s pants!' % self.bombs[channel].victim) return except KeyError: pass if self.registryValue('bombActiveUsers', msg.args[0]): if len(nicks) == 0: nicks = list(irc.state.channels[channel].users) items = self.talktimes.iteritems() nicks = [] for i in range(0, len(self.talktimes)): try: item = items.next() if time.time() - item[1] < self.registryValue('idleTime', msg.args[0])*60 and item[0] in irc.state.channels[channel].users: nicks.append(item[0]) except StopIteration: irc.reply('hey quantumlemur, something funny happened... I got a StopIteration exception') if len(nicks) == 1 and nicks[0] == msg.nick: nicks = [] if len(nicks) == 0: irc.reply('Well, no one\'s talked in the past hour, so I guess I\'ll just choose someone from the whole channel') nicks = list(irc.state.channels[channel].users) elif len(nicks) == 2: irc.reply('Well, it\'s just been you two talking recently, so I\'m going to go ahead and just bomb someone at random from the whole channel') nicks = list(irc.state.channels[channel].users) elif len(nicks) == 0: nicks = list(irc.state.channels[channel].users) if irc.nick in nicks and not self.registryValue('allowSelfBombs', msg.args[0]): nicks.remove(irc.nick) ##### #irc.reply('These people are eligible: %s' % utils.str.commaAndify(nicks)) victim = self.rng.choice(nicks) while victim == self.lastBomb or victim in self.registryValue('exclusions', msg.args[0]): victim = self.rng.choice(nicks) self.lastBomb = victim detonateTime = self.rng.randint(self.registryValue('minRandombombTime', msg.args[0]), self.registryValue('maxRandombombTime', msg.args[0])) wireCount = self.rng.randint(self.registryValue('minWires', msg.args[0]), self.registryValue('maxWires', msg.args[0])) if wireCount < 12: colors = self.registryValue('shortcolors') else: colors = self.registryValue('colors') wires = self.rng.sample(colors, wireCount) goodWire = self.rng.choice(wires) self.log.info("TimeBomb: Safewire is %s"%goodWire) irc.queueMsg(ircmsgs.privmsg("##sgoutput", "TIMEBOMB: Safe wire is %s"%goodWire)) self.bombs[channel] = self.Bomb(irc, victim, wires, detonateTime, goodWire, channel, msg.nick, self.registryValue('showArt', msg.args[0]), self.registryValue('showCorrectWire', msg.args[0]), self.registryValue('debug')) try: irc.noReply() except AttributeError: pass
def doJoin(self, irc, msg): nick = ircutils.toLower(msg.nick) if len(msg.args) < 2: # extended-join is not supported return channel = msg.args[0].split(',')[0] account = msg.args[1] if ircutils.strEqual(irc.nick, msg.nick): # message from self return if 'batch' in msg.server_tags and \ msg.server_tags['batch'] in irc.state.batches and \ irc.state.batches[msg.server_tags['batch']].type == 'netjoin': # ignore netjoin return if not ircutils.isChannel( channel) or channel not in irc.state.channels: return if not self.registryValue('enabled', channel): return if account == '*': irc.queueMsg( ircmsgs.notice( nick, 'You joined {}, but you are not identified to services and cannot speak.' ' For help with identification, type "/msg nickserv help register"' .format(channel)))
def do311(self, irc, msg): irc = self._getRealIrc(irc) nick = ircutils.toLower(msg.args[1]) if (irc, nick) not in self._whois: return else: self._whois[(irc, nick)][-1][msg.command] = msg
def timebomb(self, irc, msg, args, channel, victim): """<nick> For bombing people!""" channel = ircutils.toLower(channel) if not self.registryValue('allowBombs', channel): irc.reply('Timebombs aren\'t allowed in this channel. Set plugins.Timebomb.allowBombs to true if you want them.') return try: if self.bombs[channel].active: irc.reply('There\'s already an active bomb, in{}\'s pants!'.format(self.bombs[channel].victim)) return except KeyError: pass if victim.lower() == irc.nick.lower() and not self.registryValue('allowSelfBombs', channel): irc.reply('You really expect me to bomb myself? Stuffing explosives into my own pants isn\'t exactly my idea of fun.') return victim = string.lower(victim) found = False for nick in list(irc.state.channels[channel].users): if victim == string.lower(nick): victim = nick found = True if not found: irc.reply('Error: nick not found.') return if string.lower(victim) in self.registryValue('exclusions', channel): irc.reply('Error: that nick can\'t be timebombed') return # not (victim == msg.nick and victim == 'mniip') and if not ircdb.checkCapability(msg.prefix, 'admin') and not self._canBomb(irc, channel, msg.nick, victim, True): return detonateTime = self.rng.randint(self.registryValue('minTime', channel), self.registryValue('maxTime', channel)) wireCount = self.rng.randint(self.registryValue('minWires', channel), self.registryValue('maxWires', channel)) # if victim.lower() == 'halite' or (victim == msg.nick and victim == 'mniip'): # wireCount = self.rng.randint(11,20) if wireCount < 12: colors = self.registryValue('shortcolors') else: colors = self.registryValue('colors') wires = self.rng.sample(colors, wireCount) goodWire = self.rng.choice(wires) self.log.info("TimeBomb: Safewire is {}".format(goodWire)) if self.registryValue('debug'): irc.reply('I\'m about to create a bomb in{}'.format(channel)) # if not (victim == msg.nick and victim == 'mniip'): self._logBomb(irc, channel, msg.nick, victim) self.bombs[channel] = self.Bomb(irc, victim, wires, detonateTime, goodWire, channel, msg.nick, self.registryValue('showArt', channel), self.registryValue('showCorrectWire', channel), self.registryValue('debug')) irc.queueMsg(ircmsgs.privmsg("jacksonmj", "TIMEBOMB: Safe wire is {}".format(goodWire))) # irc.queueMsg(ircmsgs.privmsg("##jacksonmj-test", "TIMEBOMB: Safe wire is {}".format(goodWire))) irc.queueMsg(ircmsgs.privmsg("##jacksonmj-test", "TIMEBOMB: Safe wire is {}".format(self.rng.choice(wires)))) if self.registryValue('debug'): irc.reply('This message means that I got past the bomb creation line in the timebomb command')
def addwebhook(self, irc, msg, args, optrepo, optchannel): """<repository name> [#channel] Add announcing of repository webhooks to channel. """ # first check for channel. chan = msg.args[0] if not irc.isChannel(ircutils.toLower(chan)): # we're NOT run in a channel. if not optchannel: irc.reply("ERROR: You must specify a channel or run from a channel in order to add.") return else: # set chan as what the user wants. chan = optchannel # lower both chan = chan.lower() optrepo = optrepo.lower() # now lets try and add the repo. sanity check if present first. if optrepo in self._webhooks: # channel already in the webhooks. if chan in self._webhooks[optrepo]: # channel already there. irc.reply("ERROR: {0} is already being announced on {1}".format(optrepo, chan)) return # last check is to see if we're on the channel. if chan not in irc.state.channels: irc.reply("ERROR: I must be present on a channel ({0}) you're trying to add.".format(chan)) return # otherwise, we're good. lets use the _addHook. try: self._webhooks[optrepo].add(chan) self._savepickle() # save. irc.replySuccess() except Exception as e: irc.reply("ERROR: I could not add {0} to {1} :: {2}".format(optrepo, chan, e))
def start(self, irc, msg, args, channel, num): """[<channel>] [<number of questions>] Starts a game of trivia. <channel> is only necessary if the message isn't sent in the channel itself.""" if num == None: num = self.registryValue('defaultRoundLength', channel) #elif num > 100: # irc.reply('sorry, for now, you can\'t start games with more ' # 'than 100 questions :(') # num = 100 channel = ircutils.toLower(channel) if channel in self.games: if not self.games[channel].active: del self.games[channel] try: schedule.removeEvent('next_%s' % channel) except KeyError: pass irc.reply('Orphaned trivia game found and removed.') else: self.games[channel].num += num self.games[channel].total += num irc.reply('%d questions added to active game!' % num) else: self.games[channel] = self.Game(irc, channel, num, self) irc.noReply()
def getChanRecordingTimeBoundaries(self, chanName): """Returns two tuples, containing the min and max values of each year/month/day/dayofweek/hour field. Note that this data comes from the cache, so they might be a bit outdated if DEBUG is False.""" chanName = ircutils.toLower(chanName) cursor = self._conn.cursor() cursor.execute( """SELECT MIN(year), MIN(month), MIN(day), MIN(dayofweek), MIN(hour) FROM chans_cache WHERE chan=?""", (chanName,), ) min_ = cursor.fetchone() cursor = self._conn.cursor() cursor.execute( """SELECT MAX(year), MAX(month), MAX(day), MAX(dayofweek), MAX(hour) FROM chans_cache WHERE chan=?""", (chanName,), ) max_ = cursor.fetchone() if None in min_: min_ = tuple([int("0") for x in max_]) if None in max_: max_ = tuple([int("0") for x in max_]) assert None not in min_ assert None not in max_ return min_, max_
def getChanRecordingTimeBoundaries(self, chanName): """Returns two tuples, containing the min and max values of each year/month/day/dayofweek/hour field. Note that this data comes from the cache, so they might be a bit outdated if DEBUG is False.""" chanName = ircutils.toLower(chanName) cursor = self._conn.cursor() cursor.execute( """SELECT MIN(year), MIN(month), MIN(day), MIN(dayofweek), MIN(hour) FROM chans_cache WHERE chan=?""", (chanName, )) min_ = cursor.fetchone() cursor = self._conn.cursor() cursor.execute( """SELECT MAX(year), MAX(month), MAX(day), MAX(dayofweek), MAX(hour) FROM chans_cache WHERE chan=?""", (chanName, )) max_ = cursor.fetchone() if None in min_: min_ = tuple([int('0') for x in max_]) if None in max_: max_ = tuple([int('0') for x in max_]) assert None not in min_ assert None not in max_ return min_, max_
def start(self, irc, msg, args, channel, num): """[<kanal>] [<broj pitanja>] Zapocinje novu igru. <kanal> nije obavezan osim u slucaju da komandu dajete botu na PM.""" if num == None: num = self.registryValue('defaultRoundLength', channel) #elif num > 100: # irc.reply('Zao nam je ali za sada ne mozete igrati sa vise ' # 'od 100 pitanja :(') # num = 100 channel = ircutils.toLower(channel) if channel in self.games: if not self.games[channel].active: del self.games[channel] try: schedule.removeEvent('next_%s' % channel) except KeyError: pass irc.reply(_('Orphaned trivia game found and removed.')) else: self.games[channel].num += num self.games[channel].total += num irc.reply(_('%d pitanja dodano u trenutnu igru!') % num) else: self.games[channel] = self.Game(irc, channel, num, self) irc.noReply()
def playing(self, irc, msg, args): channel = ircutils.toLower(msg.args[0]) nick = msg.nick if channel in self.games: game = self.games[channel] if game.running == False: if nick in game.players: irc.reply("You already are playing.") else: if len(game.players) < game.maxPlayers: game.players.append(nick) irc.reply( "Added, Spots left %d/%d. Current Players %s" % ( game.maxPlayers - len(game.players), game.maxPlayers, ", ".join(game.players), )) else: irc.reply("Too many players") if len(game.players) > 1: game.canStart = True else: irc.reply("Game not running.")
def add(self, capability): """Adds a capability to the set.""" capability = ircutils.toLower(capability) inverted = _invert(capability) if self.__parent.__contains__(inverted): self.__parent.remove(inverted) self.__parent.add(capability)
def delwebhook(self, irc, msg, args, optrepo, optchannel): """<repo> <channel> Delete announcement of repository from channel. """ # first check for channel. chan = msg.args[0] if not irc.isChannel(ircutils.toLower(chan)): # we're NOT run in a channel. if not optchannel: irc.reply("ERROR: You must specify a channel or run from a channel in order to add.") return else: # set chan as what the user wants. chan = optchannel # lower both chan = chan.lower() optrepo = optrepo.lower() # make sure repo is valid. if optrepo not in self._webhooks: # channel already in the webhooks. irc.reply("ERROR: {0} repository is invalid. Valid choices: {0}".format(self._webhooks.keys())) return # if repo is valid, make sure channel is in there. if chan not in self._webhooks[optrepo]: # channel already there. irc.reply("ERROR: {0} is an invalid channel for repository: {1}. Repos being announced: {2}".format(chan, optrepo, self._webhooks[optrepo])) return # we're here if all is good. lets try to delete. try: self._webhooks[optrepo].remove(chan) # delete. # now lets check if the channel is empty and remove if it is. if len(self._webhooks[optrepo]) == 0: del self._webhooks[optrepo] irc.replySuccess() except Exception as e: irc.reply("ERROR: I could not delete channel {0} for {1} :: {2}".format(chan, optrepo, e))
def cutwire(self, irc, msg, args, channel, cutWire): """<colored wire> Will cut the given wire if you've been timebombed.""" channel = ircutils.toLower(channel) try: if not self.bombs[channel].active: return if not ircutils.nickEqual(self.bombs[channel].victim, msg.nick): irc.reply('You can\'t cut the wire on someone else\'s bomb!') return else: self.responded = True spellCheck = False for item in self.bombs[channel].wires : if item.lower() == cutWire.lower(): spellCheck = True if spellCheck == False : irc.reply("That doesn't appear to be one of the options.") return self.bombs[channel].cutwire(irc, cutWire) except KeyError: pass irc.noReply()
def start(self, irc, msg, args, channel, optlist): """[<channel>] [--num <number of questions>] [--cat <category>] Starts a game of Jeopardy! <channel> is only necessary if the message isn't sent in the channel itself.""" optlist = dict(optlist) if 'num' in optlist: num = optlist.get('num') else: num = self.registryValue('defaultRoundLength', channel) if 'cat' in optlist: category = optlist.get('cat') else: category = 'random' channel = ircutils.toLower(channel) if channel in self.games: if not self.games[channel].active: del self.games[channel] try: schedule.removeEvent('next_%s' % channel) except KeyError: pass irc.reply(_('Orphaned Jeopardy! game found and removed.')) irc.reply("This... is... Jeopardy!", prefixNick=False) self.games[channel] = self.Game(irc, channel, num, category, self) else: self.games[channel].num += num self.games[channel].total += num irc.reply(_('%d questions added to active game!') % num) else: irc.reply("This... is... Jeopardy!", prefixNick=False) self.games[channel] = self.Game(irc, channel, num, category, self) irc.noReply()
def getChanXXlyData(self, chanName, type_): """Same as getChanGlobalData, but for the given year/month/day/dayofweek/hour. For example, getChanXXlyData('#test', 'hour') returns a list of 24 getChanGlobalData-like tuples.""" chanName = ircutils.toLower(chanName) sampleQuery = """SELECT SUM(lines), SUM(words), SUM(chars), SUM(joins), SUM(parts), SUM(quits), SUM(nicks), SUM(kickers), SUM(kickeds) FROM chans_cache WHERE chan=? and %s=?""" min_, max_ = self.getChanRecordingTimeBoundaries(chanName) typeToIndex = {"year": 0, "month": 1, "day": 2, "dayofweek": 3, "hour": 4} if type_ not in typeToIndex: raise ValueError("Invalid type") min_ = min_[typeToIndex[type_]] max_ = max_[typeToIndex[type_]] results = {} for index in range(min_, max_ + 1): query = sampleQuery % (type_) cursor = self._conn.cursor() cursor.execute(query, (chanName, index)) try: row = cursor.fetchone() assert row is not None if None in row: row = tuple([0 for x in range(0, len(row))]) results.update({index: row}) except: self._addKeyInTmpCacheIfDoesNotExist(results, index) cursor.close() assert None not in results return results
def timebomb(self, irc, msg, args, channel, victim): """<nick> For bombing people!""" channel = ircutils.toLower(channel) if not self.registryValue('allowBombs', msg.args[0]): irc.reply( 'Timebombs aren\'t allowed in this channel. Set plugins.Timebomb.allowBombs to true if you want them.' ) return try: if self.bombs[channel].active: irc.reply('There\'s already an active bomb, in %s\'s pants!' % self.bombs[channel].victim) return except KeyError: pass if victim == irc.nick and not self.registryValue( 'allowSelfBombs', msg.args[0]): irc.reply( 'You really expect me to bomb myself? Stuffing explosives into my own pants isn\'t exactly my idea of fun.' ) return victim = string.lower(victim) found = False for nick in list(irc.state.channels[channel].users): if victim == string.lower(nick): victim = nick found = True if not found: irc.reply('Error: nick not found.') return detonateTime = self.rng.randint( self.registryValue('minTime', msg.args[0]), self.registryValue('maxTime', msg.args[0])) wireCount = self.rng.randint( self.registryValue('minWires', msg.args[0]), self.registryValue('maxWires', msg.args[0])) if wireCount < 12: colors = self.registryValue('shortcolors') else: colors = self.registryValue('colors') wires = self.rng.sample(colors, wireCount) goodWire = self.rng.choice(wires) self.log.info("TimeBomb: Safewire is %s" % goodWire) irc.queueMsg( ircmsgs.privmsg("##sgoutput", "TIMEBOMB: Safe wire is %s" % goodWire)) if self.registryValue('debug'): irc.reply('I\'m about to create a bomb in %s' % channel) self.bombs[channel] = self.Bomb( irc, victim, wires, detonateTime, goodWire, channel, msg.nick, self.registryValue('showArt', msg.args[0]), self.registryValue('showCorrectWire', msg.args[0]), self.registryValue('debug')) if self.registryValue('debug'): irc.reply( 'This message means that I got past the bomb creation line in the timebomb command' )
def timebomb(self, irc, msg, args, channel, victim): """<nick> For bombing people!""" channel = ircutils.toLower(channel) if irc.nick in irc.state.channels[channel].ops: pass else: irc.reply("I can't timebomb properly without ops now, can I?") return if not self.registryValue('allowBombs', msg.args[0]): irc.noReply() return try: if self.bombs[channel].active: irc.reply('There\'s already an active bomb, in %s\'s pants!' % self.bombs[channel].victim) return except KeyError: pass if victim == irc.nick and not self.registryValue( 'allowSelfBombs', msg.args[0]): irc.reply( 'You really expect me to bomb myself? Stuffing explosives into my own pants isn\'t exactly my idea of fun.' ) return victim = string.lower(victim) found = False for nick in list(irc.state.channels[channel].users): if victim == string.lower(nick): victim = nick found = True if not found: irc.reply('Error: nick not found.') return detonateTime = self.rng.randint( self.registryValue('minTime', msg.args[0]), self.registryValue('maxTime', msg.args[0])) wireCount = self.rng.randint( self.registryValue('minWires', msg.args[0]), self.registryValue('maxWires', msg.args[0])) if wireCount > 6: colors = self.registryValue('shortcolors') else: colors = self.registryValue('colors') wires = self.rng.sample(colors, wireCount) goodWire = self.rng.choice(wires) if self.registryValue('debug'): irc.reply('I\'m about to create a bomb in %s' % channel) self.bombs[channel] = self.Bomb( irc, victim, wires, detonateTime, goodWire, channel, msg.nick, self.registryValue('showArt', msg.args[0]), self.registryValue('showCorrectWire', msg.args[0]), self.registryValue('debug')) if self.registryValue('debug'): irc.reply( 'This message means that I got past the bomb creation line in the timebomb command' )
def scah(self, irc, msg, args): channel = ircutils.toLower(msg.args[0]) if channel in self.games: self.games[channel].close() self.games.pop(channel) irc.reply("Game stopped.") else: irc.reply("Game not running.")
def doPrivmsg(self, irc, msg): channel = ircutils.toLower(msg.args[0]) if not irc.isChannel(channel): return if callbacks.addressed(irc.nick, msg): return if channel in self.games: self.games[channel].answer(msg)
def __contains__(self, capability, ignoreOwner=False): capability = ircutils.toLower(capability) if not ignoreOwner and capability == 'owner' or capability == antiOwner: return True elif not ignoreOwner and self.__parent.__contains__('owner'): return True else: return self.__parent.__contains__(capability)
def __contains__(self, capability): capability = ircutils.toLower(capability) if self.__parent.__contains__(capability): return True if self.__parent.__contains__(_invert(capability)): return True else: return False
def __contains__(self, capability): capability = ircutils.toLower(capability) if capability == 'owner' or capability == antiOwner: return True elif self.__parent.__contains__('owner'): return True else: return self.__parent.__contains__(capability)
def _doKarma(self, irc, msg, channel, thing): def get_karma_word(thing, suffixes): words = thing.split() karma_words = [word for word in words if word.endswith(tuple(suffixes))] if len(karma_words != 1): return None return karma_words[0] inc = self.registryValue('incrementChars', channel) dec = self.registryValue('decrementChars', channel) inc_word = get_karma_word(thing, inc) dec_word = get_karma_word(thing, dec) # Ignore if there is not an unambigous op if (inc_word is None) != (dec_word is None): return word = inc_word or dec_word cmp_word = self._normalizeThing(ircutils.toLower(word)) # Don't karma if self rating is disabled allow_self_rating = self.registryValue('allowSelfRating', channel) if not allow_self_rating and cmp_word == ircutils.toLower(msg.nick): irc.error(_('You\'re not allowed to adjust your own karma.')) return # Don't karma if the target isn't a nick only_nicks = self.registryValue('onlyNicks', channel) if only_nicks: users = [ircutils.toLower(user) for user in irc.state.channels[channel].users] if not cmp_word in users: return # Execute the karma op karma = '' if inc_word: self.db.increment(channel, cmp_word) karma = self.db.get(channel, cmp_word) else: self.db.decrement(channel, cmp_word) karma = self.db.get(channel, cmp_word) if karma: self._respond(irc, channel, thing, karma[0]-karma[1])
def stopcah(self, irc, msg, args): channel = ircutils.toLower(msg.args[0]) if channel in self.games: self.games[channel].close() self.games.pop(channel) irc.reply("Game stopped.") else: irc.reply("Game not running.")
def randombomb(self, irc, msg, args, channel, nicks): """takes no arguments Bombs a random person in the channel """ channel = ircutils.toLower(channel) if not self.registryValue('allowBombs', msg.args[0]): irc.noReply() return try: if self.bombs[channel].active: irc.reply('There\'s already an active bomb, in %s\'s pants!' % self.bombs[channel].victim) return except KeyError: pass if self.registryValue('bombActiveUsers', msg.args[0]): if len(nicks) == 0: nicks = list(irc.state.channels[channel].users) items = self.talktimes.iteritems() nicks = [] for i in range(0, len(self.talktimes)): try: item = items.next() if time.time() - item[1] < self.registryValue('idleTime', msg.args[0])*60 and item[0] in irc.state.channels[channel].users: nicks.append(item[0]) except StopIteration: irc.reply('hey quantumlemur, something funny happened... I got a StopIteration exception') if len(nicks) == 1 and nicks[0] == msg.nick: nicks = [] if len(nicks) == 0: irc.reply('Well, no one\'s talked in the past hour, so I guess I\'ll just choose someone from the whole channel') nicks = list(irc.state.channels[channel].users) elif len(nicks) == 2: irc.reply('Well, it\'s just been you two talking recently, so I\'m going to go ahead and just bomb someone at random from the whole channel') nicks = list(irc.state.channels[channel].users) elif len(nicks) == 0: nicks = list(irc.state.channels[channel].users) if irc.nick in nicks and not self.registryValue('allowSelfBombs', msg.args[0]): nicks.remove(irc.nick) ##### #irc.reply('These people are eligible: %s' % utils.str.commaAndify(nicks)) victim = self.rng.choice(nicks) while victim == self.lastBomb or victim in self.registryValue('exclusions', msg.args[0]): victim = self.rng.choice(nicks) self.lastBomb = victim detonateTime = self.rng.randint(self.registryValue('minRandombombTime', msg.args[0]), self.registryValue('maxRandombombTime', msg.args[0])) wireCount = self.rng.randint(self.registryValue('minWires', msg.args[0]), self.registryValue('maxWires', msg.args[0])) if wireCount > 6: colors = self.registryValue('shortcolors') else: colors = self.registryValue('colors') wires = self.rng.sample(colors, wireCount) goodWire = self.rng.choice(wires) self.bombs[channel] = self.Bomb(irc, victim, wires, detonateTime, goodWire, channel, msg.nick, self.registryValue('showArt', msg.args[0]), self.registryValue('showCorrectWire', msg.args[0]), self.registryValue('debug')) try: irc.noReply() except AttributeError: pass
def do341(self, irc, msg): (foo, nick, channel) = msg.args nick = ircutils.toLower(nick) replyIrc = self.invites.pop((irc, nick), None) if replyIrc is not None: self.log.info("Inviting %s to %s by command of %s.", nick, channel, replyIrc.msg.prefix) replyIrc.replySuccess() else: self.log.info("Inviting %s to %s.", nick, channel)
def do402(self, irc, msg): nick = msg.args[1] loweredNick = ircutils.toLower(nick) if (irc, loweredNick) not in self._whois: return (replyIrc, replyMsg, d) = self._whois[(irc, loweredNick)] del self._whois[(irc, loweredNick)] s = _('There is no %s on %s.') % (nick, irc.network) replyIrc.reply(s)
def auth(self, irc, msg, args): """takes no argument Tries to authenticate you using network services. If you get no reply, it means you are not authenticated to the network services.""" nick = ircutils.toLower(msg.nick) self._requests[(irc.network, msg.nick)] = (time.time(), msg.prefix, irc) irc.queueMsg(ircmsgs.whois(nick, nick))
def do402(self, irc, msg): nick = msg.args[1] loweredNick = ircutils.toLower(nick) if (irc, loweredNick) not in self._whois: return (replyIrc, replyMsg, d) = self._whois[(irc, loweredNick)] del self._whois[(irc, loweredNick)] s = 'There is no %s on %s.' % (nick, irc.network) replyIrc.reply(s)
def hint(self, irc, msg, args, channel): """[<channel>] Invokes the next hint for the current question""" channel = ircutils.toLower(channel) if channel in self.games: self.games[channel].hintcommand() else: irc.reply(_("Trivia is currently not active in this channel."))
def whatNick(self, irc, msg, args, otherIrc, nick): """[<network>] <nick> """ # The double nick here is necessary because single-nick WHOIS only works # if the nick is on the same server (*not* the same network) as the user # giving the command. Yeah, it made me say wtf too. nick = ircutils.toLower(nick) otherIrc.queueMsg(ircmsgs.whois(nick, nick)) self._whois[(otherIrc, nick)] = (irc, msg, {})
def next(self, irc, msg, args, channel): """[<channel>] Moves onto the next question.""" channel = ircutils.toLower(channel) if channel in self.games: self.games[channel].skip() else: irc.reply(_("Trivia is currently not active in this channel."))
def doLog(self, irc, channel, s): if not self.registryValue('enabled', channel): return channel = ircutils.toLower(channel) if channel not in self.logs.keys(): self.logs[channel] = [] format = conf.supybot.log.timestampFormat() if format: s = time.strftime(format, time.gmtime()) + " " + ircutils.stripFormatting(s) self.logs[channel] = self.logs[channel][-199:] + [s.strip()]
def do402(self, irc, msg): irc = self._getRealIrc(irc) nick = msg.args[1] loweredNick = ircutils.toLower(nick) if (irc, loweredNick) not in self._whois: return (replyIrc, replyMsg, d) = self._whois[(irc, loweredNick)] del self._whois[(irc, loweredNick)] s = format(_('There is no %s on %s.'), nick, self._getIrcName(irc)) replyIrc.reply(s)
def invite(self, irc, msg, args, channel, nick): """[<channel>] <nick> If you have the #channel,op capability, this will invite <nick> to join <channel>. <channel> is only necessary if the message isn't sent in the channel itself. """ nick = nick or msg.nick self._sendMsg(irc, ircmsgs.invite(nick, channel)) self.invites[(irc.getRealIrc(), ircutils.toLower(nick))] = irc
def do341(self, irc, msg): (foo, nick, channel) = msg.args nick = ircutils.toLower(nick) replyIrc = self.invites.pop((irc, nick), None) if replyIrc is not None: self.log.info('Inviting %s to %s by command of %s.', nick, channel, replyIrc.msg.prefix) replyIrc.replySuccess() else: self.log.info('Inviting %s to %s.', nick, channel)
def forcestart(self, irc, msg, args): channel = ircutils.toLower(msg.args[0]) if channel in self.games: try: schedule.removeEvent("start_game_%s" % self.channel) except: pass self.games[channel].startgame() else: irc.reply("Game not running.")
def do311(self, irc, msg): nick = ircutils.toLower(msg.args[1]) if (irc, nick) not in self._whois: return elif msg.command == '319': if '319' not in self._whois[(irc, nick)][2]: self._whois[(irc, nick)][2][msg.command] = [] self._whois[(irc, nick)][2][msg.command].append(msg) else: self._whois[(irc, nick)][2][msg.command] = msg