aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar jesopo2018-11-13 16:02:26 +0000
committerGravatar jesopo2018-11-13 16:02:26 +0000
commit8b9062b942e93db587eb67e98767660c8ec4e482 (patch)
treeb7e52998dacf648038a54617fd9a73e7334df5b2 /src
parentI was accidentally removing two characters from the start of :nick!user@host (diff)
signature
Better constifying of color/font chars
Diffstat (limited to 'src')
-rw-r--r--src/ModuleManager.py6
-rw-r--r--src/utils/consts.py32
-rw-r--r--src/utils/irc.py35
3 files changed, 50 insertions, 23 deletions
diff --git a/src/ModuleManager.py b/src/ModuleManager.py
index cea15118..9dfc85df 100644
--- a/src/ModuleManager.py
+++ b/src/ModuleManager.py
@@ -138,7 +138,7 @@ class ModuleManager(object):
if name in self.waiting_requirement:
for requirement_name in self.waiting_requirement:
self.load_module(bot, requirement_name)
- self.log.info("Module '%s' loaded", [name])
+ self.log.debug("Module '%s' loaded", [name])
def load_modules(self, bot: "IRCBot.Bot", whitelist: typing.List[str]=[],
blacklist: typing.List[str]=[]):
@@ -173,8 +173,8 @@ class ModuleManager(object):
references -= 1 # 'del module' removes one reference
references -= 1 # one of the refs is from getrefcount
- self.log.info("Module '%s' unloaded (%d reference%s)",
+ self.log.debug("Module '%s' unloaded (%d reference%s)",
[name, references, "" if references == 1 else "s"])
if references > 0:
- self.log.info("References left for '%s': %s",
+ self.log.debug("References left for '%s': %s",
[name, ", ".join([str(referrer) for referrer in referrers])])
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]