def get_quotes(phenny, input): if input.group(2) is None: quotes_string = u"\n".join( _format_quote(nick, quote) for nick, quotes in phenny.quotes.items() for quote, submitter in quotes) else: nick = input.group(2).lower() quotes_string = u"\n".join( _format_quote(nick, quote) for quote, submitter in phenny.quotes.get(nick, [])) if quotes_string: try: url = web.dpaste(phenny, quotes_string) except urllib2.HTTPError as e: return phenny.say(u"Could not create quotes file: error code {}, reason: {}".format( e.code, e.reason)) else: return phenny.say(url) else: return phenny.say("No quotes were found.")
def _tell_top_karma(phenny, input): show_top = 6 if len(phenny.karmas) > 0: all_karm = dict(((key, kn.karma) for key, kn in phenny.karmas.items())) karm = dict(((key, kn.karma) for key, kn in phenny.karmas.items() if kn.root() == kn)) # remove duplicates due to aliases s_karm = sorted(karm, key=karm.get, reverse=True) if is_fools(): s_karm = [phenny.fools_dict[u] for u in s_karm] all_karm = dict(((key, karma / 2 - 5) for key, karma in all_karm.items())) msg = ', '.join([x + ": " + str(all_karm[x]) for x in s_karm[:show_top]]) if msg: phenny.notice(input.nick, "Best karma: " + msg) worst_karmas = ', '.join([x + ": " + str(all_karm[x]) for x in s_karm[:-show_top-1:-1] if all_karm[x] < 0]) if worst_karmas: phenny.notice(input.nick, "Worst karma: " + worst_karmas) dmsg = '\n'.join("{}: {}".format(x, all_karm[x]) for x in s_karm) phenny.say(web.dpaste(phenny, dmsg)) else: phenny.say("You guys don't have any karma apparently.")