aboutsummaryrefslogtreecommitdiff
path: root/src/utils
diff options
context:
space:
mode:
Diffstat (limited to 'src/utils')
-rw-r--r--src/utils/consts.py32
-rw-r--r--src/utils/irc.py35
2 files changed, 47 insertions, 20 deletions
diff --git a/src/utils/consts.py b/src/utils/consts.py
index d2816509..5d97c045 100644
--- a/src/utils/consts.py
+++ b/src/utils/consts.py
@@ -1,2 +1,34 @@
+import typing
+
BITBOT_HOOKS_MAGIC = "__bitbot_hooks"
BITBOT_EXPORTS_MAGIC = "__bitbot_exports"
+
+class IRCColor(object):
+ def __init__(self, irc: int, ansi: typing.List[int]):
+ self.irc = irc
+ self.ansi = ansi
+
+WHITE = IRCColor(0, [1, 37])
+BLACK = IRCColor(1, [30])
+BLUE = IRCColor(2, [34])
+GREEN = IRCColor(3, [32])
+RED = IRCColor(4, [1, 31])
+BROWN = IRCColor(5, [31])
+PURPLE = IRCColor(6, [35])
+ORANGE = IRCColor(7, [33])
+YELLOW = IRCColor(8, [1, 33])
+LIGHTGREEN = IRCColor(9, [1, 32])
+CYAN = IRCColor(10, [36])
+LIGHTCYAN = IRCColor(11, [1, 36])
+LIGHTBLUE = IRCColor(12, [1, 34])
+PINK = IRCColor(13, [1, 35])
+GREY = IRCColor(14, [1, 30])
+LIGHTGREY = IRCColor(15, [37])
+
+BOLD = "\x02"
+ITALIC = "\x1D"
+UNDERLINE = "\x1F"
+INVERT = "\x16"
+COLOR = "\x03"
+RESET = "\x0F"
+
diff --git a/src/utils/irc.py b/src/utils/irc.py
index 8d3241be..88377f17 100644
--- a/src/utils/irc.py
+++ b/src/utils/irc.py
@@ -1,4 +1,5 @@
import json, string, re, typing
+from src import utils
ASCII_UPPER = string.ascii_uppercase
ASCII_LOWER = string.ascii_lowercase
@@ -117,35 +118,29 @@ def parse_line(line: str) -> IRCLine:
return IRCLine(tags, prefix, command, IRCArgs(args), has_arbitrary)
-COLOR_WHITE, COLOR_BLACK, COLOR_BLUE, COLOR_GREEN = 0, 1, 2, 3
-COLOR_RED, COLOR_BROWN, COLOR_PURPLE, COLOR_ORANGE = 4, 5, 6, 7
-COLOR_YELLOW, COLOR_LIGHTGREEN, COLOR_CYAN, COLOR_LIGHTCYAN = (8, 9,
- 10, 11)
-COLOR_LIGHTBLUE, COLOR_PINK, COLOR_GREY, COLOR_LIGHTGREY = (12, 13,
- 14, 15)
-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)
+REGEX_COLOR = re.compile("%s\d\d(?:,\d\d)?" % utils.consts.COLOR)
-def color(s: str, foreground: int, background: int=None) -> str:
- foreground = str(foreground).zfill(2)
+def color(s: str, foreground: utils.consts.IRCColor,
+ background: utils.consts.IRCColor=None) -> str:
+ foreground_s = str(foreground.irc).zfill(2)
+ background_s = ""
if background:
- background = str(background).zfill(2)
- return "%s%s%s%s%s" % (FONT_COLOR, foreground,
- "" if not background else ",%s" % background, s, FONT_COLOR)
+ background_s = ",%s" % str(background.irc).zfill(2)
+
+ return "%s%s%s%s%s" % (utils.consts.COLOR, foreground_s, background_s, s,
+ utils.consts.COLOR)
def bold(s: str) -> str:
- return "%s%s%s" % (FONT_BOLD, s, FONT_BOLD)
+ return "%s%s%s" % (utils.consts.BOLD, s, utils.consts.BOLD)
def underline(s: str) -> str:
- return "%s%s%s" % (FONT_UNDERLINE, s, FONT_UNDERLINE)
+ return "%s%s%s" % (utils.consts.UNDERLINE, s, utils.consts.UNDERLINE)
def strip_font(s: str) -> str:
- s = s.replace(FONT_BOLD, "")
- s = s.replace(FONT_ITALIC, "")
+ s = s.replace(utils.consts.BOLD, "")
+ s = s.replace(utils.consts.ITALIC, "")
s = REGEX_COLOR.sub("", s)
- s = s.replace(FONT_COLOR, "")
+ s = s.replace(utils.consts.COLOR, "")
return s
OPT_STR = typing.Optional[str]