示例#1
0
    def listen(self, msg):
        if msg.find("353") != -1:
            self.loggedIn = True
            groups = re.search("353 {0} . {1} :(.*)".format(self.nick, self.channel), msg)
            try:
                for uname in groups.group(1).split():
                    uname = uname.strip(':+@')
                    if uname.isalpha():
                        self.clients.append(uname)
            except:
                pass
            print(self.clients)

        if self.loggedIn:
            # XXX should we strip the preceding channel info here?
            parts = msg.rsplit()
            privmsg = ""
            sender = parts[0]
            sender = sender[1:sender.find("!")]

            if parts[1] == "PRIVMSG":
                privmsg = ' '.join(parts[2:])

                if self.swift:
                    try:
                        self.swift.put("{0} {1}".format(sender, privmsg))
                    except Exception as e:
                        # swift is broken, hangups probably crashed
                        print("Could not write to Swift. Hangouts has likely crashed.", e)
                        self.swift = None

                Bank.operands(msg, privmsg, sender if self.private else self.channel,
                              self.clients, sender, self.donald)

            if parts[1] == "JOIN":
                new = parts[0]
                n_user = new[1:new.find("!")].lower()
                if n_user.isalpha() and n_user != self.nick:
                    self.clients.append(n_user)
                    print("Added client %s (JOIN)" % n_user)

            if parts[1] == ("PART" or "QUIT"):
                old = parts[0]
                o_user = old[1:old.find("!")].lower()
                if o_user.isalpha() and o_user in self.clients and o_user != self.nick:
                    self.clients.remove(o_user)
                    print("Removed client %s from channel list." % o_user)

            if parts[1] == "KICK":
                kicked_user = parts[3].lower()
                if kicked_user.isalpha() and kicked_user in self.clients and kicked_user != self.nick:
                    self.clients.remove(kicked_user)
                    print("Removed client %s from channel list. (KICKED)" % kicked_user)