aboutsummaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
authorGravatar jesopo2018-09-21 11:38:55 +0100
committerGravatar jesopo2018-09-21 11:39:09 +0100
commita87196c608a237968918d1c21985926850001598 (patch)
tree9327e021f1c1fa6258f5e9a57273bb72706b0ed3 /modules
parentDon't pass around full server details more than we have to. (diff)
Change Utils.color to take a string to wrap in color
Diffstat (limited to 'modules')
-rw-r--r--modules/8ball.py2
-rw-r--r--modules/commands.py6
-rw-r--r--modules/ducks.py11
-rw-r--r--modules/nr.py19
4 files changed, 17 insertions, 21 deletions
diff --git a/modules/8ball.py b/modules/8ball.py
index 9c6e5d1a..710ab448 100644
--- a/modules/8ball.py
+++ b/modules/8ball.py
@@ -19,7 +19,7 @@ CHOICES = [
"It is certain",
"Naturally",
"Reply hazy, try again later",
- Utils.color(4) + Utils.underline("DO NOT WASTE MY TIME"),
+ Utils.underline(Utils.color("DO NOT WASTE MY TIME", Utils.COLOR_RED)),
"Hmm... Could be!",
"I'm leaning towards no",
"Without a doubt",
diff --git a/modules/commands.py b/modules/commands.py
index 1a8b631a..f0068c57 100644
--- a/modules/commands.py
+++ b/modules/commands.py
@@ -37,12 +37,10 @@ class Out(object):
class StdOut(Out):
def prefix(self):
- return "%s%s%s" % (Utils.color(Utils.COLOR_GREEN),
- self.module_name, Utils.FONT_RESET)
+ return Utils.color(Utils.bold(self.module_name), Utils.COLOR_GREEN)
class StdErr(Out):
def prefix(self):
- return "%s!%s%s" % (Utils.color(Utils.COLOR_RED),
- self.module_name, Utils.FONT_RESET)
+ return Utils.color(Utils.bold(self.module_name), Utils.COLOR_RED)
class Module(object):
def __init__(self, bot, events, exports):
diff --git a/modules/ducks.py b/modules/ducks.py
index 817e444f..86bb2f0c 100644
--- a/modules/ducks.py
+++ b/modules/ducks.py
@@ -145,10 +145,13 @@ class Module(object):
duck += DUCK_TAIL
duck += random.choice(DUCK_HEAD)
- duck = str(Utils.color(4) + Utils.bold(
- duck + random.choice(DUCK_MESSAGE_RARE)) + Utils.color(
- 4)) if 1 == random.randint(1, 20) else duck + random.choice(
- DUCK_MESSAGE)
+ if random.randint(1, 20) == 1:
+ # rare!
+ message = random.choice(DUCK_MESSAGE_RARE)
+ duck = Utils.color(Utils.bold(duck + message), Utils.COLOR_RED)
+ else:
+ # not rare!
+ duck += random.choice(DUCK_MESSAGE)
channel.send_message(duck)
channel.games["ducks"]["duck_spawned"] = 1
diff --git a/modules/nr.py b/modules/nr.py
index 490c6c1d..0958967d 100644
--- a/modules/nr.py
+++ b/modules/nr.py
@@ -195,8 +195,7 @@ class Module(object):
query["stationManagerCode"])
else:
station_summary = "%s (%s, %s%s)" % (query["locationName"], query["crs"], query["stationManagerCode"],
- ", %s%s severe messages%s" % (Utils.color(Utils.COLOR_RED), nrcc_severe, Utils.color(Utils.FONT_RESET)) if nrcc_severe else ""
- )
+ ", %s%s severe messages%s" % (Utils.color(nrcc_severe, Utils.COLOR_RED) if nrcc_severe else ""))
if not "trainServices" in query and not "busServices" in query and not "ferryServices" in query:
return event["stdout"].write("%s: No services for the next %s minutes" % (
@@ -291,7 +290,7 @@ class Module(object):
t["origin_summary"] if t["terminating"] or filter["type"]=="arrival" else t["dest_summary"]
) for t in trains_filtered])
else:
- trains_string = ", ".join(["%s%s (%s, %s%s%s%s, %s%s%s%s%s)" % (
+ trains_string = ", ".join(["%s%s (%s, %s%s%s%s, %s%s%s)" % (
"from " if not filter["type"][0] in "ad" and t["terminating"] else '',
t["origin_summary"] if t["terminating"] or filter["type"]=="arrival" else t["dest_summary"],
t["uid"],
@@ -300,9 +299,7 @@ class Module(object):
"*" if t["platform_hidden"] else '',
"?" if "platformsAreUnreliable" in query and query["platformsAreUnreliable"] else '',
t["times"][filter["type"]]["prefix"].replace(filter["type"][0], '') if not t["cancelled"] else "",
- Utils.color(colours[t["times"][filter["type"]]["status"]]),
- t["times"][filter["type"]]["shortest"*filter["st"] or "short"],
- Utils.color(Utils.FONT_RESET),
+ Utils.color(t["times"][filter["type"]]["shortest"*filter["st"] or "short"], colours[t["times"][filter["type"]]["status"]]),
bool(t["activity"])*", " + "+".join(t["activity"]),
) for t in trains_filtered])
if event.get("external"):
@@ -371,7 +368,7 @@ class Module(object):
if "delayReason" in query:
disruptions.append("Delayed (%s%s)" % (query["delayReason"]["value"], " at " + query["delayReason"]["_tiploc"] if query["delayReason"]["_tiploc"] else ""))
if disruptions and not external:
- disruptions = Utils.color(Utils.COLOR_RED) + ", ".join(disruptions) + Utils.color(Utils.FONT_RESET) + " "
+ disruptions = Utils.color(", ".join(disruptions), Utils.COLOR_RED) + " "
elif disruptions and external:
disruptions = ", ".join(disruptions)
else: disruptions = ""
@@ -450,16 +447,14 @@ class Module(object):
elif station["called"]:
station["times"]["arrival"]["status"], station["times"]["departure"]["status"] = 0, 0
- station["summary"] = "%s%s (%s%s%s%s%s%s%s)%s" % (
+ station["summary"] = "%s%s (%s%s%s%s%s)%s" % (
"*" * station["passing"],
station["name"],
station["crs"] + ", " if station["name"] != station["crs"] else '',
station["length"] + " cars, " if station["length"] and (station["first"] or (station["last"]) or station["associations"]) else '',
("~" if station["times"][filter["type"]]["estimate"] else '') +
station["times"][filter["type"]]["prefix"].replace(filter["type"][0], ""),
- Utils.color(colours[station["times"][filter["type"]]["status"]]),
- station["times"][filter["type"]]["short"],
- Utils.color(Utils.FONT_RESET),
+ Utils.color(station["times"][filter["type"]]["short"], colours[station["times"][filter["type"]]["status"]]),
", "*bool(station["activity_p"]) + "+".join(station["activity_p"]),
", ".join([a["summary"] for a in station["associations"]]),
)
@@ -498,7 +493,7 @@ class Module(object):
else:
event["stdout"].write("%s%s %s %s (%s%s%s/%s/%s): %s" % (disruptions, query["operatorCode"],
query["trainid"], query["serviceType"],
- Utils.color(Utils.COLOR_LIGHTBLUE), done_count, Utils.color(Utils.FONT_RESET),
+ Utils.color(done_count, Utils.COLOR_LIGHTBLUE),
len(stations_filtered), total_count,
", ".join([s["summary"] for s in stations_filtered])))