Ejemplo n.º 1
0
    def privmsg(self, nick, chan, msg):
        try:
            msg = msg.decode('utf-8')
        except UnicodeDecodeError:
            msg = msg.decode('iso-8859-1', 'ignore')
        # display msg, do other stuff
        if len(msg) == 0:
            return
        # silently ignore CTCP
        if msg[0] == '\x01':
            handle = nick[0:nick.find("!")]
            logging.warning("---> recv \"CTCP %s :%s\"" % (handle, msg[1:-1]))
            if msg[1:-1] == "VERSION":
                helpers.ctcp_reply(self.parent.cli, handle, "VERSION",
                                   "Pesterchum %s" % (_pcVersion))
            elif msg[1:-1].startswith("NOQUIRKS") and chan[0] == "#":
                op = nick[0:nick.find("!")]
                self.parent.quirkDisable.emit(chan, msg[10:-1], op)
            return
        handle = nick[0:nick.find("!")]

        if chan != "#pesterchum":
            # We don't need anywhere near that much spam.
            logging.info("---> recv \"PRIVMSG %s :%s\"" % (handle, msg))

        if chan == "#pesterchum":
            # follow instructions
            if msg[0:6] == "MOOD >":
                try:
                    mood = Mood(int(msg[6:]))
                except ValueError:
                    mood = Mood(0)
                self.parent.moodUpdated.emit(handle, mood)
            elif msg[0:7] == "GETMOOD":
                mychumhandle = self.mainwindow.profile().handle
                mymood = self.mainwindow.profile().mood.value()
                if msg.find(mychumhandle, 8) != -1:
                    helpers.msg(self.client, "#pesterchum",
                                "MOOD >%d" % (mymood))
        elif chan[0] == '#':
            if msg[0:16] == "PESTERCHUM:TIME>":
                self.parent.timeCommand.emit(chan, handle, msg[16:])
            else:
                self.parent.memoReceived.emit(chan, handle, msg)
        else:
            # private message
            # silently ignore messages to yourself.
            if handle == self.mainwindow.profile().handle:
                return
            if msg[0:7] == "COLOR >":
                colors = msg[7:].split(",")
                try:
                    colors = [int(d) for d in colors]
                except ValueError:
                    colors = [0, 0, 0]
                color = QtGui.QColor(*colors)
                self.parent.colorUpdated.emit(handle, color)
            else:
                self.parent.messageReceived.emit(handle, msg)
Ejemplo n.º 2
0
 def privmsg(self, nick, chan, msg):
     try:
         msg = msg.decode('utf-8')
     except UnicodeDecodeError:
         msg = msg.decode('iso-8859-1', 'ignore')
     # display msg, do other stuff
     if len(msg) == 0:
         return
     # Notice IRC /me (The CTCP kind)
     if msg[0:8] == '\x01ACTION ':
         msg = '/me' + msg[7:-1]
     # silently ignore the rest of the CTCPs
     if msg[0] == '\x01':
         handle = nick[0:nick.find("!")]
         logging.info("---> recv \"CTCP %s :%s\"" % (handle, msg[1:-1]))
         if msg[1:-1] == "VERSION":
             helpers.ctcp_reply(self.parent.cli, handle, "VERSION", "Pesterchum %s" % (_pcVersion))
         elif msg[1:-1].startswith("NOQUIRKS") and chan[0] == "#":
             op = nick[0:nick.find("!")]
             self.parent.quirkDisable.emit(chan, msg[10:-1], op)
         return
     handle = nick[0:nick.find("!")]
     logging.info("---> recv \"PRIVMSG %s :%s\"" % (handle, msg))
     if chan == "#pesterchum":
         # follow instructions
         if msg[0:6] == "MOOD >":
             try:
                 mood = Mood(int(msg[6:]))
             except ValueError:
                 mood = Mood(0)
             self.parent.moodUpdated.emit(handle, mood)
         elif msg[0:7] == "GETMOOD":
             mychumhandle = self.mainwindow.profile().handle
             mymood = self.mainwindow.profile().mood.value()
             if msg.find(mychumhandle, 8) != -1:
                 helpers.msg(self.client, "#pesterchum",
                             "MOOD >%d" % (mymood))
     elif chan[0] == '#':
         if msg[0:16] == "PESTERCHUM:TIME>":
             self.parent.timeCommand.emit(chan, handle, msg[16:])
         else:
             self.parent.memoReceived.emit(chan, handle, msg)
     else:
         # private message
         # silently ignore messages to yourself.
         if handle == self.mainwindow.profile().handle:
             return
         if msg[0:7] == "COLOR >":
             colors = msg[7:].split(",")
             try:
                 colors = [int(d) for d in colors]
             except ValueError:
                 colors = [0,0,0]
             color = QtGui.QColor(*colors)
             self.parent.colorUpdated.emit(handle, color)
         else:
             self.parent.messageReceived.emit(handle, msg)