def setComment(self, message=""):
        """
        set user comment
        """
        if not self._session:
            self._log("can't set comment to %s: no valid session id" % message,
                      1)
            return False

        if not self._established:
            self._log(
                "can't set comment to %s: connection not established" %
                message, 1)
            return False

        if len(message) > 128:
            # longer comments would require handling RequestBlob messages
            self._log("can't set comment: too long (>128 bytes)", 1)
            return False

        pbMess = pb2.UserState()
        pbMess.session = self._session
        pbMess.comment = message
        pbMess.channel_id = self._channelId
        if not self._sendMessage(pbMess):
            self._log("failed to send comment package", 1)
            return False

        return True
    def _joinChannel(self, channel):
        """
        join a channel by name
        """
        if not self._session:
            self._log("can't join channel: no valid session id", 1)
            return False

        try:
            cid = self._channelIds[channel]
        except:
            self._log("can't join channel " + channel + ": unknown id.", 1)
            return False
        self._log(
            "sending package to join channel " + channel + " (id " + str(cid) +
            ")", 2)

        pbMess = pb2.UserState()
        pbMess.session = self._session
        pbMess.channel_id = cid
        if not self._sendMessage(pbMess):
            self._log("failed to send join package", 1)
            return False

        self._channelId = cid
        self._connectionEstablished()
 def _initConnection(self):
     # send version package.
     pbMess = pb2.Version()
     pbMess.release = "1.2.6"
     pbMess.version = 0x010206  # int32
     pbMess.os = platform.system()
     pbMess.os_version = "mumblebot lol"
     if not self._sendMessage(pbMess):
         raise Exception("couldn't send version package", 0)
     # send auth package.
     pbMess = pb2.Authenticate()
     pbMess.username = self._nickname
     if self._password is not None:
         pbMess.password = self._password
     if not self._sendMessage(pbMess):
         raise Exception("couldn't send auth package", 0)
     # great success.
     return True
 def _sendTextMessageUnsafe(self, message):
     """
     send message as a TextMessage.
     """
     pbMess = pb2.TextMessage()
     pbMess.session.append(self._session)
     pbMess.channel_id.append(self._channelId)
     pbMess.message = message
     self._log("sending text message: " + message, 2)
     return self._sendMessage(pbMess)
 def _pingLoop(self):
     while self._connected:
         pbMess = pb2.Ping()
         if not self._sendMessage(pbMess):
             self._log("failed to send ping message", 1)
         time.sleep(10)