Skip to content

Commit 78769fa

Browse files
committed
Switch to using colors.parse() for string formatting instead of using the raw characters
1 parent 0517eb1 commit 78769fa

1 file changed

Lines changed: 13 additions & 12 deletions

File tree

plugins/reddit_info.py

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from datetime import datetime
55
from bs4 import BeautifulSoup
66
from cloudbot import hook
7+
from cloudbot.util import colors
78
from cloudbot.util.formatting import pluralize
89

910
search_pages = defaultdict(list)
@@ -87,7 +88,7 @@ def moderates(text, chan):
8788

8889
mod_list = mod_list.text.split('r/')
8990
del mod_list[0]
90-
out = "\x02{}\x02 moderates these public subreddits: ".format(user)
91+
out = colors.parse("$(b){}$(b) moderates these public subreddits: ".format(user))
9192
for sub in mod_list:
9293
out += "{} \u2022 ".format(sub)
9394
out = out[:-2]
@@ -107,24 +108,24 @@ def karma(text):
107108
if r.status_code != 200:
108109
return statuscheck(r.status_code, user)
109110
data = r.json()
110-
out = "\x02{}\x02 ".format(user)
111-
out += "\x02{:,}\x02 link karma and ".format(data['data']['link_karma'])
112-
out += "\x02{:,}\x02 comment karma | ".format(data['data']['comment_karma'])
111+
out = "$(b){}$(b) ".format(user)
112+
out += "$(b){:,}$(b) link karma and ".format(data['data']['link_karma'])
113+
out += "$(b){:,}$(b) comment karma | ".format(data['data']['comment_karma'])
113114
if data['data']['is_gold']:
114115
out += "has reddit gold | "
115116
if data['data']['is_mod']:
116117
out += "is a moderator | "
117118
if data['data']['has_verified_email']:
118119
out += "email has been verified | "
119-
out += "cake day is {} | ".format(datetime.fromtimestamp(data['data']['created_utc']).strftime('%B %d') )
120+
out += "cake day is {} | ".format(datetime.fromtimestamp(data['data']['created_utc']).strftime('%B %d'))
120121
account_age = datetime.now() - datetime.fromtimestamp(data['data']['created'])
121122
age = account_age.days
122123
age_unit = "day"
123124
if age > 365:
124125
age //= 365
125126
age_unit = "year"
126127
out += "redditor for {}.".format(pluralize(age, age_unit))
127-
return out
128+
return colors.parse(out)
128129

129130

130131
@hook.command("cakeday", singlethread=True)
@@ -136,8 +137,8 @@ def cake_day(text):
136137
if r.status_code != 200:
137138
return statuscheck(r.status_code, user)
138139
data = r.json()
139-
out = "\x02{}'s\x02 ".format(user)
140-
out += "cake day is {}, ".format(datetime.fromtimestamp(data['data']['created_utc']).strftime('%B %d') )
140+
out = colors.parse("$(b){}'s$(b) ".format(user))
141+
out += "cake day is {}, ".format(datetime.fromtimestamp(data['data']['created_utc']).strftime('%B %d'))
141142
account_age = datetime.now() - datetime.fromtimestamp(data['data']['created'])
142143
age = account_age.days
143144
age_unit = "day"
@@ -174,7 +175,7 @@ def submods(text, chan):
174175
if r.status_code != 200:
175176
return statuscheck(r.status_code, 'r/'+sub)
176177
data = r.json()
177-
out = "/r/\x02{}\x02 mods: ".format(sub)
178+
out = colors.parse("/r/$(b){}$(b) mods: ".format(sub))
178179
for mod in data['data']['children']:
179180
username = mod['name']
180181
# Showing the modtime makes the message too long for larger subs
@@ -212,9 +213,9 @@ def subinfo(text):
212213
active = data['data']['accounts_active']
213214
sub_age = datetime.now() - datetime.fromtimestamp(data['data']['created'])
214215
age, age_unit = time_format(sub_age.days)
215-
out = "/r/\x02{}\x02 - {} - a community for {}{}, there are {:,} subscribers and {:,} people online now.".format(
216+
out = "/r/$(b){}$(clear) - {} - a community for {}{}, there are {:,} subscribers and {:,} people online now.".format(
216217
name, title, age, age_unit, subscribers, active
217218
)
218219
if nsfw:
219-
out += " \x0304NSFW\x0304"
220-
return out
220+
out += " $(red)NSFW$(clear)"
221+
return colors.parse(out)

0 commit comments

Comments
 (0)