Skip to content

Commit ede6410

Browse files
authored
Merge pull request CloudBotIRC#162 from linuxdaemon/gonzobot+reddit-info-fix
Switch .subs command away from page scraping
2 parents e065c3e + 1697791 commit ede6410

1 file changed

Lines changed: 6 additions & 10 deletions

File tree

plugins/reddit_info.py

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -73,24 +73,20 @@ def moremod(text, chan):
7373
@hook.command("subs", "moderates", singlethread=True)
7474
def moderates(text, chan):
7575
"""This plugin prints the list of subreddits a user moderates listed in a reddit users profile. Private subreddits will not be listed."""
76-
#This command was written using concepts from FurCode http://github.com/FurCode.
7776
global search_pages
7877
search_pages[chan] = []
7978
search_page_indexes[chan] = 0
8079
user = text
81-
r = requests.get(user_url.format(user), headers=agent)
80+
r = requests.get(user_url.format(user) + "moderated_subreddits.json", headers=agent)
8281
if r.status_code != 200:
8382
return statuscheck(r.status_code, user)
84-
soup = BeautifulSoup(r.text)
85-
mod_list = soup.find('ul', id="side-mod-list")
86-
if mod_list is None:
87-
return "{} does not moderate any public subreddits.".format(user)
8883

89-
mod_list = mod_list.text.split('r/')
90-
del mod_list[0]
84+
data = r.json()
85+
subs = data['data']
9186
out = colors.parse("$(b){}$(b) moderates these public subreddits: ".format(user))
92-
for sub in mod_list:
93-
out += "{} \u2022 ".format(sub)
87+
for sub in subs:
88+
out += "{} \u2022 ".format(sub['sr'])
89+
9490
out = out[:-2]
9591
out = smart_truncate(out)
9692
if len(out.split('\n')) > 2:

0 commit comments

Comments
 (0)