2019-02-09 17:52:51 +00:00
|
|
|
import re
|
2019-02-09 17:49:01 +00:00
|
|
|
from src import utils
|
|
|
|
|
2019-02-10 20:49:59 +00:00
|
|
|
STR_MORE = " (more...)"
|
2019-02-09 17:50:40 +00:00
|
|
|
STR_CONTINUED = "(...continued) "
|
|
|
|
|
2019-02-09 17:49:01 +00:00
|
|
|
class Out(object):
|
|
|
|
def __init__(self, server, module_name, target, msgid, statusmsg):
|
|
|
|
self.server = server
|
|
|
|
self.module_name = module_name
|
|
|
|
self._hide_prefix = False
|
|
|
|
self.target = target
|
|
|
|
self._text = ""
|
|
|
|
self.written = False
|
|
|
|
self._msgid = msgid
|
|
|
|
self._statusmsg = statusmsg
|
|
|
|
|
|
|
|
def write(self, text):
|
|
|
|
self._text += text
|
|
|
|
self.written = True
|
|
|
|
return self
|
|
|
|
|
|
|
|
def send(self, method):
|
|
|
|
if self.has_text():
|
|
|
|
tags = {}
|
|
|
|
if self._msgid:
|
|
|
|
tags["+draft/reply"] = self._msgid
|
|
|
|
|
|
|
|
prefix = ""
|
|
|
|
if not self._hide_prefix:
|
|
|
|
prefix = utils.consts.RESET + "[%s] " % self.prefix()
|
|
|
|
|
|
|
|
target_str = "%s%s" % (self._statusmsg, self.target.name)
|
2019-02-10 20:49:59 +00:00
|
|
|
full_text = "%s%s" % (prefix, self._text)
|
2019-02-09 17:49:01 +00:00
|
|
|
if method == "PRIVMSG":
|
2019-02-10 20:49:59 +00:00
|
|
|
line = self.server.send_message(target_str, full_text,
|
|
|
|
tags=tags)
|
2019-02-09 17:49:01 +00:00
|
|
|
elif method == "NOTICE":
|
2019-02-10 20:49:59 +00:00
|
|
|
line = self.server.send_notice(target_str, full_text, tags=tags)
|
|
|
|
else:
|
2019-04-30 21:45:37 +00:00
|
|
|
raise ValueError("Unknown command method '%s'" % method)
|
2019-02-10 20:49:59 +00:00
|
|
|
|
2019-02-23 21:33:04 +00:00
|
|
|
line.truncate_marker = STR_MORE
|
2019-02-10 20:49:59 +00:00
|
|
|
if line.truncated():
|
|
|
|
self._text = "%s%s" % (STR_CONTINUED, line.truncated())
|
2019-02-22 17:47:25 +00:00
|
|
|
else:
|
|
|
|
self._text = ""
|
2019-02-09 17:49:01 +00:00
|
|
|
|
|
|
|
def set_prefix(self, prefix):
|
|
|
|
self.module_name = prefix
|
|
|
|
def hide_prefix(self):
|
|
|
|
self._hide_prefix = True
|
|
|
|
|
|
|
|
def has_text(self):
|
|
|
|
return bool(self._text)
|
|
|
|
|
|
|
|
class StdOut(Out):
|
|
|
|
def prefix(self):
|
|
|
|
return utils.irc.color(self.module_name, utils.consts.GREEN)
|
|
|
|
class StdErr(Out):
|
|
|
|
def prefix(self):
|
2019-04-30 21:45:52 +00:00
|
|
|
return utils.irc.color(self.module_name, utils.consts.RED)
|
2019-02-09 17:49:01 +00:00
|
|
|
|