def _doKarma(self, irc, channel, thing): assert thing[-2:] in ('++', '--') if thing.endswith('C++'): c = 2 elif thing.endswith('c++'): c = 2 elif thing.endswith('++'): thing = thing[:-2] if ircutils.strEqual(thing, irc.msg.nick) and \ not self.registryValue('allowSelfRating', channel): irc.error('Voc\xc3\xaa n\xc3\xa3o pode dar cervejas para voc\xc3\xaa mesmo') elif thing: self.db.increment(channel, self._normalizeThing(thing)) self._respond(irc, channel) else: thing = thing[:-2] if ircutils.strEqual(thing, irc.msg.nick) and \ not self.registryValue('allowSelfRating', channel): irc.error('Voc\xc3\xaa n\xc3\xa3o pode dar cervejas para voc\xc3\xaa mesmo') elif thing: self.db.decrement(channel, self._normalizeThing(thing)) self._respond(irc, channel) t = self.db.get(channel, thing) (added, subtracted) = t total = added - subtracted if thing.endswith('C++'): c = 2 elif thing.endswith('c++'): c = 2 else: irc.reply('%s tem %s00Ml de cerveja' % (thing, total))
def shutup(self, irc, msg, args, text): """<who> [for <reason>] Tells <who> to shutup. """ def _firstWord(s): return s.split()[0] if ' for ' in text: (target, reason) = map(str.strip, text.split(' for ', 1)) else: (target, reason) = (text, '') msgtext = "duct tapes $who" text = self._replaceFirstPerson(msgtext, msg.nick) if ircutils.strEqual(target, irc.nick) or ircutils.strEqual(_firstWord(target), irc.nick): target = msg.nick reason = self._replaceFirstPerson('trying to dis me', irc.nick) else: target = self._replaceFirstPerson(target, msg.nick) reason = self._replaceFirstPerson(reason, msg.nick) if target.endswith('.'): target = target.rstrip('.') text = text.replace('$who', target) if reason: text += ' for ' + reason irc.reply(text, action=True)
def _doKarma(self, irc, msg, channel, thing): inc = self.registryValue('incrementChars', channel) dec = self.registryValue('decrementChars', channel) onlynicks = self.registryValue('onlyNicks', channel) karma = '' for s in inc: if thing.endswith(s): thing = thing[:-len(s)] # Don't reply if the target isn't a nick if onlynicks and thing.lower() not in map(ircutils.toLower, irc.state.channels[channel].users): return if ircutils.strEqual(thing, msg.nick) and \ not self.registryValue('allowSelfRating', channel): irc.error(_('You\'re not allowed to adjust your own karma.')) return self.db.increment(channel, self._normalizeThing(thing)) karma = self.db.get(channel, self._normalizeThing(thing)) for s in dec: if thing.endswith(s): thing = thing[:-len(s)] if onlynicks and thing.lower() not in map(ircutils.toLower, irc.state.channels[channel].users): return if ircutils.strEqual(thing, msg.nick) and \ not self.registryValue('allowSelfRating', channel): irc.error(_('You\'re not allowed to adjust your own karma.')) return self.db.decrement(channel, self._normalizeThing(thing)) karma = self.db.get(channel, self._normalizeThing(thing)) if karma: self._respond(irc, channel, thing, karma[0]-karma[1])
def doNick(self, irc, msg): nick = self._getNick() if ircutils.strEqual(msg.args[0], irc.nick) and \ ircutils.strEqual(irc.nick, nick): self._doIdentify(irc) elif ircutils.strEqual(msg.nick, nick): irc.sendMsg(ircmsgs.nick(nick))
def _doKarma(self, irc, msg, channel, thing): inc = self.registryValue('incrementChars', channel) dec = self.registryValue('decrementChars', channel) if thing.endswith(tuple(inc + dec)): for s in inc: if thing.endswith(s): thing = thing[:-len(s)] if ircutils.strEqual(thing, msg.nick) and \ not self.registryValue('allowSelfRating', channel): irc.error( _('You\'re not allowed to adjust your own karma.')) return self.db.increment(channel, self._normalizeThing(thing)) karma = self.db.get(channel, self._normalizeThing(thing)) for s in dec: if thing.endswith(s): thing = thing[:-len(s)] if ircutils.strEqual(thing, msg.nick) and \ not self.registryValue('allowSelfRating', channel): irc.error( _('You\'re not allowed to adjust your own karma.')) return self.db.decrement(channel, self._normalizeThing(thing)) karma = self.db.get(channel, self._normalizeThing(thing)) self._respond(irc, channel, thing, karma[0] - karma[1])
def _doKatelloKarma(self, irc, channel, thing): assert thing[-2:] in ('++', '--') if thing.endswith('++'): thing = thing[:-2] if ircutils.strEqual(thing, irc.msg.nick) and \ not self.registryValue('allowSelfRating', channel): irc.error('You\'re not allowed to adjust your own karma.') elif thing: self.db.increment(channel, self._normalizeThing(thing)) t = self.db.get(channel, thing) if t is None: irc.reply(format('%s has neutral karma.', thing)) else: (added, subtracted) = t total = added - subtracted irc.reply( format('%s has %i point(s) of karma', thing, total)) else: thing = thing[:-2] if ircutils.strEqual(thing, irc.msg.nick) and \ not self.registryValue('allowSelfRating', channel): irc.error('You\'re not allowed to adjust your own karma.') elif thing: self.db.decrement(channel, self._normalizeThing(thing)) self._respond(irc, channel)
def _doKarma(self, irc, msg, channel, thing): inc = self.registryValue('incrementChars', channel) dec = self.registryValue('decrementChars', channel) onlynicks = self.registryValue('onlyNicks', channel) karma = '' for s in inc: if thing.endswith(s): thing = thing[:-len(s)] # Don't reply if the target isn't a nick if onlynicks and thing.lower() not in map( ircutils.toLower, irc.state.channels[channel].users): return if ircutils.strEqual(thing, msg.nick) and \ not self.registryValue('allowSelfRating', channel): irc.error( _('You\'re not allowed to adjust your own karma.')) return self.db.increment(channel, self._normalizeThing(thing)) karma = self.db.get(channel, self._normalizeThing(thing)) for s in dec: if thing.endswith(s): thing = thing[:-len(s)] if onlynicks and thing.lower() not in map( ircutils.toLower, irc.state.channels[channel].users): return if ircutils.strEqual(thing, msg.nick) and \ not self.registryValue('allowSelfRating', channel): irc.error( _('You\'re not allowed to adjust your own karma.')) return self.db.decrement(channel, self._normalizeThing(thing)) karma = self.db.get(channel, self._normalizeThing(thing)) if karma: self._respond(irc, channel, thing, karma[0] - karma[1])
def doNotice(self, irc, msg): if irc.afterConnect: nickserv = self.registryValue('NickServ') chanserv = self.registryValue('ChanServ') if nickserv and ircutils.strEqual(msg.nick, nickserv): self.doNickservNotice(irc, msg) elif chanserv and ircutils.strEqual(msg.nick, chanserv): self.doChanservNotice(irc, msg)
def doMode(self, irc, msg): channel = msg.channel chanOp = ircdb.makeChannelCapability(channel, 'op') chanVoice = ircdb.makeChannelCapability(channel, 'voice') chanHalfOp = ircdb.makeChannelCapability(channel, 'halfop') if not ircdb.checkCapability(msg.prefix, chanOp): irc.sendMsg(ircmsgs.deop(channel, msg.nick)) for (mode, value) in ircutils.separateModes(msg.args[1:]): if not value: continue if ircutils.strEqual(value, msg.nick): # We allow someone to mode themselves to oblivion. continue if irc.isNick(value): hostmask = irc.state.nickToHostmask(value) if mode == '+o': if not self.isOp(irc, channel, hostmask): irc.queueMsg(ircmsgs.deop(channel, value)) elif mode == '+h': if not ircdb.checkCapability(hostmask, chanHalfOp): irc.queueMsg(ircmsgs.dehalfop(channel, value)) elif mode == '+v': if not ircdb.checkCapability(hostmask, chanVoice): irc.queueMsg(ircmsgs.devoice(channel, value)) elif mode == '-o': if ircdb.checkCapability(hostmask, chanOp): irc.queueMsg(ircmsgs.op(channel, value)) elif mode == '-h': if ircdb.checkCapability(hostmask, chanOp): irc.queueMsg(ircmsgs.halfop(channel, value)) elif mode == '-v': if ircdb.checkCapability(hostmask, chanOp): irc.queueMsg(ircmsgs.voice(channel, value)) else: assert ircutils.isUserHostmask(value)
def doJoin(self, irc, msg): #irc.reply("hello") if ircutils.strEqual(irc.nick, msg.nick): return # It's us channel = msg.args[0] if channel != "#code4lib" and channel not in test_channels: return #if self.db[channel, msg.nick] is None: try: self.db.get(channel, msg.nick) except KeyError: # The except means that we only message people not yet in the db. irc.queueMsg(ircmsgs.privmsg(msg.nick, joinmsg % (irc.nick))) irc.noReply() #self.db.add(channel, msg.nick) self.db.add(channel, msg.nick) # Also notify the helpers privately if a potential newbie shows up, # so that we can roll out the welcome mat human-style. for helper in self._get_helpers(channel): # Sometimes the helpers db stores blank lines, which we should # ignore. if helper: irc.queueMsg( ircmsgs.privmsg(helper, helpermsg % (msg.nick))) irc.noReply()
def greeter(self, irc, msg, args): """ (add|remove) nick1 [nick2 nick3...] This plugin will issue a greeting via privmsg for the first time someone joins a channel. Doing greeter add foobar causes that nick to be added to the list of nicks to ignore. Remove command removes them from the list of nicks to ignore. If called without arguments, will send the caller the introduction message via privmsg, regardless of whether they've already been greeted. """ channel = msg.args[0] # apparently having remove and add in their own defs # makes then "available" as their own plugins. IE # @remove and @add, don't want that, so having the # @greeter part do the add/remove via private methods if len(args) == 0: if ircutils.strEqual(irc.nick, msg.nick): return # It's us irc.queueMsg(ircmsgs.privmsg(msg.nick, joinmsg % (irc.nick))) irc.noReply() else: # should see if there's a way to trigger help message irc.reply(" I don't understand what you are asking ")
def doMode(self, irc, msg): channel = msg.args[0] chanOp = ircdb.makeChannelCapability(channel, 'op') chanVoice = ircdb.makeChannelCapability(channel, 'voice') chanHalfOp = ircdb.makeChannelCapability(channel, 'halfop') if not ircdb.checkCapability(msg.prefix, chanOp): irc.sendMsg(ircmsgs.deop(channel, msg.nick)) for (mode, value) in ircutils.separateModes(msg.args[1:]): if not value: continue if ircutils.strEqual(value, msg.nick): # We allow someone to mode themselves to oblivion. continue if irc.isNick(value): hostmask = irc.state.nickToHostmask(value) if mode == '+o': if not self.isOp(irc, channel, hostmask): irc.queueMsg(ircmsgs.deop(channel, value)) elif mode == '+h': if not ircdb.checkCapability(hostmask, chanHalfOp): irc.queueMsg(ircmsgs.dehalfop(channel, value)) elif mode == '+v': if not ircdb.checkCapability(hostmask, chanVoice): irc.queueMsg(ircmsgs.devoice(channel, value)) elif mode == '-o': if ircdb.checkCapability(hostmask, chanOp): irc.queueMsg(ircmsgs.op(channel, value)) elif mode == '-h': if ircdb.checkCapability(hostmask, chanOp): irc.queueMsg(ircmsgs.halfop(channel, value)) elif mode == '-v': if ircdb.checkCapability(hostmask, chanOp): irc.queueMsg(ircmsgs.voice(channel, value)) else: assert ircutils.isUserHostmask(value)
def doInvite(self, irc, msg): if ircutils.strEqual(msg.nick, self.registryValue('ChanServ')): channel = msg.args[1] on = 'on %s' % irc.network networkGroup = conf.supybot.networks.get(irc.network) self.log.info('Joining %s, invited by ChanServ %s.', channel, on) irc.queueMsg(networkGroup.channels.join(channel))
def any(self, irc, msg, args, channel, optlist, name): """[<channel>] [--user <name>] [<nick>] Returns the last time <nick> was seen and what <nick> was last seen doing. This includes any form of activity, instead of just PRIVMSGs. If <nick> isn't specified, returns the last activity seen in <channel>. If --user is specified, looks up name in the user database and returns the last time user was active in <channel>. <channel> is only necessary if the message isn't sent on the channel itself. """ if name and ircutils.strEqual(name, irc.nick): irc.reply(_("You've found me!")) return self._checkChannelPresence(irc, channel, msg.nick, True) if name and optlist: raise callbacks.ArgumentError elif name: self._seen(irc, channel, name, any=True) elif optlist: for (option, arg) in optlist: if option == 'user': user = arg self._user(irc, channel, user, any=True) else: self._last(irc, channel, any=True)
def rank(self, irc, msg, args, channel, expr): """[<channel>] <stat expression> Returns the ranking of users according to the given stat expression. Valid variables in the stat expression include 'msgs', 'chars', 'words', 'smileys', 'frowns', 'actions', 'joins', 'parts', 'quits', 'kicks', 'kicked', 'topics', and 'modes'. Any simple mathematical expression involving those variables is permitted. """ # XXX I could do this the right way, and abstract out a safe eval, # or I could just copy/paste from the Math plugin. if expr != expr.translate(utils.str.chars, '_[]'): irc.error( 'There\'s really no reason why you should have ' 'underscores or brackets in your mathematical ' 'expression. Please remove them.', Raise=True) if 'lambda' in expr: irc.error('You can\'t use lambda in this command.', Raise=True) expr = expr.lower() users = [] for ((c, id), stats) in self.db.items(): if ircutils.strEqual(c, channel) and ircdb.users.hasUser(id): e = self._env.copy() for attr in stats._values: e[attr] = float(getattr(stats, attr)) try: v = eval(expr, e, e) except ZeroDivisionError: v = float('inf') except NameError, e: irc.errorInvalid('stat variable', str(e).split()[1]) except Exception, e: irc.error(utils.exnToString(e), Raise=True) users.append((v, ircdb.users.getUser(id).name))
def doJoin(self, irc, msg): channel = msg.args[0] if self.registryValue('enabled', channel): if not ircutils.strEqual(irc.nick, msg.nick): irc = callbacks.SimpleProxy(irc, msg) now = time.time() throttle = self.registryValue('throttle', channel) if now - self.lastBacklog.get((channel, msg.nick), now-1-throttle) < throttle: return else: self.lastBacklog[channel, msg.nick] = now try: lines = int(self.db["1337allthechannels1337", msg.nick]) except: lines = int(self.registryValue('lines')) if lines != 0: irc.queueMsg(ircmsgs.notice(msg.nick, "Hello "+msg.nick+". I will now show you up to "+str(lines)+" messages from "+channel+", before you joined. To change this behavior, write me: @setbackloglines [0-25]. Setting it to zero disables this feature. Time is GMT.")) logg = self.logck.get(channel, lines) for i in range(0, lines): if len(logg) <= 0: break; else: irc.queueMsg(ircmsgs.notice(msg.nick,str((logg[:1]).pop()))) logg = logg[1:] self.doLog(irc, channel, '*** %s <%s> has joined %s', msg.nick, msg.prefix, channel)
def praise(self, irc, msg, args, channel, id, text): """[<channel>] [<id>] <who|what> [for <reason>] Praises <who|what> (for <reason>, if given). If <id> is given, uses that specific praise. <channel> is only necessary if the message isn't sent in the channel itself. """ if ' for ' in text: (target, reason) = map(str.strip, text.split(' for ', 1)) else: (target, reason) = (text, '') if ircutils.strEqual(target, irc.nick): target = 'itself' if id is not None: try: praise = self.db.get(channel, id) except KeyError: irc.error(format('There is no praise with id #%i.', id)) return else: praise = self.db.random(channel) if not praise: irc.error(format('There are no praises in my database ' \ 'for %s.', channel)) return text = self._replaceFirstPerson(praise.text, msg.nick) reason = self._replaceFirstPerson(reason, msg.nick) target = self._replaceFirstPerson(target, msg.nick) text = text.replace('$who', target) if reason: text += ' for ' + reason if self.registryValue('showIds', channel): text += format(' (#%i)', praise.id) # changed action to False -- gsf 2007-07-25 irc.reply(text, action=False, prefixNick=False)
def praise(self, irc, msg, args, channel, id, text): """[<channel>] [<id>] <who|what> [for <reason>] Praises <who|what> (for <reason>, if given). If <id> is given, uses that specific praise. <channel> is only necessary if the message isn't sent in the channel itself. """ if ' for ' in text: (target, reason) = list(map(str.strip, text.split(' for ', 1))) else: (target, reason) = (text, '') if ircutils.strEqual(target, irc.nick): target = 'itself' if id is not None: try: praise = self.db.get(channel, id) except KeyError: irc.error(format(_('There is no praise with id #%i.'), id)) return else: praise = self.db.random(channel) if not praise: irc.error(format(_('There are no praises in my database ' \ 'for %s.'), channel)) return text = self._replaceFirstPerson(praise.text, msg.nick) reason = self._replaceFirstPerson(reason, msg.nick) target = self._replaceFirstPerson(target, msg.nick) text = text.replace('$who', target) if reason: text += _(' for ') + reason if self.registryValue('showIds', channel): text += format(' (#%i)', praise.id) irc.reply(text, action=True)
def rank(self, irc, msg, args, channel, expr): """[<channel>] <stat expression> Returns the ranking of users according to the given stat expression. Valid variables in the stat expression include 'msgs', 'chars', 'words', 'smileys', 'frowns', 'actions', 'joins', 'parts', 'quits', 'kicks', 'kicked', 'topics', and 'modes'. Any simple mathematical expression involving those variables is permitted. """ # XXX I could do this the right way, and abstract out a safe eval, # or I could just copy/paste from the Math plugin. if expr != expr.translate(utils.str.chars, '_[]'): irc.error('There\'s really no reason why you should have ' 'underscores or brackets in your mathematical ' 'expression. Please remove them.', Raise=True) if 'lambda' in expr: irc.error('You can\'t use lambda in this command.', Raise=True) expr = expr.lower() users = [] for ((c, id), stats) in self.db.items(): if ircutils.strEqual(c, channel) and ircdb.users.hasUser(id): e = self._env.copy() for attr in stats._values: e[attr] = float(getattr(stats, attr)) try: v = eval(expr, e, e) except ZeroDivisionError: v = float('inf') except NameError, e: irc.errorInvalid('stat variable', str(e).split()[1]) except Exception, e: irc.error(utils.exnToString(e), Raise=True) users.append((v, ircdb.users.getUser(id).name))
def unload(self, irc, msg, args, name): """<plugin> Unloads the callback by name; use the 'list' command to see a list of the currently loaded plugins. Obviously, the Owner plugin can't be unloaded. """ if ircutils.strEqual(name, self.name()): irc.error('You can\'t unload the %s plugin.' % name) return # Let's do this so even if the plugin isn't currently loaded, it doesn't # stay attempting to load. old_callback = irc.getCallback(name) if old_callback: # Normalize the plugin case to prevent duplicate registration # entries, https://github.com/ProgVal/Limnoria/issues/1295 name = old_callback.name() conf.registerPlugin(name, False) callbacks = irc.removeCallback(name) if callbacks: for callback in callbacks: callback.die() del callback gc.collect() irc.replySuccess() return irc.error('There was no plugin %s.' % name)
def tell(self, irc, msg, args, nicks, text): """<nick1[,nick2[,...]]> <text> Tells each <nickX> <text> the next time <nickX> is seen. <nickX> can contain wildcard characters, and the first matching nick will be given the note. """ self._deleteExpired() validnicks = [] for nick in nicks: if ircutils.strEqual(nick, irc.nick): irc.error(_('I can\'t send notes to myself.')) return validnick = self._validateNick(irc, nick) if validnick is False: irc.error(_('%s is an invalid IRC nick. Please check your ' 'input.' % nick)) return validnicks.append(validnick) full_queues = [] for validnick in validnicks: try: self._addNote(validnick, msg.nick, text) except ValueError: full_queues.append(validnick) if full_queues: irc.error(format( _('These recipients\' message queue are already full: %L'), full_queues)) else: irc.replySuccess()
def quiet(self, irc, msg, args, channel, nick, expiry): """[<channel>] <nick> [<expiry>] Quietens <nick> from <channel> for <expiry>. If <expiry> isn't given, the duration is permanent. <channel> is only necessary if the message isn't sent in the channel itself. """ if irc.isNick(nick): bannedNick = nick try: bannedHostmask = irc.state.nickToHostmask(nick) except KeyError: irc.error(format(_('I haven\'t seen %s.'), bannedNick), Raise=True) else: bannedNick = ircutils.nickFromHostmask(nick) bannedHostmask = nick if not irc.isNick(bannedNick): self.log.warning('%q tried to quiet a non nick: %q', msg.prefix, bannedNick) raise callbacks.ArgumentError banmaskstyle = conf.supybot.protocols.irc.banmask banmask = banmaskstyle.makeBanmask(bannedHostmask) if ircutils.strEqual(nick, irc.nick): irc.error('I cowardly refuse to quiet myself.', Raise=True) thismsg=self.registryValue('message') self._sendMsg(irc, ircmsgs.mode(channel, ("+q", banmask))) if self.registryValue('SendMsgPvt'): self._sendMsg(irc, ircmsgs.privmsg(nick,nick+", "+thismsg )) else: self._sendMsg(irc, ircmsgs.privmsg(channel,nick+", "+thismsg )) def f(): irc.queueMsg(ircmsgs.mode(channel, ("-q", banmask))) if expiry: schedule.addEvent(f, expiry)
def tell(self, irc, msg, args, nicks, text): """<nick1[,nick2[,...]]> <text> Tells each <nickX> <text> the next time <nickX> is seen. <nickX> can contain wildcard characters, and the first matching nick will be given the note. """ self._deleteExpired() validnicks = [] for nick in set(nicks): # Ignore duplicates if ircutils.strEqual(nick, irc.nick): irc.error(_('I can\'t send notes to myself.')) return validnicks.append(nick) full_queues = [] for validnick in validnicks: try: self._addNote(validnick, msg.nick, text) except QueueIsFull: full_queues.append(validnick) if full_queues: irc.error(format( _('These recipients\' message queue are already full: %L'), full_queues)) else: irc.replySuccess()
def _validLastMsg(self, irc, msg, chan): return ( msg.prefix and msg.command == "PRIVMSG" and irc.isChannel(msg.args[0]) and ircutils.strEqual(chan, msg.args[0]) )
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 add(self, irc, msg, args, user, capability): """<name|hostmask> <capability> Gives the user specified by <name> (or the user to whom <hostmask> currently maps) the specified capability <capability> """ # Ok, the concepts that are important with capabilities: # ### 1) No user should be able to elevate his privilege to owner. ### 2) Admin users are *not* superior to #channel.ops, and don't ### have God-like powers over channels. ### 3) We assume that Admin users are two things: non-malicious and ### and greedy for power. So they'll try to elevate their ### privilege to owner, but they won't try to crash the bot for ### no reason. # Thus, the owner capability can't be given in the bot. Admin # users can only give out capabilities they have themselves (which # will depend on supybot.capabilities and its child default) but # generally means they can't mess with channel capabilities. if ircutils.strEqual(capability, 'owner'): irc.error('The "owner" capability can\'t be added in the bot.' ' Use the supybot-adduser program (or edit the ' 'users.conf file yourself) to add an owner ' 'capability.') return if ircdb.isAntiCapability(capability) or \ ircdb.checkCapability(msg.prefix, capability): user.addCapability(capability) ircdb.users.setUser(user) irc.replySuccess() else: irc.error('You can\'t add capabilities you don\'t have.')
def reload(self, irc, msg, args, name): """<plugin> Unloads and subsequently reloads the plugin by name; use the 'list' command to see a list of the currently loaded plugins. """ if ircutils.strEqual(name, self.name()): irc.error('You can\'t reload the %s plugin.' % name) return callbacks = irc.removeCallback(name) if callbacks: module = sys.modules[callbacks[0].__module__] if hasattr(module, 'reload'): x = module.reload() try: module = plugin.loadPluginModule(name) if hasattr(module, 'reload') and 'x' in locals(): module.reload(x) if hasattr(module, 'config'): from imp import reload reload(module.config) for callback in callbacks: callback.die() del callback gc.collect() # This makes sure the callback is collected. callback = plugin.loadPluginClass(irc, module) irc.replySuccess() except ImportError: for callback in callbacks: irc.addCallback(callback) irc.error('No plugin named %s exists.' % name) else: irc.error('There was no plugin %s.' % name)
def doJoin(self, irc, msg): channel = msg.args[0] sender = msg.nick if (ircutils.strEqual(msg.nick, irc.nick)): ### Put the per-channel values into the channel's config # get the graph graph = self.instances[irc.network].getGraph(channel) # pull out the config and copy it channelConfig = graph.config.copy() # put in the values channelConfig.update( outputWidth=self.registryValue('image.outputWidth', channel), outputHeight=self.registryValue('image.outputHeight', channel), backgroundColor=pyPie.getcolor(self.registryValue('color.backgroundColor', channel)), channelColor=pyPie.getcolor(self.registryValue('color.channelColor', channel)), labelColor=pyPie.getcolor(self.registryValue('color.labelColor', channel)), titleColor=pyPie.getcolor(self.registryValue('color.titleColor', channel)), nodeColor=pyPie.getcolor(self.registryValue('color.nodeColor', channel)), edgeColor=pyPie.getcolor(self.registryValue('color.edgeColor', channel)), borderColor=pyPie.getcolor(self.registryValue('color.borderColor', channel)), ignoreSet=self.registryValue('ignore.ignoreSet', channel), ) # put the config in the graph graph.config = channelConfig self.instances[irc.network].onJoin(channel, sender)
def blame(self, irc, msg, args, channel, id, text): """[<channel>] [<id>] <who|what> [for <reason>] Blames <who|what> (for <reason>, if given). If <id> is given, uses that specific blame. <channel> is only necessary if the message isn't sent in the channel itself. """ if " for " in text: (target, reason) = map(str.strip, text.split(" for ", 1)) else: (target, reason) = (text, "") if ircutils.strEqual(target, irc.nick): target = "itself" if id is not None: try: blame = self.db.get(channel, id) except KeyError: irc.error(format("There is no blame with id #%i.", id)) return else: blame = self.db.random(channel) if not blame: irc.error(format("There are no blames in my database " "for %s.", channel)) return text = self._replaceFirstPerson(blame.text, msg.nick) reason = self._replaceFirstPerson(reason, msg.nick) target = self._replaceFirstPerson(target, msg.nick) text = text.replace("$who", target).replace("$WHO", target.upper()) if reason: text += " for " + reason if self.registryValue("showIds", channel): text += format(" (#%i)", blame.id) # changed action to False -- gsf 2007-07-25 irc.reply(text, action=False)
def add(self, irc, msg, args, user, capability): """<name|hostmask> <capability> Gives the user specified by <name> (or the user to whom <hostmask> currently maps) the specified capability <capability> """ # Ok, the concepts that are important with capabilities: # ### 1) No user should be able to elevate their privilege to owner. ### 2) Admin users are *not* superior to #channel.ops, and don't ### have God-like powers over channels. ### 3) We assume that Admin users are two things: non-malicious and ### and greedy for power. So they'll try to elevate their ### privilege to owner, but they won't try to crash the bot for ### no reason. # Thus, the owner capability can't be given in the bot. Admin # users can only give out capabilities they have themselves (which # will depend on supybot.capabilities and its child default) but # generally means they can't mess with channel capabilities. if ircutils.strEqual(capability, 'owner'): irc.error(_('The "owner" capability can\'t be added in the ' 'bot. Use the supybot-adduser program (or edit the ' 'users.conf file yourself) to add an owner ' 'capability.')) return if ircdb.isAntiCapability(capability) or \ ircdb.checkCapability(msg.prefix, capability): user.addCapability(capability) ircdb.users.setUser(user) irc.replySuccess() else: irc.error(_('You can\'t add capabilities you don\'t have.'))
def greeter(self, irc, msg, args): """ (add|remove) nick1 [nick2 nick3...] This plugin will issue a greeting via privmsg for the first time someone joins a channel. Doing greeter add foobar causes that nick to be added to the list of nicks to ignore. Remove command removes them from the list of nicks to ignore. If called without arguments, will send the caller the introduction message via privmsg, regardless of whether they've already been greeted. """ channel = msg.args[0] # apparently having remove and add in their own defs # makes then "available" as their own plugins. IE # @remove and @add, don't want that, so having the # @greeter part do the add/remove via private methods if len(args) == 0: if ircutils.strEqual(irc.nick, msg.nick): return # It's us irc.queueMsg(ircmsgs.privmsg(msg.nick, joinmsg % ( irc.nick ) )) irc.noReply() else: # should see if there's a way to trigger help message irc.reply(" I don't understand what you are asking ")
def doJoin(self, irc, msg): #irc.reply("hello") if ircutils.strEqual(irc.nick, msg.nick): return # It's us channel = msg.args[0] if channel != "#code4lib" and channel not in test_channels: return #if self.db[channel, msg.nick] is None: try: self.db.get(channel, msg.nick) except KeyError: # The except means that we only message people not yet in the db. irc.queueMsg(ircmsgs.privmsg(msg.nick, joinmsg % ( irc.nick ) )) irc.noReply() #self.db.add(channel, msg.nick) self.db.add(channel, msg.nick) # Also notify the helpers privately if a potential newbie shows up, # so that we can roll out the welcome mat human-style. for helper in self._get_helpers(channel): # Sometimes the helpers db stores blank lines, which we should # ignore. if helper: irc.queueMsg(ircmsgs.privmsg(helper, helpermsg % ( msg.nick ) )) irc.noReply()
def grab(self, irc, msg, args, channel, nick): """[<channel>] <nick> Grabs a quote from <channel> by <nick> for the quotegrabs table. <channel> is only necessary if the message isn't sent in the channel itself. """ # chan is used to make sure we know where to grab the quote from, as # opposed to channel which is used to determine which db to store the # quote in chan = msg.args[0] if chan is None or not irc.isChannel(chan): raise callbacks.ArgumentError if ircutils.nickEqual(nick, msg.nick): irc.error(_('You can\'t quote grab yourself.'), Raise=True) if conf.supybot.protocols.irc.experimentalExtensions(): msgid = msg.server_tags.get('+draft/reply') else: msgid = None for m in reversed(irc.state.history): if msgid and m.server_tags.get('msgid') != msgid: continue if m.command == 'PRIVMSG' and ircutils.nickEqual(m.nick, nick) \ and ircutils.strEqual(m.args[0], chan): # TODO: strip statusmsg prefix for comparison? Must be careful # abouk leaks, though. self._grab(channel, irc, m, msg.prefix) irc.replySuccess() return irc.error(_('I couldn\'t find a proper message to grab.'))
def _replacer_process(self, irc, msg, target, pattern, replacement, count, messages): for m in messages: if m.command in ('PRIVMSG', 'NOTICE') and \ ircutils.strEqual(m.args[0], msg.args[0]) and m.tagged('receivedBy') == irc: if target and m.nick != target: continue # Don't snarf ignored users' messages unless specifically # told to. if ircdb.checkIgnored(m.prefix) and not target: continue # When running substitutions, ignore the "* nick" part of any actions. action = ircmsgs.isAction(m) if action: text = ircmsgs.unAction(m) else: text = m.args[1] # Test messages sent before SedRegex was activated. Mark them all as seen # so we only need to do this check once per message. if not m.tagged(TAG_SEEN): m.tag(TAG_SEEN) if SED_REGEX.match(m.args[1]): m.tag(TAG_IS_REGEX) # Ignore messages containing a regexp if ignoreRegex is on. if self.registryValue('ignoreRegex', msg.channel, irc.network) and m.tagged(TAG_IS_REGEX): self.log.debug( "Skipping message %s because it is tagged as isRegex", m.args[1]) continue if m.nick == msg.nick: messageprefix = msg.nick else: messageprefix = '%s thinks %s' % (msg.nick, m.nick) try: replace_result = pattern.search(text) if replace_result: if self.registryValue('boldReplacementText', msg.channel, irc.network): replacement = ircutils.bold(replacement) subst = pattern.sub(replacement, text, count) if action: # If the message was an ACTION, prepend the nick back. subst = '* %s %s' % (m.nick, subst) subst = axe_spaces(subst) return _("%s meant to say: %s") % \ (messageprefix, subst) except Exception as e: self.log.warning(_("SedRegex error: %s"), e, exc_info=True) raise self.log.debug( _("SedRegex: Search %r not found in the last %i messages of %s."), msg.args[1], len(irc.state.history), msg.args[0]) raise SearchNotFoundError()
def stats(self, irc, msg, args, channel, name): """[<channel>] [<name>] Returns the statistics for <name> on <channel>. <channel> is only necessary if the message isn't sent on the channel itself. If <name> isn't given, it defaults to the user sending the command. """ if msg.nick not in irc.state.channels[channel].users: irc.error(format("You must be in %s to use this command.", channel)) return if name and ircutils.strEqual(name, irc.nick): id = 0 elif not name: try: id = ircdb.users.getUserId(msg.prefix) name = ircdb.users.getUser(id).name except KeyError: irc.error(_("I couldn't find you in my user database.")) return elif not ircdb.users.hasUser(name): try: hostmask = irc.state.nickToHostmask(name) id = ircdb.users.getUserId(hostmask) except KeyError: irc.errorNoUser() return else: id = ircdb.users.getUserId(name) try: stats = self.db.getUserStats(channel, id) s = format( _( "%s has sent %n; a total of %n, %n, " "%n, and %n; %s of those messages %s. " "%s has joined %n, parted %n, quit %n, " "kicked someone %n, been kicked %n, " "changed the topic %n, and changed the " "mode %n." ), name, (stats.msgs, "message"), (stats.chars, _("character")), (stats.words, _("word")), (stats.smileys, _("smiley")), (stats.frowns, _("frown")), stats.actions, stats.actions == 1 and _("was an ACTION") or _("were ACTIONs"), name, (stats.joins, _("time")), (stats.parts, _("time")), (stats.quits, _("time")), (stats.kicks, _("time")), (stats.kicked, _("time")), (stats.topics, _("time")), (stats.modes, _("time")), ) irc.reply(s) except KeyError: irc.error(format(_("I have no stats for that %s in %s."), name, channel))
def isOwner(self, irc, channel, hostmask): if ircdb.checkCapability(hostmask, "owner"): return True if ircutils.strEqual(hostmask, irc.prefix): return True return False
def doPart(self, irc, msg): """Kill the authentication when user parts channel.""" channels = self.registryValue('channels').split(';') if msg.args[0] in channels and irc.network == self.registryValue('network'): if ircutils.strEqual(msg.nick, irc.nick): #we're parting self.authed_users.clear() else: self._unauth(msg.prefix)
def outFilter(self, irc, msg): try: if msg.command == 'QUIT' and ircutils.strEqual(msg.nick, irc.nick): irc.state._operup_tried_oper = False except: self.log.exception('OperUp: caught error from outFilter on %s', irc.name) finally: return msg
def add(self, irc, msg, args, user): """<user> adds user to parrot list""" if ircutils.strEqual(user, irc.nick): irc.reply('No, I will not parrot myself.') return self._targets.add(user) irc.replySuccess()
def doMode(self, irc, msg): if self.disabled(irc): return chanserv = self.registryValue("ChanServ") on = "on %s" % irc.network if ircutils.strEqual(msg.nick, chanserv): channel = msg.args[0] if len(msg.args) == 3: if ircutils.strEqual(msg.args[2], irc.nick): mode = msg.args[1] info = self.log.info if mode == "+o": info("Received op from ChanServ in %s %s.", channel, on) elif mode == "+h": info("Received halfop from ChanServ in %s %s.", channel, on) elif mode == "+v": info("Received voice from ChanServ in %s %s.", channel, on)
def stats(self, irc, msg, args, channel, name): """[<channel>] [<name>] Returns the statistics for <name> on <channel>. <channel> is only necessary if the message isn't sent on the channel itself. If <name> isn't given, it defaults to the user sending the command. """ if channel != '#': # Skip this check if databases.plugins.channelspecific is False. if msg.nick not in irc.state.channels[channel].users: irc.error(format('You must be in %s to use this command.', channel)) return if name and ircutils.strEqual(name, irc.nick): id = 0 elif not name: try: id = ircdb.users.getUserId(msg.prefix) name = ircdb.users.getUser(id).name except KeyError: irc.error(_('I couldn\'t find you in my user database.')) return elif not ircdb.users.hasUser(name): try: hostmask = irc.state.nickToHostmask(name) id = ircdb.users.getUserId(hostmask) except KeyError: irc.errorNoUser() return else: id = ircdb.users.getUserId(name) try: stats = self.db.getUserStats(channel, id) s = format(_('%s has sent %n; a total of %n, %n, ' '%n, and %n; %s of those messages %s. ' '%s has joined %n, parted %n, quit %n, ' 'kicked someone %n, been kicked %n, ' 'changed the topic %n, and changed the ' 'mode %n.'), name, (stats.msgs, 'message'), (stats.chars, _('character')), (stats.words, _('word')), (stats.smileys, _('smiley')), (stats.frowns, _('frown')), stats.actions, stats.actions == 1 and _('was an ACTION') or _('were ACTIONs'), name, (stats.joins, _('time')), (stats.parts, _('time')), (stats.quits, _('time')), (stats.kicks, _('time')), (stats.kicked, _('time')), (stats.topics, _('time')), (stats.modes, _('time'))) irc.reply(s) except KeyError: irc.error(format(_('I have no stats for that %s in %s.'), name, channel))
def since(self, irc, msg, args, channel, nick): """[<channel>] [<nick>] Returns the messages since <nick> last left the channel. If <nick> is not given, it defaults to the nickname of the person calling the command. """ if nick is None: nick = msg.nick if channel not in irc.state.channels: irc.error(_('I am not in %s.') % channel) return if nick not in irc.state.channels[channel].users: irc.error( format(_('%s must be in %s to use this command.'), ('You' if nick == msg.nick else nick), channel)) return if nick is None: nick = msg.nick end = None # By default, up until the most recent message. for (i, m) in utils.seq.renumerate(irc.state.history): if end is None and m.command == 'JOIN' and \ ircutils.strEqual(m.args[0], channel) and \ ircutils.strEqual(m.nick, nick): end = i if m.command == 'PART' and \ ircutils.strEqual(m.nick, nick) and \ ircutils.strEqual(m.args[0], channel): break elif m.command == 'QUIT' and ircutils.strEqual(m.nick, nick): # XXX We assume the person was in-channel at this point. break elif m.command == 'KICK' and \ ircutils.strEqual(m.args[1], nick) and \ ircutils.strEqual(m.args[0], channel): break else: # I never use this; it only kicks in when the for loop exited normally. irc.error( format( _('I couldn\'t find in my history of %s messages ' 'where %r last left %s'), len(irc.state.history), nick, channel)) return msgs = [ m for m in irc.state.history[i:end] if m.command == 'PRIVMSG' and ircutils.strEqual(m.args[0], channel) ] if msgs: irc.reply(format('%L', list(map(ircmsgs.prettyPrint, msgs)))) else: irc.reply( format( _('Either %s didn\'t leave, ' 'or no messages were sent while %s was gone.'), nick, nick))
def isProtected(self, irc, channel, hostmask): cap = ircdb.makeChannelCapability(channel, 'protected') if ircdb.checkCapability(hostmask, cap): self.log.debug('%s is protected on %s, it has %s.', hostmask, channel, cap) return True if ircutils.strEqual(hostmask, irc.prefix): return True return False
def _doKarma(self, irc, channel, thing): assert thing[-2:] in ('++', '--') if thing.endswith('++'): thing = thing[:-2] if ircutils.strEqual(thing, irc.msg.nick) and \ not self.registryValue('allowSelfRating', channel): irc.error('You\'re not allowed to adjust your own karma.') elif thing: self.db.increment(channel, self._normalizeThing(thing)) self._respond(irc, channel) else: thing = thing[:-2] if ircutils.strEqual(thing, irc.msg.nick) and \ not self.registryValue('allowSelfRating', channel): irc.error('You\'re not allowed to adjust your own karma.') elif thing: self.db.decrement(channel, self._normalizeThing(thing)) self._respond(irc, channel)
def doMode(self, irc, msg): chanserv = self.registryValue('ChanServ') on = 'on %s' % irc.network if ircutils.strEqual(msg.nick, chanserv): channel = msg.args[0] if len(msg.args) == 3: if ircutils.strEqual(msg.args[2], irc.nick): mode = msg.args[1] info = self.log.info if mode == '+o': info('Received op from ChanServ in %s %s.', channel, on) elif mode == '+h': info('Received halfop from ChanServ in %s %s.', channel, on) elif mode == '+v': info('Received voice from ChanServ in %s %s.', channel, on)
def __call__(self, irc, msg): if irc.afterConnect: nick = self._getNick() if nick and not ircutils.strEqual(nick, irc.nick): # We used to check this, but nicksToHostmasks is never cleared # except on reconnects, which can cause trouble. # if nick not in irc.state.nicksToHostmasks: self._ison(irc, nick) self.__parent.__call__(irc, msg)
def __call__(self, irc, msg): if irc.afterConnect: nick = self._getNick(irc.network) if nick and not ircutils.strEqual(nick, irc.nick): # We used to check this, but nicksToHostmasks is never cleared # except on reconnects, which can cause trouble. # if nick not in irc.state.nicksToHostmasks: self._ison(irc, nick) self.__parent.__call__(irc, msg)
def isImmune(self, irc, msg): if not ircutils.isUserHostmask(msg.prefix): self.log.debug('%q is immune, it\'s a server.', msg) return True # It's a server prefix. if ircutils.strEqual(msg.nick, irc.nick): self.log.debug('%q is immune, it\'s me.', msg) return True # It's the bot itself. if msg.nick in self.registryValue('immune', msg.channel, irc.network): self.log.debug('%q is immune, it\'s configured to be immune.', msg) return True return False