summaryrefslogtreecommitdiffstats
path: root/Reaktor/IRC
diff options
context:
space:
mode:
authormakefu <github@syntax-fehler.de>2013-04-24 20:44:30 +0200
committermakefu <github@syntax-fehler.de>2013-04-24 20:44:30 +0200
commit7fdb1fca9089f400a7938573cb4398db78c6628d (patch)
tree248d2626a379d931a7b52c30a81384fc11b7dfc7 /Reaktor/IRC
parent9f38a2b96abb3fdc4cce5ef23c791728268b7b6f (diff)
parent57fb05c0512f9c12ff56924cdc0d835f1999754a (diff)
Merge branch 'master' of github.com:krebscode/painload
Diffstat (limited to 'Reaktor/IRC')
-rwxr-xr-xReaktor/IRC/asybot.py8
-rwxr-xr-xReaktor/IRC/index2
-rw-r--r--Reaktor/IRC/translate_colors.py31
3 files changed, 38 insertions, 3 deletions
diff --git a/Reaktor/IRC/asybot.py b/Reaktor/IRC/asybot.py
index df758ed6..2cb533ea 100755
--- a/Reaktor/IRC/asybot.py
+++ b/Reaktor/IRC/asybot.py
@@ -2,7 +2,7 @@
#
# //Reaktor/IRC/asybot.py
#
-
+from translate_colors import translate_colors
def is_executable(x):
import os
return os.path.exists(x) and os.access(x, os.X_OK)
@@ -24,6 +24,9 @@ formatter = logging.Formatter( '%(filename)s: %(levelname)s: %(message)s')
hdlr.setFormatter(formatter)
log.addHandler(hdlr)
+# s/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]//g -- removes color codes
+
+
class asybot(asychat):
def __init__(self, server, port, nickname, targets, **kwargs):
asychat.__init__(self)
@@ -110,6 +113,7 @@ class asybot(asychat):
def PRIVMSG(text):
for line in self.wrapper.wrap(text):
msg = 'PRIVMSG %s :%s' % (','.join(params), line)
+ log.info(msg)
self.push(msg)
sleep(1)
@@ -151,7 +155,7 @@ class asybot(asychat):
return
pid = p.pid
for line in iter(p.stdout.readline,""):
- PRIVMSG(line)
+ PRIVMSG(translate_colors(line))
log.debug('%s stdout: %s' % (pid, line))
p.wait()
elapsed = time() - start
diff --git a/Reaktor/IRC/index b/Reaktor/IRC/index
index 50022ec9..cc2652fe 100755
--- a/Reaktor/IRC/index
+++ b/Reaktor/IRC/index
@@ -3,4 +3,4 @@ set -xeuf
# cd //Reaktor
cd $(dirname $(readlink -f $0))/..
-host=irc.freenode.net target='#krebsco' python IRC/asybot.py "$@"
+host=irc.freenode.net target='#krebs' python IRC/asybot.py "$@"
diff --git a/Reaktor/IRC/translate_colors.py b/Reaktor/IRC/translate_colors.py
new file mode 100644
index 00000000..bd716618
--- /dev/null
+++ b/Reaktor/IRC/translate_colors.py
@@ -0,0 +1,31 @@
+
+
+COLOR_MAP = {
+ "\x1b[0m" : "\x0F", # reset
+ "\x1b[37m" : "\x0300",
+ "\x1b[30m" : "\x0301",
+ "\x1b[34m" : "\x0302",
+ "\x1b[32m" : "\x0303",
+ "\x1b[31m" : "\x0304",
+ "\x1b[33m" : "\x0305",
+ "\x1b[35m" : "\x0306",
+ "\x1b[33m" : "\x0307",
+ "\x1b[33m" : "\x0308",
+ "\x1b[32m" : "\x0309",
+ "\x1b[36m" : "\x0310",
+ "\x1b[36m" : "\x0311",
+ "\x1b[34m" : "\x0312",
+ "\x1b[31m" : "\x0313",
+ "\x1b[30m" : "\x0314",
+ "\x1b[37m" : "\x0315",
+ "\x1b[1m" : "\x02", # bold on
+ "\x1b[22m" : "\x02" # bold off
+ }
+def translate_colors (line):
+ for color,replace in COLOR_MAP.items():
+ line = line.replace(color,replace)
+ return line
+
+if __name__ == "__main__":
+ import sys
+ print (translate_colors(sys.stdin.read()))