def testReplyTo(self): irc = getTestIrc() prefix = 'foo!bar@baz' channel = ircmsgs.privmsg('#foo', 'bar baz', prefix=prefix) private = ircmsgs.privmsg('jemfinch', 'bar baz', prefix=prefix) irc._tagMsg(channel) irc._tagMsg(private) self.assertEqual(ircutils.replyTo(channel), channel.args[0]) self.assertEqual(ircutils.replyTo(private), private.nick)
def inFilter(self, irc, msg): if msg.command == 'PRIVMSG': replyTo = ircutils.replyTo(msg) if replyTo == "geordi" and irc.network == "FreeNode": (me, text) = msg.args self._replyIrc.queueMsg(callbacks.reply(self._replyMsg, text)) return None return msg
def smash(self, irc, msg, args, target): """<target> "Smashes" the target user or inanimate object with an action message. """ text = self.PickRandom(self.smashes) + " " + target irc.queueMsg(ircmsgs.action(ircutils.replyTo(msg), text)) irc.noReply()
def real_find(self, irc, msg, args, package, release): """<package/filename> [<release>] Search for <package> or, of that fails, find <filename>'s package(s). Optionally in <release> """ channel = self.__getChannel(msg.args[0]) reply_target = ircutils.replyTo(msg) (release, rest) = self.__getRelease(irc, release, channel) if not release: return reply = self.Apt.find(package, release) if rest: if rest[0] == '|': try: target = rest while target[0] == '|': target = target[1:].strip() if target.lower() == "me": target = msg.nick queue(irc, reply_target, "%s: %s" % (target, reply)) return except Exception as e: self.log.info("PackageInfo: (find) Exception in pipe: %r" % e) pass elif rest[0] == '>': try: while rest[0] == '>': rest = rest[1:].strip() targets = [_ for _ in rest.split() if _] # Split and discard empty parts target = stripNick( targets[0] ) # Take the first "nick" and strip off bad chars if target.lower() == "me": target = msg.nick # redirect if not target: # Throw error raise Exception('No target') queue(irc, target, "<%s> wants you to know: %s" % (msg.nick, reply)) return except Exception as e: self.log.info( "PackageInfo: (find) Exception in redirect: %r" % e) pass queue(irc, reply_target, reply)
def real_find(self, irc, msg, args, package, release): """<package/filename> [<release>] Search for <package> or, of that fails, find <filename>'s package(s). Optionally in <release> """ channel = self.__getChannel(msg.args[0]) reply_target = ircutils.replyTo(msg) (release, rest) = self.__getRelease(irc, release, channel) if not release: return reply = self.Apt.find(package, release) if rest: if rest[0] == '|': try: target = rest while target[0] == '|': target = target[1:].strip() if target.lower() == "me": target = msg.nick queue(irc, reply_target, "%s: %s" % (target, reply)) return except Exception as e: self.log.info("PackageInfo: (find) Exception in pipe: %r" % e) pass elif rest[0] == '>': try: while rest[0] == '>': rest = rest[1:].strip() targets = [_ for _ in rest.split() if _] # Split and discard empty parts target = stripNick(targets[0]) # Take the first "nick" and strip off bad chars if target.lower() == "me": target = msg.nick # redirect if not target: # Throw error raise Exception('No target') queue(irc, target, "<%s> wants you to know: %s" % (msg.nick, reply)) return except Exception as e: self.log.info("PackageInfo: (find) Exception in redirect: %r" % e) pass queue(irc, reply_target, reply)
def kill(self, irc, msg, args, target): """<target> "Kills" the target user or inanimate object with an action message. """ # check if target is immortal ltarget = target.lower() # make sure we match a whole word for x in self.immortals.keys(): if re.search(r'\b' + x + r'\b', ltarget): irc.reply(self.immortals[x]) return # OK, we can kill them text = self.PickRandom( self.attacks) + " " + target + " with " + self.PickRandom( self.weapons) irc.queueMsg(ircmsgs.action(ircutils.replyTo(msg), text)) irc.noReply()
def summon(self, irc, msg, args, what): """<what> Summons someone or something from who knows where... """ text = self.PickRandom(self.summons) text = text.replace("{what}", what) for i in range(0, 10): # get different words for each replacement text = text.replace("{adjective}", self.PickRandom(self.summonadjectives), 1) text = text.replace("{noun}", self.PickRandom(self.summonnouns), 1) text = text.replace("{verb}", self.PickRandom(self.summonverbs), 1) text = text.replace("{latin}", self.PickRandom(self.summonlatins), 1) text = text.replace("{creature}", self.PickRandom(self.summoncreatures), 1) text = text.replace("{bodypart}", self.PickRandom(self.summonbodyparts), 1) text = text.replace("{stuff}", self.PickRandom(self.summonstuffs), 1) text = text.replace("{place}", self.PickRandom(self.summonplaces), 1) irc.queueMsg(ircmsgs.action(ircutils.replyTo(msg), text)) irc.noReply()
def testReplyTo(self): prefix = 'foo!bar@baz' channel = ircmsgs.privmsg('#foo', 'bar baz', prefix=prefix) private = ircmsgs.privmsg('jemfinch', 'bar baz', prefix=prefix) self.assertEqual(ircutils.replyTo(channel), channel.args[0]) self.assertEqual(ircutils.replyTo(private), private.nick)
def testReplyTo(self): prefix = "foo!bar@baz" channel = ircmsgs.privmsg("#foo", "bar baz", prefix=prefix) private = ircmsgs.privmsg("jemfinch", "bar baz", prefix=prefix) self.assertEqual(ircutils.replyTo(channel), channel.args[0]) self.assertEqual(ircutils.replyTo(private), private.nick)