def _on_message(self, _, msg):
        """Sends and receives data to the callback function."""
        result = json.loads(msg)
        if result["cmd"] == "chat":
            data = {"type": "message", "nick": result["nick"],
                    "text": result["text"]}
            if "trip" in result:
                data["trip"] = result["trip"]
            self._callback(self, data)
        elif result["cmd"] == "onlineSet":
            self._onlineUsers += result["nicks"]
        elif result["cmd"] == "onlineAdd":
            self._onlineUsers.append(result["nick"])
            self._callback(self, {"type": "online add",
                                 "nick": result["nick"]})
        elif result["cmd"] == "onlineRemove":
            self._onlineUsers.remove(result["nick"])
            self._callback(self, {"type": "online remove",
                                 "nick": result["nick"]})
        elif result["cmd"] == "info" and " invited " in result["text"]:
            if "You invited " in result["text"]:
                name = self._nick
            else:
                space = re.search(r"\s", result["text"])
                name = result["text"][:space.start()]
            link = re.search(r"\?", result["text"])
            channel = result["text"][link.end():]
            self._callback(self, {"type": "invite", "nick": name,
                                 "channel": channel})
        elif result["cmd"] == "info" and " IPs " in result["text"]:
            data = result["text"].split()
            self._callback(self, {"type": "stats", "IPs": data[0],
                                 "channels": data[4]})
        elif result["cmd"] == "info" and "Banned " in result["text"]:
            nick = result["text"][len("Banned "):]
            self._callback(self, {"type": "banned", "nick": nick})
        elif result["cmd"] == "info" and "Unbanned " in result["text"]:
            ip = result["text"][len("Unbanned "):]
            self._callback(self, {"type": "unbanned", "ip": ip})
        elif (result["cmd"] == "info"
              and "Server broadcast: " in result["text"]):
            txt = result["text"][len("Server broadcast: "):]
            self._callback(self, {"type": "broadcast", "text": txt})
        elif result["cmd"] == "info":
            self._callback(self, {"type": "list users",
                                 "text": result["text"]})
        elif result["cmd"] == "warn":
            data = {"type": "warn", "warning": result["text"]}
            if "Could not find " in result["text"]:
                data["warning"] = "user to ban not found"
                data["nick"] = result["text"][len("Could not find "):]
            self._callback(self, data)
def _on_message ( self , _ , msg ) : result = json . loads ( msg ) if result [ "cmd" ] == "chat" : data = { "type" : "message" , "nick" : result [ "nick" ] , "text" : result [ "text" ] } if "trip" in result : data [ "trip" ] = result [ "trip" ] self . _callback ( self , data ) elif result [ "cmd" ] == "onlineSet" : self . _onlineUsers += result [ "nicks" ] elif result [ "cmd" ] == "onlineAdd" : self . _onlineUsers . append ( result [ "nick" ] ) self . _callback ( self , { "type" : "online add" , "nick" : result [ "nick" ] } ) elif result [ "cmd" ] == "onlineRemove" : self . _onlineUsers . remove ( result [ "nick" ] ) self . _callback ( self , { "type" : "online remove" , "nick" : result [ "nick" ] } ) elif result [ "cmd" ] == "info" and " invited " in result [ "text" ] : if "You invited " in result [ "text" ] : name = self . _nick else : space = re . search ( r"\s" , result [ "text" ] ) name = result [ "text" ] [ : space . start ( ) ] link = re . search ( r"\?" , result [ "text" ] ) channel = result [ "text" ] [ link . end ( ) : ] self . _callback ( self , { "type" : "invite" , "nick" : name , "channel" : channel } ) elif result [ "cmd" ] == "info" and " IPs " in result [ "text" ] : data = result [ "text" ] . split ( ) self . _callback ( self , { "type" : "stats" , "IPs" : data [ 0 ] , "channels" : data [ 4 ] } ) elif result [ "cmd" ] == "info" and "Banned " in result [ "text" ] : nick = result [ "text" ] [ len ( "Banned " ) : ] self . _callback ( self , { "type" : "banned" , "nick" : nick } ) elif result [ "cmd" ] == "info" and "Unbanned " in result [ "text" ] : ip = result [ "text" ] [ len ( "Unbanned " ) : ] self . _callback ( self , { "type" : "unbanned" , "ip" : ip } ) elif ( result [ "cmd" ] == "info" and "Server broadcast: " in result [ "text" ] ) : txt = result [ "text" ] [ len ( "Server broadcast: " ) : ] self . _callback ( self , { "type" : "broadcast" , "text" : txt } ) elif result [ "cmd" ] == "info" : self . _callback ( self , { "type" : "list users" , "text" : result [ "text" ] } ) elif result [ "cmd" ] == "warn" : data = { "type" : "warn" , "warning" : result [ "text" ] } if "Could not find " in result [ "text" ] : data [ "warning" ] = "user to ban not found" data [ "nick" ] = result [ "text" ] [ len ( "Could not find " ) : ] self . _callback ( self , data )
Sends and receives data to the callback function.