Example #1
0
    def send(self, method):
        if self.has_text():
            prefix = ""
            if not self._hide_prefix:
                prefix = utils.consts.RESET + "[%s] " % self._prefix

            text = self._text[:].replace("\r", "")
            while "\n\n" in text:
                text = text.replace("\n\n", "\n")

            full_text = "%s%s" % (prefix, text)
            message_factory = _message_factory(method)

            line = message_factory(self._target_str,
                                   full_text,
                                   tags=self._tags)
            if self._assured:
                line.assure()

            valid, truncated = line.truncate(self.server.hostmask(),
                                             margin=STR_MORE_LEN)

            if truncated:
                valid, truncated = self._adjust_to_word_boundaries(
                    valid, truncated)

                line = IRCLine.parse_line(valid + STR_MORE)
                self._text = "%s%s" % (STR_CONTINUED, truncated)
            else:
                self._text = ""

            sent_line = self.server.send(line)
Example #2
0
    def _out(self, server, target, target_str, is_channel, obj, type, tags):
        if type == OutType.OUT:
            color = utils.consts.GREEN
        else:
            color = utils.consts.RED

        line_str = obj.pop()
        if obj.prefix:
            line_str = "[%s] %s" % (utils.irc.color(obj.prefix,
                                                    color), line_str)
        method = self._command_method(server, target, is_channel)

        if not method in ["PRIVMSG", "NOTICE"]:
            raise ValueError("Unknown command-method '%s'" % method)

        line = IRCLine.ParsedLine(method, [target_str, line_str], tags=tags)
        valid, trunc = line.truncate(server.hostmask(), margin=STR_MORE_LEN)

        if trunc:
            if not trunc[0] in WORD_BOUNDARIES:
                for boundary in WORD_BOUNDARIES:
                    left, *right = valid.rsplit(boundary, 1)
                    if right:
                        valid = left
                        trunc = right[0] + trunc
            obj.insert("%s %s" % (STR_CONTINUED, trunc))
            valid = valid + STR_MORE
        line = IRCLine.parse_line(valid)
        server.send(line)
Example #3
0
 def _execute(self, server, commands, **kwargs):
     for command in commands:
         line = command.format(**kwargs)
         if IRCLine.is_human(line):
             line = IRCLine.parse_human(line)
         else:
             line = IRCLine.parse_line(line)
         server.send(line)
Example #4
0
    def raw(self, event):
        if IRCLine.is_human(event["spec"][0]):
            line = IRCLine.parse_human(event["spec"][0])
        else:
            line = IRCLine.parse_line(event["spec"][0])
        line = event["server"].send(line)

        if not line == None:
            event["stdout"].write("Sent: %s" % line.parsed_line.format())
        else:
            event["stderr"].write("Line was filtered")
Example #5
0
    def rawctl(self, event):
        rawargs = str(event["data"]).split(" ", 1)
        server = self._server_from_alias(rawargs[0])
        if IRCLine.is_human(rawargs[1]):
            line = IRCLine.parse_human(rawargs[1])
        else:
            line = IRCLine.parse_line(rawargs[1])
        line = server.send(line)

        if not line == None:
            return "Sent: " + line.parsed_line.format()
        else:
            return "Line was filtered"
Example #6
0
    def raw(self, event):
        """
        :help: Send a line of raw IRC data
        :usage: <raw line>
        :permission: raw
        """
        if IRCLine.is_human(event["args"]):
            line = IRCLine.parse_human(event["args"])
        else:
            line = IRCLine.parse_line(event["args"])
        line = event["server"].send(line)

        if not line == None:
            event["stdout"].write("Sent: %s" % line.parsed_line.format())
        else:
            event["stderr"].write("Line was filtered")
Example #7
0
 def send_raw(self, line: str):
     return self.send(IRCLine.parse_line(line))
Example #8
0
 def _post_read(self, lines: typing.List[str]):
     for line in lines:
         self.bot.log.debug("%s (raw recv) | %s", [str(self), line])
         self.events.on("raw.received").call_unsafe(server=self,
             line=IRCLine.parse_line(line))
         self.check_users()