aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar jesopo2018-09-30 20:12:11 +0100
committerGravatar jesopo2018-09-30 20:12:11 +0100
commit43740d40f42f15abd45da4be3d55c6dd40897342 (patch)
tree28cdae525c2dad144661b7a408e2d4f492e1d364 /src
parentMove src/IRCLineHandler.py to modules/line_handler.py (diff)
signature
Add modules/strip_color.py
Diffstat (limited to 'src')
-rw-r--r--src/IRCServer.py10
-rw-r--r--src/Utils.py8
2 files changed, 15 insertions, 3 deletions
diff --git a/src/IRCServer.py b/src/IRCServer.py
index 4e4281fb..a45da3fb 100644
--- a/src/IRCServer.py
+++ b/src/IRCServer.py
@@ -250,12 +250,16 @@ class Server(object):
return self.until_read_timeout == 0
def send(self, data):
- encoded = data.split("\n")[0].strip("\r").encode("utf8")
+ returned = self.events.on("preprocess.send").call_for_result(
+ server=self, line=data)
+ line = returned or data
+
+ encoded = line.split("\n")[0].strip("\r").encode("utf8")
if len(encoded) > 450:
encoded = encoded[:450]
self.buffered_lines.append(encoded + b"\r\n")
- if self.bot.args.verbose:
- self.bot.log.info(">%s | %s", [str(self), encoded.decode("utf8")])
+
+ self.bot.log.debug(">%s | %s", [str(self), encoded.decode("utf8")])
def _send(self):
if not len(self.write_buffer):
self.write_buffer = self.buffered_lines.pop(0)
diff --git a/src/Utils.py b/src/Utils.py
index e87330c2..ebf82f82 100644
--- a/src/Utils.py
+++ b/src/Utils.py
@@ -155,6 +155,7 @@ COLOR_LIGHTBLUE, COLOR_PINK, COLOR_GREY, COLOR_LIGHTGREY = (12, 13,
FONT_BOLD, FONT_ITALIC, FONT_UNDERLINE, FONT_INVERT = ("\x02", "\x1D",
"\x1F", "\x16")
FONT_COLOR, FONT_RESET = "\x03", "\x0F"
+REGEX_COLOR = re.compile("%s\d\d(?:,\d\d)?" % FONT_COLOR)
def color(s, foreground, background=None):
foreground = str(foreground).zfill(2)
@@ -169,6 +170,13 @@ def bold(s):
def underline(s):
return "%s%s%s" % (FONT_UNDERLINE, s, FONT_UNDERLINE)
+def strip_font(s):
+ s = s.replace(FONT_BOLD, "")
+ s = s.replace(FONT_ITALIC, "")
+ s = REGEX_COLOR.sub("", s)
+ s = s.replace(FONT_COLOR, "")
+ return s
+
TIME_SECOND = 1
TIME_MINUTE = TIME_SECOND*60
TIME_HOUR = TIME_MINUTE*60