def submods(text, chan, conn, reply): """<subreddit> - prints the moderators of the specified subreddit.""" sub = get_sub(text) url = subreddit_url + "about/moderators.json" r = requests.get(url.format(sub), headers=agent) try: r.raise_for_status() except HTTPError as e: reply(statuscheck(e.response.status_code, 'r/' + sub)) raise if r.status_code != 200: return statuscheck(r.status_code, 'r/' + sub) data = r.json() moderators = [] for mod in data['data']['children']: username = mod['name'] # Showing the modtime makes the message too long for larger subs # if you want to show this information add modtime.days to out below modtime = datetime.now() - datetime.fromtimestamp(mod['date']) modtime = time_format(modtime.days) moderators.append("{} ({}{})".format(username, modtime[0], modtime[1])) pager = paginated_list(moderators) search_pages[conn.name][chan.casefold()] = pager page = pager.next() if len(pager) > 1: page[-1] += " .moremod" out = colors.parse("/r/$(b){}$(b) mods: ".format(sub)) page[0] = out + page[0] return page
def moderates(text, chan, conn, reply): """<username> - This plugin prints the list of subreddits a user moderates listed in a reddit users profile. Private subreddits will not be listed.""" user = get_user(text) r = requests.get(user_url.format(user) + "moderated_subreddits.json", headers=agent) try: r.raise_for_status() except HTTPError as e: reply(statuscheck(e.response.status_code, user)) raise if r.status_code != 200: return statuscheck(r.status_code, user) data = r.json() subs = data['data'] out = colors.parse( "$(b){}$(b) moderates these public subreddits: ".format(user)) pager = paginated_list([sub['sr'] for sub in subs]) search_pages[conn.name][chan.casefold()] = pager page = pager.next() if len(pager) > 1: page[-1] += " .moremod" page[0] = out + page[0] return page
def page_scores(conn, chan, scores): pager = paginated_list(scores, delim=" | ", pager_cls=CommandPager) search_pages[conn.name][chan.casefold()] = pager page = pager.next() if len(pager) > 1: page[-1] += " .morescore" return page
def profile(text, chan, notice, nick): """<nick> [category] - Returns a user's saved profile data from \"<category>\", or lists all available profile categories for the user if no category specified""" chan_cf = chan.casefold() nick_cf = nick.casefold() # Check if we are in a PM with the user if nick_cf == chan_cf: return "Profile data not available outside of channels" chan_profiles = profile_cache.get(chan_cf, {}) # Split the text in to the nick and requested category unpck = text.split(None, 1) pnick = unpck.pop(0) pnick_cf = pnick.casefold() user_profile = chan_profiles.get(pnick_cf, {}) if not user_profile: notice( "User {} has no profile data saved in this channel".format(pnick)) return # Check if the caller specified a profile category, if not, send a NOTICE with the users registered categories if not unpck: cats = list(user_profile.keys()) pager = paginated_list(cats, ', ', pager_cls=CommandPager) cat_pages[chan_cf][nick_cf] = pager page = pager.next() page[0] = "Categories: {}".format(page[0]) if len(pager) > 1: page[-1] += " .moreprofile" for line in page: notice(line) else: category = unpck.pop(0) cat_cf = category.casefold() if cat_cf not in user_profile: notice( "User {} has no profile data for category {} in this channel". format(pnick, category)) else: content = user_profile[cat_cf] return format_profile(pnick, category, content)
def moderates(text, chan, conn): """This plugin prints the list of subreddits a user moderates listed in a reddit users profile. Private subreddits will not be listed.""" user = text r = requests.get(user_url.format(user) + "moderated_subreddits.json", headers=agent) if r.status_code != 200: return statuscheck(r.status_code, user) data = r.json() subs = data['data'] out = colors.parse( "$(b){}$(b) moderates these public subreddits: ".format(user)) pager = paginated_list([sub['sr'] for sub in subs]) search_pages[conn.name][chan.casefold()] = pager page = pager.next() if len(page) > 1: page[-1] += " .moremod" page[0] = out + page[0] return page
def grabsearch(text, chan, conn): """[text] - matches "text" against nicks or grab strings in the database""" result = [] lower_text = text.lower() with cache_lock: try: chan_grabs = grab_cache[chan] except LookupError: return "I couldn't find any grabs in {}.".format(chan) try: quotes = chan_grabs[lower_text] except KeyError: pass else: result.extend((text, quote) for quote in quotes) for name, quotes in chan_grabs.items(): if name != lower_text: result.extend((name, quote) for quote in quotes if lower_text in quote.lower()) if not result: return "I couldn't find any matches for {}.".format(text) grabs = [] for name, quote in result: if lower_text == name: name = text grabs.append(format_grab(name, quote)) pager = paginated_list(grabs) search_pages[conn.name][chan] = pager page = pager.next() if len(pager) > 1: page[-1] += " .moregrab" return page
def submods(text, chan, conn, reply): """<subreddit> - prints the moderators of the specified subreddit.""" sub = get_sub(text) url = subreddit_url + "about/moderators.json" data = get_sub_data(url, sub, reply) moderators = [] for mod in data['data']['children']: username = mod['name'] # Showing the modtime makes the message too long for larger subs # if you want to show this information add modtime.days to out below modtime = datetime.now() - datetime.fromtimestamp(mod['date']) modtime = time_format(modtime.days) moderators.append("{} ({}{})".format(username, modtime[0], modtime[1])) pager = paginated_list(moderators, pager_cls=CommandPager) search_pages[conn.name][chan.casefold()] = pager page = pager.next() if len(pager) > 1: page[-1] += " .moremod" out = colors.parse("/r/$(b){}$(b) mods: ".format(sub)) page[0] = out + page[0] return page