Skip to content

Commit 1d6d678

Browse files
authored
Merge pull request CloudBotIRC#54 from MuffinMedic/reddit_info
Allow use of "/r/" and "r/" sub formats in 'mods' and 'subinfo' commands
2 parents 822e94b + e83c6b0 commit 1d6d678

1 file changed

Lines changed: 12 additions & 4 deletions

File tree

plugins/reddit_info.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -162,17 +162,21 @@ def time_format(numdays):
162162

163163
@hook.command("submods", "mods", "rmods", singlethreaded=True)
164164
def submods(text, chan):
165-
"""submods <subreddit> prints the moderators of the specified subreddit. Do not include /r/ when specifying a subreddit."""
165+
"""submods <subreddit> prints the moderators of the specified subreddit."""
166166
global search_pages
167167
search_pages[chan] = []
168168
search_page_indexes[chan] = 0
169169
sub = text
170+
if sub.startswith('/r/'):
171+
sub = sub[3:]
172+
elif sub.startswith('r/'):
173+
sub = sub[2:]
170174
url = subreddit_url + "about/moderators.json"
171175
r = requests.get(url.format(sub), headers=agent)
172176
if r.status_code != 200:
173177
return statuscheck(r.status_code, 'r/'+sub)
174178
data = r.json()
175-
out = "r/\x02{}\x02 mods: ".format(sub)
179+
out = "/r/\x02{}\x02 mods: ".format(sub)
176180
for mod in data['data']['children']:
177181
username = mod['name']
178182
# Showing the modtime makes the message too long for larger subs
@@ -189,8 +193,12 @@ def submods(text, chan):
189193

190194
@hook.command("subinfo","subreddit", "sub", "rinfo", singlethreaded=True)
191195
def subinfo(text):
192-
"""subinfo <subreddit> fetches information about the specified subreddit. Do not include /r/ when specifying a subreddit."""
196+
"""subinfo <subreddit> fetches information about the specified subreddit."""
193197
sub = text
198+
if sub.startswith('/r/'):
199+
sub = sub[3:]
200+
elif sub.startswith('r/'):
201+
sub = sub[2:]
194202
url = subreddit_url + "about.json"
195203
r = requests.get(url.format(sub), headers=agent)
196204
if r.status_code != 200:
@@ -209,7 +217,7 @@ def subinfo(text):
209217
age = (int(sub_age.days / 365), "y")
210218
else:
211219
age = (sub_age.days, "d")
212-
out = "r/\x03{}\x02 - {} - a community for {}{}, there are {:,} subscribers and {:,} people online now.".format(name, title, age[0], age[1], subscribers, active)
220+
out = "/r/\x03{}\x02 - {} - a community for {}{}, there are {:,} subscribers and {:,} people online now.".format(name, title, age[0], age[1], subscribers, active)
213221
if nsfw:
214222
out += " \x0304NSFW\x0304"
215223
return out

0 commit comments

Comments
 (0)