def send_raw(self, string): """Send raw string to the server. The string will be padded with appropriate CR LF. """ # The string should not contain any carriage return other than the # one added here. if "\n" in string: raise InvalidCharacters( "Carriage returns not allowed in privmsg(text)") bytes = string.encode("utf-8") + b"\r\n" # According to the RFC http://tools.ietf.org/html/rfc2812#page-6, # clients should not transmit more than 512 bytes. # However, Twitch have raised that limit to 2048 in their servers. if len(bytes) > 2048: raise MessageTooLong( "Messages limited to 2048 bytes including CR/LF") if self.socket is None: raise ServerNotConnectedError("Not connected.") sender = getattr(self.socket, "write", self.socket.send) try: sender(bytes) except socket.error: # Ouch! self.disconnect("Connection reset by peer.")
def say(self, msg, target=None): if not target: target = self.config['channel'] if type(msg) is bytes: msg = msg.decode('utf-8') if self.is_msg_too_long(msg): if not self.config['wrap_too_long_msgs']: self.logger.debug('privmsg too long, discarding...') raise MessageTooLong(msg) self.logger.debug('privmsg too long, wrapping...') for part in textwrap.wrap(msg, 450): self._say_dispatcher(part, target) else: self._say_dispatcher(msg, target)
def say(self, msg, target=None, force=False): """ send public message to channel or private one to target if specified block until message delivered if force param is true does nothing if msg is None throws MessageTooLong if wrap_too_long_msgs config entry is false and msg is too long """ if not msg: return if not target: target = self.get_channel_name() if type(msg) is bytes: msg = msg.decode('utf-8') if not isinstance(msg, str): msg = str(msg) if self.is_msg_too_long(msg): if not self.config['wrap_too_long_msgs']: self._logger.debug('privmsg too long, discarding...') raise MessageTooLong(msg) self._logger.debug('privmsg too long, wrapping...') for part in textwrap.wrap(msg, 450): self._say_dispatcher(part, target, force) else: self._say_dispatcher(msg, target, force)