Ejemplo n.º 1
0
 def process(self, msg, sender):
     user = fb_user.fb_user(self, sender)
     if not user.is_valid():
         if "@" not in self.host:
             self.on_servermsg(msg)
         return False
         
     nickname = user.info("lastnick")
     message = string.join(msg[3:], " ")[1:]
     
     if msg[1] == "PRIVMSG":
         channel = msg[2]
         self.on_privmsg(message, channel, user)
     elif msg[1] == "NOTICE":
         self.on_notice(message, user)
     elif msg[1] == "NICK":
         self.on_nick(msg[2][1:], user)
     elif msg[1] == "JOIN":
         channel = msg[2]
         self.on_join(channel, user)
     elif msg[1] == "PART":
         channel = msg[2]
         self.on_part(message, channel, user)
     elif msg[1] == "KICK":
         channel = msg[2]
         self.on_kick(msg[3] + " " + string.join(msg[4:], " ")[1:], channel, user)
     elif msg[1] == "QUIT":
         self.on_quit(string.join(msg[2:], " ")[1:], user)
     elif msg[1] == "TOPIC":
         channel = msg[2]
         self.on_topic(message, channel, user)
     elif self.debugmode == "verbose":
         self.debug("Unrecognized command %s from %s" % (msg[1], nickname))
Ejemplo n.º 2
0
    def lines(self, message, channel, user):
        if len(message.split(" ")) < 2:
          self.irc.sendMsg(channel, "BUT WHO")
          return True

        nickname = message.split(" ")[1]
        userid = self.get_id_for_nickname(nickname)
        user = fb_user.fb_user(self.irc, userid)
        lines = float(self.db.execute("SELECT COUNT(*) FROM log WHERE userid = ? AND channel = ? AND type = 'text'", (user.get_id(), channel)).fetchone()[0])
        maxlines = float(self.db.execute("SELECT COUNT(*) AS lines FROM log WHERE channel = ? AND type = 'text' GROUP BY userid ORDER BY lines DESC LIMIT 1", (channel,)).fetchone()[0])
        rank = ('pretty terrible!', 'quite bad!!', 'despicable!!!', 'unfathomable!!!!', 'embarassing!!!!!', 'getting there!!!!!!', 'not bad!!!!!!!', 'pretty cool!!!!!!!!', 'kinda awesome!!!!!!!!!', 'le boss!!!!!!!!!!')[int(math.ceil((lines / maxlines) * 10))-1]
        self.irc.sendMsg(channel, "%s has %i lines!!! %s" % (user.info("lastnick"), lines, rank))
        return True
Ejemplo n.º 3
0
    def seen(self, message, channel, user):
        return False
        params = message.split(" ")
        
        if len(params) < 2:
            return True
        nickname = params[1]
        
        userid = self.get_id_for_nickname(nickname)
        
        if not userid:
            self.irc.sendMsg(channel, "%s ain't no user I ever heard of" % nickname)
            return True
        else:
            user = fb_user.fb_user(self.irc, userid)
            
        if len(params) > 2 and string.lower(params[2]) in ("text", "join", "quit", "kick", "topic", "part"):
            clause = "AND type LIKE '" + params[2] + "' "
            what = "that"
        else:
            clause = ""
            what = "something"

        try:
            last = self.db.execute("SELECT *, rowid FROM log WHERE userid = ? AND channel = ? " + clause + "ORDER BY time DESC LIMIT 1", (user.get_id(), channel)).fetchone()
            if last[1] == "text":
                message = "saying '%s' in %s" % (last[4], last[3])
            elif last[1] == "JOIN":
                message = "join %s" % last[3]
            elif last[1] == "QUIT":
                message = "quit with message '%s'" % last[4]
            elif last[1] == "KICK":
                message = "getting kicked"
            elif last[1] == "TOPIC":
                message = "setting %s's topic to '%s'" % (last[3], last[4])
            elif last[1] == "PART":
                message = "parting %s" % last[3]
            timestamp = time.gmtime(last[2])
            timestamp = time.strftime("%d %b %Y, %H:%M", timestamp)
            self.irc.sendMsg(channel, "Last saw %s %s on %s" % (user.info("lastnick"), message, timestamp))
        except:
            self.irc.sendMsg(channel, "I've heard of %s, but never actually saw them doing %s..." % (user.info("lastnick"), what))
        
        return True
Ejemplo n.º 4
0
    def on_servermsg(self, msg):
        msgcode = msg[1]
        if msgcode == "376": #logon
            f = open("login")
            details = f.readlines()
            f.close()
            self.sendCmd("PRIVMSG [email protected] :AUTH %s %s" % (string.strip(details[0]), string.strip(details[1])))

        elif msgcode == "311": #whois reply
            hostmask = "%s!%s@%s" % (msg[3], msg[4], msg[5])
            usertest = fb_user.fb_user(self, hostmask)

        elif msgcode == "353": #NAMES reply
            nicknames = msg[5:]
            for nickname in nicknames:
                nickname = nickname.replace("@", "").replace("+", "")
                self.sendCmd("WHOIS %s" % nickname)
                
        elif msgcode == "433": #nickname already in use
            self.sendCmd("NICK :%s" % self.altnickname)
            self.nickname = self.altnickname
Ejemplo n.º 5
0
    def stats(self, message, channel, user):
        if message[7:] == "lines":
            lines = self.db.execute("SELECT COUNT(*) FROM log WHERE channel = ? AND type = 'text'", (channel,)).fetchone()[0]
            self.irc.sendMsg(channel, "%i lines on this channel." % lines)
        elif message[7:10] == "top":
            params = message.split(" ")
            try:
                limit = int(re.sub(r'[^0-9+]', "", params[1]))
            except ValueError:
                limit = 10

            if limit <= 0:
                limit = 10
            top10 = self.db.execute("SELECT userid, COUNT(*) AS lines FROM log WHERE channel = ? AND type = 'text' GROUP BY userid HAVING lines > 0 ORDER BY lines DESC LIMIT %s" % limit, (channel,)).fetchall()
            index = 0
            response = ""
            for row in top10:
                user = fb_user.fb_user(self.irc, row[0])
                index += 1
                response += str(index) + ". " + user.info("lastnick") + ": " + str(row[1]) + " "
            self.irc.sendMsg(channel, response)
        return True