From 398b34fad5858ba3ed6db12200f20ef6629b4904 Mon Sep 17 00:00:00 2001 From: Luke Rogers Date: Thu, 13 Feb 2014 12:34:03 +1300 Subject: [PATCH 01/16] Disabled mark.py @md-5 --- plugins/mark.py => disabled_plugins | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename plugins/mark.py => disabled_plugins (100%) diff --git a/plugins/mark.py b/disabled_plugins similarity index 100% rename from plugins/mark.py rename to disabled_plugins From 6cc7554cd891449fbcd6bfba2a51bd21d3b1d935 Mon Sep 17 00:00:00 2001 From: Luke Rogers Date: Thu, 13 Feb 2014 14:34:50 +1300 Subject: [PATCH 02/16] A dash of PEP-8 --- plugins/{coins.py => cryptocoins.py} | 5 +++-- plugins/dice.py | 14 +++++++------- plugins/domainr.py | 2 +- plugins/eightball.py | 2 +- plugins/namegen.py | 7 +++---- plugins/newegg.py | 14 +++++++------- plugins/password.py | 6 +++--- plugins/pre.py | 2 +- plugins/reddit.py | 12 ++++++------ plugins/twitter.py | 4 ++-- plugins/wolframalpha.py | 1 - 11 files changed, 34 insertions(+), 35 deletions(-) rename plugins/{coins.py => cryptocoins.py} (90%) diff --git a/plugins/coins.py b/plugins/cryptocoins.py similarity index 90% rename from plugins/coins.py rename to plugins/cryptocoins.py index bdb0e19..4973444 100644 --- a/plugins/coins.py +++ b/plugins/cryptocoins.py @@ -35,7 +35,8 @@ exchanges = { @hook.command("btc", autohelp=False) @hook.command(autohelp=False) def bitcoin(inp): - """bitcoin -- Gets current exchange rate for bitcoins from several exchanges, default is Blockchain. Supports MtGox, Bitpay, Coinbase and BitStamp.""" + """bitcoin -- Gets current exchange rate for bitcoins from several exchanges, default is Blockchain. + Supports MtGox, Bitpay, Coinbase and BitStamp.""" inp = inp.lower() if inp: @@ -58,4 +59,4 @@ def litecoin(inp, message=None): data = http.get_json("https://btc-e.com/api/2/ltc_usd/ticker") ticker = data['ticker'] message("Current: \x0307${:,.2f}\x0f - High: \x0307${:,.2f}\x0f" - " - Low: \x0307${:,.2f}\x0f - Volume: {:,.2f} LTC".format(ticker['buy'], ticker['high'], ticker['low'], ticker['vol_cur'])) + " - Low: \x0307${:,.2f}\x0f - Volume: {:,.2f} LTC".format(ticker['buy'], ticker['high'], ticker['low'], ticker['vol_cur'])) diff --git a/plugins/dice.py b/plugins/dice.py index 94e0f46..f748da6 100644 --- a/plugins/dice.py +++ b/plugins/dice.py @@ -49,7 +49,7 @@ def dice(inp): spec = whitespace_re.sub('', inp) if not valid_diceroll_re.match(spec): - return "Invalid diceroll" + return "Invalid dice roll" groups = sign_re.findall(spec) total = 0 @@ -73,13 +73,13 @@ def dice(inp): side = int(side) try: if count > 0: - dice = nrolls(count, side) - rolls += map(str, dice) - total += sum(dice) + d = nrolls(count, side) + rolls += map(str, d) + total += sum(d) else: - dice = nrolls(-count, side) - rolls += [str(-x) for x in dice] - total -= sum(dice) + d = nrolls(-count, side) + rolls += [str(-x) for x in d] + total -= sum(d) except OverflowError: return "Thanks for overflowing a float, jerk >:[" diff --git a/plugins/domainr.py b/plugins/domainr.py index 804d237..061ad3f 100644 --- a/plugins/domainr.py +++ b/plugins/domainr.py @@ -9,7 +9,7 @@ def domainr(inp): except (http.URLError, http.HTTPError) as e: return "Unable to get data for some reason. Try again later." if data['query'] == "": - return "An error occurrred: {status} - {message}".format(**data['error']) + return "An error occurred: {status} - {message}".format(**data['error']) domains = "" for domain in data['results']: domains += ("\x034" if domain['availability'] == "taken" else ( diff --git a/plugins/eightball.py b/plugins/eightball.py index 929a890..0e039fb 100644 --- a/plugins/eightball.py +++ b/plugins/eightball.py @@ -13,7 +13,7 @@ with open("plugins/data/8ball_responses.txt") as f: @hook.command('8ball') -def eightball(input, action=None): +def eightball(inp, action=None): """8ball -- The all knowing magic eight ball, in electronic form. Ask and it shall be answered!""" diff --git a/plugins/namegen.py b/plugins/namegen.py index f4ab7fe..0a95f36 100644 --- a/plugins/namegen.py +++ b/plugins/namegen.py @@ -1,4 +1,3 @@ -# Plugin by Lukeroge from util import hook, text, textgen import json import os @@ -10,13 +9,13 @@ GEN_DIR = "./plugins/data/name_files/" def get_generator(_json): data = json.loads(_json) return textgen.TextGenerator(data["templates"], - data["parts"], default_templates=data["default_templates"]) + data["parts"], default_templates=data["default_templates"]) @hook.command(autohelp=False) def namegen(inp, notice=None): - "namegen [generator] -- Generates some names using the chosen generator. " \ - "'namegen list' will display a list of all generators." + """namegen [generator] -- Generates some names using the chosen generator. + 'namegen list' will display a list of all generators.""" # clean up the input inp = inp.strip().lower() diff --git a/plugins/newegg.py b/plugins/newegg.py index 0a88286..76b2a70 100644 --- a/plugins/newegg.py +++ b/plugins/newegg.py @@ -21,11 +21,11 @@ def format_item(item, show_url=True): # format the rating nicely if it exists if not item["ReviewSummary"]["TotalReviews"] == "[]": rating = "Rated {}/5 ({} ratings)".format(item["ReviewSummary"]["Rating"], - item["ReviewSummary"]["TotalReviews"][1:-1]) + item["ReviewSummary"]["TotalReviews"][1:-1]) else: rating = "No Ratings" - if not item["FinalPrice"] == item["OriginalPrice"]: + if not item["FinalPrice"] == item["OriginalPrice"]: price = "{FinalPrice}, was {OriginalPrice}".format(**item) else: price = item["FinalPrice"] @@ -46,17 +46,17 @@ def format_item(item, show_url=True): if item["IsShellShockerItem"]: tags.append("\x02SHELL SHOCKER®\x02") - # join all the tags together in a comma seperated string ("tag1, tag2, tag3") + # join all the tags together in a comma separated string ("tag1, tag2, tag3") tag_text = u", ".join(tags) if show_url: # create the item URL and shorten it url = web.try_isgd(ITEM_URL.format(item["NeweggItemNumber"])) return u"\x02{}\x02 ({}) - {} - {} - {}".format(title, price, rating, - tag_text, url) + tag_text, url) else: return u"\x02{}\x02 ({}) - {} - {}".format(title, price, rating, - tag_text) + tag_text) ## HOOK FUNCTIONS @@ -80,8 +80,8 @@ def newegg(inp): # submit the search request r = http.get_json( - 'http://www.ows.newegg.com/Search.egg/Advanced', - post_data = json.dumps(request) + 'http://www.ows.newegg.com/Search.egg/Advanced', + post_data=json.dumps(request) ) # get the first result diff --git a/plugins/password.py b/plugins/password.py index 6878515..2187302 100644 --- a/plugins/password.py +++ b/plugins/password.py @@ -39,10 +39,10 @@ def password(inp, notice=None): if not okay: okay = okay + list(string.ascii_lowercase) - password = "" + pw = "" # generates password for x in range(length): - password = password + random.choice(okay) + pw = pw + random.choice(okay) - notice(password) + notice(pw) diff --git a/plugins/pre.py b/plugins/pre.py index 80aa77f..0e443f9 100644 --- a/plugins/pre.py +++ b/plugins/pre.py @@ -5,7 +5,7 @@ import datetime @hook.command("scene") @hook.command def pre(inp): - 'pre -- searches scene releases using orlydb.com' + """pre -- searches scene releases using orlydb.com""" try: h = http.get_html("http://orlydb.com/", q=inp) diff --git a/plugins/reddit.py b/plugins/reddit.py index 7b96a94..add83d1 100644 --- a/plugins/reddit.py +++ b/plugins/reddit.py @@ -52,7 +52,7 @@ def reddit(inp): data = data["data"]["children"] # get the requested/random post - if id_num != None: + if id_num is not None: try: item = data[id_num]["data"] except IndexError: @@ -64,14 +64,14 @@ def reddit(inp): item["title"] = text.truncate_str(item["title"], 50) item["link"] = short_url.format(item["id"]) - rawtime = datetime.fromtimestamp(int(item["created_utc"])) - item["timesince"] = timesince.timesince(rawtime) + raw_time = datetime.fromtimestamp(int(item["created_utc"])) + item["timesince"] = timesince.timesince(raw_time) if item["over_18"]: item["warning"] = " \x02NSFW\x02" else: item["warning"] = "" - return u'\x02{title} : {subreddit}\x02 - posted by \x02{author}\x02' \ - ' {timesince} ago - {ups} upvotes, {downs} downvotes -' \ - ' {link}{warning}'.format(**item) + return u"\x02{title} : {subreddit}\x02 - posted by \x02{author}\x02" \ + " {timesince} ago - {ups} upvotes, {downs} downvotes -" \ + " {link}{warning}".format(**item) diff --git a/plugins/twitter.py b/plugins/twitter.py index f0b2e52..2ea8ab8 100644 --- a/plugins/twitter.py +++ b/plugins/twitter.py @@ -26,7 +26,7 @@ def get_api(bot): @hook.regex(*TWITTER_RE) def twitter_url(match, bot=None): tweet_id = match.group(1) - + api = get_api(bot) if not api: return @@ -46,7 +46,7 @@ def twitter_url(match, bot=None): time = timesince.timesince(tweet.created_at, datetime.utcnow()) return u"{}@\x02{}\x02 ({}): {} ({} ago)".format(prefix, user.screen_name, user.name, text, time) - + @hook.command("tw") @hook.command("twatter") diff --git a/plugins/wolframalpha.py b/plugins/wolframalpha.py index 0ade2bc..b20ffed 100644 --- a/plugins/wolframalpha.py +++ b/plugins/wolframalpha.py @@ -9,7 +9,6 @@ from util import hook, http, text, web @hook.command def wolframalpha(inp, bot=None): """wa -- Computes using Wolfram Alpha.""" - api_key = bot.config.get("api_keys", {}).get("wolframalpha", None) if not api_key: From cd5ae1d32bb19dc165ede22a7c393ee2c951f4ff Mon Sep 17 00:00:00 2001 From: Luke Rogers Date: Thu, 13 Feb 2014 15:02:44 +1300 Subject: [PATCH 03/16] further pepping, spelling and other such things --- plugins/spellcheck.py | 6 +++--- plugins/steam.py | 3 ++- plugins/stock.py | 2 +- plugins/title.py | 6 +++--- plugins/tvdb.py | 23 +++++++++++------------ plugins/urban.py | 21 ++++++++++----------- plugins/utility.py | 6 +++--- plugins/validate.py | 6 +++--- plugins/vimeo.py | 2 +- plugins/weather.py | 2 +- plugins/yahooanswers.py | 4 ++-- plugins/youtube.py | 27 ++++++++++++--------------- 12 files changed, 52 insertions(+), 56 deletions(-) diff --git a/plugins/spellcheck.py b/plugins/spellcheck.py index 33265d6..7ab188d 100644 --- a/plugins/spellcheck.py +++ b/plugins/spellcheck.py @@ -15,11 +15,11 @@ def spell(inp): if len(inp.split(" ")) > 1: # input is a sentence - chkr = SpellChecker(locale) - chkr.set_text(inp) + checker = SpellChecker(locale) + checker.set_text(inp) offset = 0 - for err in chkr: + for err in checker: # find the location of the incorrect word start = err.wordpos + offset finish = start + len(err.word) diff --git a/plugins/steam.py b/plugins/steam.py index 69089ae..c18867d 100644 --- a/plugins/steam.py +++ b/plugins/steam.py @@ -56,7 +56,8 @@ def get_steam_info(url): data["price"] = soup.find('div', {'class': 'game_purchase_price price'}).text.strip() - return u"\x02{name}\x02: {desc}, \x02Genre\x02: {genre}, \x02Release Date\x02: {release date}, \x02Price\x02: {price}".format(**data) + return u"\x02{name}\x02: {desc}, \x02Genre\x02: {genre}, \x02Release Date\x02: {release date}," \ + u" \x02Price\x02: {price}".format(**data) @hook.regex(*steam_re) diff --git a/plugins/stock.py b/plugins/stock.py index 73c36bc..aedf051 100644 --- a/plugins/stock.py +++ b/plugins/stock.py @@ -9,7 +9,7 @@ def stock(inp): query = "SELECT * FROM yahoo.finance.quote WHERE symbol=@symbol LIMIT 1" quote = web.query(query, {"symbol": sym}).one() - # if we dont get a company name back, the symbol doesn't match a company + # if we don't get a company name back, the symbol doesn't match a company if quote['Change'] is None: return "Unknown ticker symbol: {}".format(sym) diff --git a/plugins/title.py b/plugins/title.py index 1e3b403..6b912a3 100644 --- a/plugins/title.py +++ b/plugins/title.py @@ -14,9 +14,9 @@ def title(inp): except (http.HTTPError, http.URLError): return "Could not fetch page." - title = soup.find('title').contents[0] + page_title = soup.find('title').contents[0] - if not title: + if not page_title: return "Could not find title." - return u"{} [{}]".format(title, real_url) + return u"{} [{}]".format(page_title, real_url) diff --git a/plugins/tvdb.py b/plugins/tvdb.py index 22a5cd7..fa7584c 100644 --- a/plugins/tvdb.py +++ b/plugins/tvdb.py @@ -13,7 +13,6 @@ from util import hook, http base_url = "http://thetvdb.com/api/" -api_key = "469B73127CA0C411" def get_zipped_xml(*args, **kwargs): @@ -25,11 +24,11 @@ def get_zipped_xml(*args, **kwargs): return etree.parse(ZipFile(zip_buffer, "r").open(path)) -def get_episodes_for_series(seriesname, api_key): +def get_episodes_for_series(series_name, api_key): res = {"error": None, "ended": False, "episodes": None, "name": None} # http://thetvdb.com/wiki/index.php/API:GetSeries try: - query = http.get_xml(base_url + 'GetSeries.php', seriesname=seriesname) + query = http.get_xml(base_url + 'GetSeries.php', seriesname=series_name) except URLError: res["error"] = "error contacting thetvdb.com" return res @@ -63,7 +62,7 @@ def get_episode_info(episode, api_key): first_aired = episode.findtext("FirstAired") try: - airdate = datetime.date(*map(int, first_aired.split('-'))) + air_date = datetime.date(*map(int, first_aired.split('-'))) except (ValueError, TypeError): return None @@ -79,7 +78,7 @@ def get_episode_info(episode, api_key): episode_desc = '{}'.format(episode_num) if episode_name: episode_desc += ' - {}'.format(episode_name) - return first_aired, airdate, episode_desc + return first_aired, air_date, episode_desc @hook.command @@ -111,15 +110,15 @@ def tv_next(inp, bot=None): if ep_info is None: continue - (first_aired, airdate, episode_desc) = ep_info + (first_aired, air_date, episode_desc) = ep_info - if airdate > today: + if air_date > today: next_eps = ['{} ({})'.format(first_aired, episode_desc)] - elif airdate == today: + elif air_date == today: next_eps = ['Today ({})'.format(episode_desc)] + next_eps else: - #we're iterating in reverse order with newest episodes last - #so, as soon as we're past today, break out of loop + # we're iterating in reverse order with newest episodes last + # so, as soon as we're past today, break out of loop break if not next_eps: @@ -158,9 +157,9 @@ def tv_last(inp, bot=None): if ep_info is None: continue - (first_aired, airdate, episode_desc) = ep_info + (first_aired, air_date, episode_desc) = ep_info - if airdate < today: + if air_date < today: #iterating in reverse order, so the first episode encountered #before today was the most recently aired prev_ep = '{} ({})'.format(first_aired, episode_desc) diff --git a/plugins/urban.py b/plugins/urban.py index 5158829..7374145 100644 --- a/plugins/urban.py +++ b/plugins/urban.py @@ -10,37 +10,36 @@ def urban(inp): """urban [id] -- Looks up on urbandictionary.com.""" # clean and split the input - input = inp.lower().strip() - parts = input.split() + inp = inp.lower().strip() + parts = inp.split() # if the last word is a number, set the ID to that number if parts[-1].isdigit(): - id = int(parts[-1]) + id_num = int(parts[-1]) # remove the ID from the input string del parts[-1] - input = " ".join(parts) + inp = " ".join(parts) else: - id = 1 + id_num = 1 # fetch the definitions - page = http.get_json(base_url, term=input, referer="http://m.urbandictionary.com") - defs = page['list'] - print page + page = http.get_json(base_url, term=inp, referer="http://m.urbandictionary.com") + definitions = page['list'] if page['result_type'] == 'no_results': return 'Not found.' # try getting the requested definition try: - definition = defs[id - 1]['definition'].replace('\r\n', ' ') + definition = definitions[id_num - 1]['definition'].replace('\r\n', ' ') definition = re.sub('\s+', ' ', definition).strip() # remove excess spaces definition = text.truncate_str(definition, 200) except IndexError: return 'Not found.' - url = defs[id - 1]['permalink'] + url = definitions[id_num - 1]['permalink'] output = u"[%i/%i] %s :: %s" % \ - (id, len(defs), definition, url) + (id_num, len(definitions), definition, url) return output diff --git a/plugins/utility.py b/plugins/utility.py index 79fd598..baa215b 100644 --- a/plugins/utility.py +++ b/plugins/utility.py @@ -7,7 +7,7 @@ import re colors = collections.OrderedDict([ ('red', '\x0304'), - ('ornage', '\x0307'), + ('orange', '\x0307'), ('yellow', '\x0308'), ('green', '\x0309'), ('cyan', '\x0303'), @@ -24,8 +24,8 @@ colors = collections.OrderedDict([ strip_re = re.compile("(\x03|\x02|\x1f)(?:,?\d{1,2}(?:,\d{1,2})?)?", re.UNICODE) -def strip(text): - return strip_re.sub('', text) +def strip(string): + return strip_re.sub('', string) # basic text tools diff --git a/plugins/validate.py b/plugins/validate.py index 56a04fc..88022b7 100644 --- a/plugins/validate.py +++ b/plugins/validate.py @@ -20,7 +20,7 @@ def validate(inp): status = info['x-w3c-validator-status'].lower() if status in ("valid", "invalid"): - errorcount = info['x-w3c-validator-errors'] - warningcount = info['x-w3c-validator-warnings'] + error_count = info['x-w3c-validator-errors'] + warning_count = info['x-w3c-validator-warnings'] return "{} was found to be {} with {} errors and {} warnings." \ - " see: {}".format(inp, status, errorcount, warningcount, url) + " see: {}".format(inp, status, error_count, warning_count, url) diff --git a/plugins/vimeo.py b/plugins/vimeo.py index 5b21e87..0a55549 100644 --- a/plugins/vimeo.py +++ b/plugins/vimeo.py @@ -8,7 +8,7 @@ def vimeo_url(match): % match.group(1)) if info: - info[0]["duration"] = timeformat.timeformat(info[0]["duration"]) + info[0]["duration"] = timeformat.format_time(info[0]["duration"]) info[0]["stats_number_of_likes"] = format( info[0]["stats_number_of_likes"], ",d") info[0]["stats_number_of_plays"] = format( diff --git a/plugins/weather.py b/plugins/weather.py index 436a059..8a56046 100644 --- a/plugins/weather.py +++ b/plugins/weather.py @@ -13,7 +13,7 @@ def weather(inp, reply=None, db=None, nick=None, bot=None, notice=None): if not api_key: return "Error: No wunderground API details." - # initalise weather DB + # initialise weather DB db.execute("create table if not exists weather(nick primary key, loc)") # if there is no input, try getting the users last location from the DB diff --git a/plugins/yahooanswers.py b/plugins/yahooanswers.py index 319502e..e28ed63 100644 --- a/plugins/yahooanswers.py +++ b/plugins/yahooanswers.py @@ -11,6 +11,6 @@ def answer(inp): short_url = web.try_isgd(result["Link"]) # we split the answer and .join() it to remove newlines/extra spaces - answer = text.truncate_str(' '.join(result["ChosenAnswer"].split()), 80) + answer_text = text.truncate_str(' '.join(result["ChosenAnswer"].split()), 80) - return u'\x02{}\x02 "{}" - {}'.format(result["Subject"], answer, short_url) + return u'\x02{}\x02 "{}" - {}'.format(result["Subject"], answer_text, short_url) diff --git a/plugins/youtube.py b/plugins/youtube.py index 91e0ea7..67627db 100644 --- a/plugins/youtube.py +++ b/plugins/youtube.py @@ -14,10 +14,7 @@ video_url = "http://youtu.be/%s" def plural(num=0, text=''): - return "{:,} {}{}".format(num, text, "s"[num==1:]) - - - + return "{:,} {}{}".format(num, text, "s"[num == 1:]) def get_video_description(video_id): @@ -41,22 +38,23 @@ def get_video_description(video_id): likes = plural(int(data['likeCount']), "like") dislikes = plural(data['ratingCount'] - int(data['likeCount']), "dislike") - percent = 100 * float(data['likeCount'])/float(data['ratingCount']) + percent = 100 * float(data['likeCount']) / float(data['ratingCount']) out += u' - {}, {} (\x02{:.1f}\x02%)'.format(likes, - dislikes, percent) + dislikes, percent) if 'viewCount' in data: views = data['viewCount'] - out += u' - \x02{:,}\x02 view{}'.format(views, "s"[views==1:]) + out += u' - \x02{:,}\x02 view{}'.format(views, "s"[views == 1:]) try: - uploader = http.get_json(base_url + "users/{}?alt=json".format(data["uploader"]))["entry"]["author"][0]["name"]["$t"] + uploader = http.get_json(base_url + "users/{}?alt=json".format(data["uploader"]))["entry"]["author"][0]["name"][ + "$t"] except: uploader = data["uploader"] - + upload_time = time.strptime(data['uploaded'], "%Y-%m-%dT%H:%M:%S.000Z") out += u' - \x02{}\x02 on \x02{}\x02'.format(uploader, - time.strftime("%Y.%m.%d", upload_time)) + time.strftime("%Y.%m.%d", upload_time)) if 'contentRating' in data: out += u' - \x034NSFW\x02' @@ -88,7 +86,6 @@ def youtube(inp): return get_video_description(video_id) + u" - " + video_url % video_id - @hook.command('ytime') @hook.command def youtime(inp): @@ -119,8 +116,8 @@ def youtime(inp): total_text = timeformat.format_time(total, accuracy=8) return u'The video \x02{}\x02 has a length of {} and has been viewed {:,} times for ' \ - 'a total run time of {}!'.format(data['title'], length_text, views, \ - total_text) + u'a total run time of {}!'.format(data['title'], length_text, views, + total_text) ytpl_re = (r'(.*:)//(www.youtube.com/playlist|youtube.com/playlist)(:[0-9]+)?(.*)', re.I) @@ -135,6 +132,6 @@ def ytplaylist_url(match): return "\x034\x02Invalid response." title = soup.find('title').text.split('-')[0].strip() author = soup.find('img', {'class': 'channel-header-profile-image'})['title'] - numvideos = soup.find('ul', {'class': 'header-stats'}).findAll('li')[0].text.split(' ')[0] + num_videos = soup.find('ul', {'class': 'header-stats'}).findAll('li')[0].text.split(' ')[0] views = soup.find('ul', {'class': 'header-stats'}).findAll('li')[1].text.split(' ')[0] - return u"\x02%s\x02 - \x02%s\x02 views - \x02%s\x02 videos - \x02%s\x02" % (title, views, numvideos, author) + return u"\x02%s\x02 - \x02%s\x02 views - \x02%s\x02 videos - \x02%s\x02" % (title, views, num_videos, author) From 223bef30a5485fc064f8f74cba896b87a311d70f Mon Sep 17 00:00:00 2001 From: Luke Rogers Date: Thu, 13 Feb 2014 15:09:22 +1300 Subject: [PATCH 04/16] pepepepep8 --- plugins/fishbans.py | 1 - plugins/fmylife.py | 8 ++++---- plugins/metacritic.py | 5 ----- plugins/minecraft_bukget.py | 5 +++-- plugins/minecraft_wiki.py | 2 +- 5 files changed, 8 insertions(+), 13 deletions(-) diff --git a/plugins/fishbans.py b/plugins/fishbans.py index 26d86c5..7afe5e2 100644 --- a/plugins/fishbans.py +++ b/plugins/fishbans.py @@ -51,6 +51,5 @@ def bancount(inp): if not out: return "The user \x02{}\x02 has no bans.".format(user) else: - # dat string. return "Bans for \x02{}\x02: ".format(user) + ", ".join(out) + ". More info " \ "at {}".format(user_url) diff --git a/plugins/fmylife.py b/plugins/fmylife.py index a25b1a4..1d8c0fa 100644 --- a/plugins/fmylife.py +++ b/plugins/fmylife.py @@ -8,9 +8,9 @@ def refresh_cache(): soup = http.get_soup('http://www.fmylife.com/random/') for e in soup.find_all('div', {'class': 'post article'}): - id = int(e['id']) + fml_id = int(e['id']) text = ''.join(e.find('p').find_all(text=True)) - fml_cache.append((id, text)) + fml_cache.append((fml_id, text)) # do an initial refresh of the cache refresh_cache() @@ -21,9 +21,9 @@ def fml(inp, reply=None): """fml -- Gets a random quote from fmyfife.com.""" # grab the last item in the fml cache and remove it - id, text = fml_cache.pop() + fml_id, text = fml_cache.pop() # reply with the fml we grabbed - reply('(#{}) {}'.format(id, text)) + reply('(#{}) {}'.format(fml_id, text)) # refresh fml cache if its getting empty if len(fml_cache) < 3: refresh_cache() diff --git a/plugins/metacritic.py b/plugins/metacritic.py index eb27114..e32059d 100644 --- a/plugins/metacritic.py +++ b/plugins/metacritic.py @@ -12,12 +12,8 @@ def metacritic(inp): """mc [all|movie|tv|album|x360|ps3|pc|gba|ds|3ds|wii|vita|wiiu|xone|ps4] Gets rating for <title> from metacritic on the specified medium.""" - - # if the results suck, it's metacritic's fault - args = inp.strip() - game_platforms = ('x360', 'ps3', 'pc', 'gba', 'ds', '3ds', 'wii', 'vita', 'wiiu', 'xone', 'ps4') @@ -76,7 +72,6 @@ def metacritic(inp): ''' # get the proper result element we want to pull data from - result = None if not doc.find_class('query_results'): diff --git a/plugins/minecraft_bukget.py b/plugins/minecraft_bukget.py index 3da5675..31895ad 100644 --- a/plugins/minecraft_bukget.py +++ b/plugins/minecraft_bukget.py @@ -13,7 +13,7 @@ details_url = base_url + "plugins/bukkit/{}" categories = http.get_json("http://api.bukget.org/3/categories") count_total = sum([cat["count"] for cat in categories]) -count_categores = {cat["name"].lower() : int(cat["count"]) for cat in categories} # dict conps! +count_categories = {cat["name"].lower() : int(cat["count"]) for cat in categories} # dict comps! class BukgetError(Exception): @@ -99,7 +99,8 @@ def format_output(data): else: line_a = u"\x02{}\x02, by \x02{}\x02 ({}) \x02{}".format(name, authors, stage, url) - line_b = u"Last release: \x02v{}\x02 for \x02{}\x02 at {} \x02{}\x02".format(version_number, bukkit_versions, last_update, link) + line_b = u"Last release: \x02v{}\x02 for \x02{}\x02 at {} \x02{}\x02".format(version_number, bukkit_versions, + last_update, link) return line_a, line_b diff --git a/plugins/minecraft_wiki.py b/plugins/minecraft_wiki.py index e699e7a..878f434 100644 --- a/plugins/minecraft_wiki.py +++ b/plugins/minecraft_wiki.py @@ -21,7 +21,7 @@ def mcwiki(inp): return "No results found." # we remove items with a '/' in the name, because - # gamepedia uses subpages for different languages + # gamepedia uses sub-pages for different languages # for some stupid reason items = [item for item in j[1] if not "/" in item] From a7e931541f602ef7bdc2674a3012fa3211843638 Mon Sep 17 00:00:00 2001 From: Luke Rogers <lukeroge@gmail.com> Date: Thu, 13 Feb 2014 20:07:01 +1300 Subject: [PATCH 05/16] Fixed mcping on windows :) --- plugins/minecraft_ping.py | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/plugins/minecraft_ping.py b/plugins/minecraft_ping.py index 423c714..0042278 100644 --- a/plugins/minecraft_ping.py +++ b/plugins/minecraft_ping.py @@ -106,7 +106,7 @@ def mcping_legacy(host, port): def get_srv_data(domain): """ takes a domain and finds minecraft SRV records """ - DNS.ParseResolvConf() + DNS.DiscoverNameServers() srv_req = DNS.Request(qtype='srv') srv_result = srv_req.req('_minecraft._tcp.{}'.format(domain)) @@ -137,10 +137,10 @@ def parse_input(inp): @hook.command("mcp6") def mcping6(inp): """mcping6 <server>[:port] - Ping a Minecraft server version 1.6 or smaller to check status.""" - try: - host, port = parse_input(inp) - except Exception as ex: - return ex.args[0] + #try: + host, port = parse_input(inp) + #except Exception as ex: + # return ex.args[0] try: return mcping_legacy(host, port) except: @@ -165,10 +165,12 @@ def mcping7(inp): @hook.command("mcp") def mcping(inp): """mcping <server>[:port] - Ping a Minecraft server to check status.""" - try: - host, port = parse_input(inp) - except Exception as e: - return e.args[0] + # try: + host, port = parse_input(inp) + #except Exception as e: + # return e.args[0] +# + try: return mcping_modern(host, port) From 136acd126d386c2c482c64489253b8333bb95d9c Mon Sep 17 00:00:00 2001 From: Luke Rogers <lukeroge@gmail.com> Date: Thu, 13 Feb 2014 20:47:47 +1300 Subject: [PATCH 06/16] Reduce line length --- plugins/cryptocoins.py | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/plugins/cryptocoins.py b/plugins/cryptocoins.py index 4973444..a29fce1 100644 --- a/plugins/cryptocoins.py +++ b/plugins/cryptocoins.py @@ -5,14 +5,17 @@ from util import http, hook exchanges = { "blockchain": { "api_url": "https://blockchain.info/ticker", - "func": lambda data: u"Blockchain // Buy: \x0307${:,.2f}\x0f - Sell: \x0307${:,.2f}\x0f".format(data["USD"]["buy"], \ - data["USD"]["sell"]) + "func": lambda data: u"Blockchain // Buy: \x0307${:,.2f}\x0f -" + u" Sell: \x0307${:,.2f}\x0f".format(data["USD"]["buy"], data["USD"]["sell"]) }, "mtgox": { "api_url": "https://mtgox.com/api/1/BTCUSD/ticker", - "func": lambda data: u"MtGox // Current: \x0307{}\x0f - High: \x0307{}\x0f - Low: \x0307{}\x0f - Best Ask: \x0307{}\x0f - Volume: {}".format(data['return']['last']['display'], \ - data['return']['high']['display'], data['return']['low']['display'], data['return']['buy']['display'], \ - data['return']['vol']['display']) + "func": lambda data: u"MtGox // Current: \x0307{}\x0f - High: \x0307{}\x0f - Low: \x0307{}\x0f" + u" - Best Ask: \x0307{}\x0f - Volume: {}".format(data['return']['last']['display'], + data['return']['high']['display'], + data['return']['low']['display'], + data['return']['buy']['display'], + data['return']['vol']['display']) }, "coinbase":{ "api_url": "https://coinbase.com/api/v1/prices/spot_rate", @@ -24,8 +27,11 @@ exchanges = { }, "bitstamp": { "api_url": "https://www.bitstamp.net/api/ticker/", - "func": lambda data: u"BitStamp // Current: \x0307${:,.2f}\x0f - High: \x0307${:,.2f}\x0f - Low: \x0307${:,.2f}\x0f - Volume: {:,.2f} BTC".format(float(data['last']), float(data['high']), float(data['low']), \ - float(data['volume'])) + "func": lambda data: u"BitStamp // Current: \x0307${:,.2f}\x0f - High: \x0307${:,.2f}\x0f -" + u" Low: \x0307${:,.2f}\x0f - Volume: {:,.2f} BTC".format(float(data['last']), + float(data['high']), + float(data['low']), + float(data['volume'])) } } @@ -59,4 +65,5 @@ def litecoin(inp, message=None): data = http.get_json("https://btc-e.com/api/2/ltc_usd/ticker") ticker = data['ticker'] message("Current: \x0307${:,.2f}\x0f - High: \x0307${:,.2f}\x0f" - " - Low: \x0307${:,.2f}\x0f - Volume: {:,.2f} LTC".format(ticker['buy'], ticker['high'], ticker['low'], ticker['vol_cur'])) + " - Low: \x0307${:,.2f}\x0f - Volume: {:,.2f} LTC".format(ticker['buy'], ticker['high'], ticker['low'], + ticker['vol_cur'])) From c21b358f9bb6211668649e75d971105401908983 Mon Sep 17 00:00:00 2001 From: Luke Rogers <lukeroge@gmail.com> Date: Thu, 13 Feb 2014 20:51:11 +1300 Subject: [PATCH 07/16] messing with dice --- plugins/dice.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/plugins/dice.py b/plugins/dice.py index f748da6..a89f3d5 100644 --- a/plugins/dice.py +++ b/plugins/dice.py @@ -14,7 +14,7 @@ sign_re = re.compile(r'[+-]?(?:\d*d)?(?:\d+|F)', re.I) split_re = re.compile(r'([\d+-]*)d?(F|\d*)', re.I) -def nrolls(count, n): +def n_rolls(count, n): """roll an n-sided die count times""" if n == "F": return [random.randint(-1, 1) for x in xrange(min(count, 100))] @@ -36,7 +36,7 @@ def nrolls(count, n): #@hook.regex(valid_diceroll, re.I) @hook.command def dice(inp): - """dice <diceroll> -- Simulates dicerolls. Example of <diceroll>: + """dice <dice roll> -- Simulates dice rolls. Example of <dice roll>: 'dice 2d20-d5+4 roll 2'. D20s, subtract 1D5, add 4""" try: # if inp is a re.match object... @@ -59,7 +59,7 @@ def dice(inp): count, side = split_re.match(roll).groups() count = int(count) if count not in " +-" else 1 if side.upper() == "F": # fudge dice are basically 1d3-2 - for fudge in nrolls(count, "F"): + for fudge in n_rolls(count, "F"): if fudge == 1: rolls.append("\x033+\x0F") elif fudge == -1: @@ -73,14 +73,15 @@ def dice(inp): side = int(side) try: if count > 0: - d = nrolls(count, side) + d = n_rolls(count, side) rolls += map(str, d) total += sum(d) else: - d = nrolls(-count, side) + d = n_rolls(-count, side) rolls += [str(-x) for x in d] total -= sum(d) except OverflowError: + # I have never seen this happen. If you make this happen, you win a cookie return "Thanks for overflowing a float, jerk >:[" if desc: From 289561e76af81d1d55aa5181bccd2703637a5144 Mon Sep 17 00:00:00 2001 From: Dabo Ross <daboross@daboross.net> Date: Sat, 18 Jan 2014 02:45:34 -0800 Subject: [PATCH 08/16] Resolve 'time' name conflicts --- plugins/{time.py => time_plugin.py} | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) rename plugins/{time.py => time_plugin.py} (89%) diff --git a/plugins/time.py b/plugins/time_plugin.py similarity index 89% rename from plugins/time.py rename to plugins/time_plugin.py index b508522..93dd2f2 100644 --- a/plugins/time.py +++ b/plugins/time_plugin.py @@ -16,10 +16,10 @@ def time_command(inp, bot=None): return "error: no wolfram alpha api key set" request = http.get_xml(api_url, input=query, appid=api_key) - time = " ".join(request.xpath("//pod[@title='Result']/subpod/plaintext/text()")) - time = time.replace(" | ", ", ") + current_time = " ".join(request.xpath("//pod[@title='Result']/subpod/plaintext/text()")) + current_time = current_time.replace(" | ", ", ") - if time: + if current_time: # nice place name for UNIX time if inp.lower() == "unix": place = "Unix Epoch" @@ -27,7 +27,7 @@ def time_command(inp, bot=None): place = capitalize_first(" ".join(request.xpath("//pod[@" "title='Input interpretation']/subpod/plaintext/text()"))[ 16:]) - return "{} - \x02{}\x02".format(time, place) + return "{} - \x02{}\x02".format(current_time, place) else: return "Could not get the time for '{}'.".format(inp) From 3a13621ae4253166a71b02fa1836dc18ea418576 Mon Sep 17 00:00:00 2001 From: Luke Rogers <lukeroge@gmail.com> Date: Thu, 13 Feb 2014 22:18:00 +1300 Subject: [PATCH 09/16] Delete puush.py --- plugins/puush.py | 49 ------------------------------------------------ 1 file changed, 49 deletions(-) delete mode 100644 plugins/puush.py diff --git a/plugins/puush.py b/plugins/puush.py deleted file mode 100644 index 015897d..0000000 --- a/plugins/puush.py +++ /dev/null @@ -1,49 +0,0 @@ -import urllib2 -import random -from util import hook - - -def make_string(): - stuff = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890" - string = random.choice("123") - for x in range(4): - string += random.choice(stuff) - return string - - -def check_url(code): - try: - urllib2.urlopen(make_url(code)) - return True - except: - return False # sorry <3 - - -def make_url(code): - return "http://puu.sh/{}".format(code) - - -@hook.command(autohelp=False) -def puush(inp): - """puush [1-5] -- Returns a number of random puu.sh entries.""" - out = "" - num = 0 - - if not inp: - inp = "1" - if not inp.isdigit(): - out += "Defaulting to one: " - num = 1 - elif int(inp[0]) > 5: - out += "Five images max: " - num = 5 - else: - num = int(inp[0]) - - images = [] - for x in xrange(num): - ran = make_string() - while not check_url(ran): - ran = make_string() - images.append(make_url(ran)) - return out + " ".join(images) From ada153c8bc322d0f2679b9d17aab3326978027f0 Mon Sep 17 00:00:00 2001 From: Luke Rogers <lukeroge@gmail.com> Date: Thu, 13 Feb 2014 23:21:07 +1300 Subject: [PATCH 10/16] Delete disabled_plugins --- disabled_plugins | 25 ------------------------- 1 file changed, 25 deletions(-) delete mode 100644 disabled_plugins diff --git a/disabled_plugins b/disabled_plugins deleted file mode 100644 index 9012dcc..0000000 --- a/disabled_plugins +++ /dev/null @@ -1,25 +0,0 @@ -import random -from util import hook, text - -@hook.command('harmon', autohelp=False) -@hook.command(autohelp=False) -def mark(inp): - """mark -- Spreads the glory of Mark Harmon""" - responses = [ - "Praise our lord Mark Harmon", - "Have you considered joining the Church of Mark Harmon?", - "M A R K H A R M O N", - "Did you know, Mark Harmon used to be a lifeguard?", - "Mark Harmon is our guide in these dark times.", - "Why not donate to the Church of Mark Harmon and help further our cause?", - "MERK HERMERN", - "Mark Harmon can cut through a hot knife with butter.", - "Mark Harmon can win a game of connect four in only three moves." - "PRAISE MARK HARMON", - "GLORY TO OUR LORD", - "Become a Mark Harmoner today and promote Mark Harmony!", - "The Church of Mark Harmon choir can achieve perfect Mark Harmony." - "Mark!" - ] - - return random.choice(responses) From ee0ad67a16032804dfab23b404c282b5fdf8030f Mon Sep 17 00:00:00 2001 From: Luke Rogers <lukeroge@gmail.com> Date: Fri, 14 Feb 2014 00:47:01 +1300 Subject: [PATCH 11/16] tidying! --- plugins/brainfuck.py | 4 ++-- plugins/fact.py | 10 +++++----- plugins/help.py | 2 +- plugins/hulu.py | 4 ++-- plugins/imgur.py | 2 +- plugins/isup.py | 2 +- plugins/metacritic.py | 30 ------------------------------ plugins/mlia.py | 2 +- plugins/newegg.py | 2 +- plugins/notes.py | 6 +++--- plugins/tell.py | 2 +- plugins/twitter.py | 5 ++++- plugins/utility.py | 2 +- requirements.txt | 1 + 14 files changed, 24 insertions(+), 50 deletions(-) diff --git a/plugins/brainfuck.py b/plugins/brainfuck.py index 1c68b57..a7dc12e 100644 --- a/plugins/brainfuck.py +++ b/plugins/brainfuck.py @@ -1,5 +1,5 @@ -'''brainfuck interpreter adapted from (public domain) code at -http://brainfuck.sourceforge.net/brain.py''' +"""brainfuck interpreter adapted from (public domain) code at +http://brainfuck.sourceforge.net/brain.py""" import re import random diff --git a/plugins/fact.py b/plugins/fact.py index ab05f17..1d48ae7 100644 --- a/plugins/fact.py +++ b/plugins/fact.py @@ -2,7 +2,7 @@ from util import hook, http, web @hook.command(autohelp=False) -def fact(inp, say=False, nick=False): +def fact(inp): """fact -- Gets a random fact from OMGFACTS.""" attempts = 0 @@ -20,10 +20,10 @@ def fact(inp, say=False, nick=False): response = soup.find('a', {'class': 'surprise'}) link = response['href'] - fact = ''.join(response.find(text=True)) + fact_data = ''.join(response.find(text=True)) - if fact: - fact = fact.strip() + if fact_data: + fact_data = fact_data.strip() break else: if attempts > 2: @@ -34,4 +34,4 @@ def fact(inp, say=False, nick=False): url = web.try_isgd(link) - return "{} - {}".format(fact, url) + return "{} - {}".format(fact_data, url) diff --git a/plugins/help.py b/plugins/help.py index 4a4fd47..08001a5 100644 --- a/plugins/help.py +++ b/plugins/help.py @@ -3,7 +3,7 @@ from util import hook @hook.command(autohelp=False) -def help(inp, notice=None, input=None, conn=None, bot=None): +def help(inp, notice=None, conn=None, bot=None): """help -- Gives a list of commands/help for a command.""" funcs = {} diff --git a/plugins/hulu.py b/plugins/hulu.py index 0b69788..46d31ee 100644 --- a/plugins/hulu.py +++ b/plugins/hulu.py @@ -10,7 +10,7 @@ def hulu_url(match): data = http.get_json("http://www.hulu.com/api/oembed.json?url=http://www.hulu.com" + match.group(3)) showname = data['title'].split("(")[-1].split(")")[0] title = data['title'].split(" (")[0] - return "{}: {} - {}".format(showname, title, timeformat.timeformat(int(data['duration']))) + return "{}: {} - {}".format(showname, title, timeformat.format_time(int(data['duration']))) @hook.command('hulu') @@ -21,7 +21,7 @@ def hulu_search(inp): data = result.find('results').find('videos').find('video') showname = data.find('show').find('name').text title = data.find('title').text - duration = timeformat.timeformat(int(float(data.find('duration').text))) + duration = timeformat.format_time(int(float(data.find('duration').text))) description = data.find('description').text rating = data.find('content-rating').text return "{}: {} - {} - {} ({}) {}".format(showname, title, description, duration, rating, diff --git a/plugins/imgur.py b/plugins/imgur.py index 80efbca..8db3b96 100644 --- a/plugins/imgur.py +++ b/plugins/imgur.py @@ -18,7 +18,7 @@ def is_valid(data): @hook.command(autohelp=False) def imgur(inp): - "imgur [subreddit] -- Gets the first page of imgur images from [subreddit] and returns a link to them. If [subreddit] is undefined, return any imgur images" + """imgur [subreddit] -- Gets the first page of imgur images from [subreddit] and returns a link to them. If [subreddit] is undefined, return any imgur images""" if inp: # see if the input ends with "nsfw" show_nsfw = inp.endswith(" nsfw") diff --git a/plugins/isup.py b/plugins/isup.py index 454b8f5..5fc95d6 100644 --- a/plugins/isup.py +++ b/plugins/isup.py @@ -5,7 +5,7 @@ from util import hook, http, urlnorm @hook.command def isup(inp): - "isup -- uses isup.me to see if a site is up or not" + """isup -- uses isup.me to see if a site is up or not""" # slightly overcomplicated, esoteric URL parsing scheme, auth, path, query, fragment = urlparse.urlsplit(inp.strip()) diff --git a/plugins/metacritic.py b/plugins/metacritic.py index e32059d..92d0933 100644 --- a/plugins/metacritic.py +++ b/plugins/metacritic.py @@ -41,36 +41,6 @@ def metacritic(inp): except HTTPError: return 'error fetching results' - ''' result format: - -- game result, with score - -- subsequent results are the same structure, without first_result class - <li class="result first_result"> - <div class="result_type"> - <strong>Game</strong> - <span class="platform">WII</span> - </div> - <div class="result_wrap"> - <div class="basic_stats has_score"> - <div class="main_stats"> - <h3 class="product_title basic_stat">...</h3> - <div class="std_score"> - <div class="score_wrap"> - <span class="label">Metascore: </span> - <span class="data metascore score_favorable">87</span> - </div> - </div> - </div> - <div class="more_stats extended_stats">...</div> - </div> - </div> - </li> - - -- other platforms are the same basic layout - -- if it doesn't have a score, there is no div.basic_score - -- the <div class="result_type"> changes content for non-games: - <div class="result_type"><strong>Movie</strong></div> - ''' - # get the proper result element we want to pull data from result = None diff --git a/plugins/mlia.py b/plugins/mlia.py index c155a3e..7153081 100644 --- a/plugins/mlia.py +++ b/plugins/mlia.py @@ -23,7 +23,7 @@ refresh_cache() @hook.command(autohelp=False) def mlia(inp, reply=None): - "mlia -- Gets a random quote from MyLifeIsAverage.com." + """mlia -- Gets a random quote from MyLifeIsAverage.com.""" # grab the last item in the mlia cache and remove it id, text = mlia_cache.pop() # reply with the mlia we grabbed diff --git a/plugins/newegg.py b/plugins/newegg.py index 76b2a70..00271f8 100644 --- a/plugins/newegg.py +++ b/plugins/newegg.py @@ -44,7 +44,7 @@ def format_item(item, show_url=True): tags.append("\x02Featured\x02") if item["IsShellShockerItem"]: - tags.append("\x02SHELL SHOCKER®\x02") + tags.append(u"\x02SHELL SHOCKER\u00AE\x02") # join all the tags together in a comma separated string ("tag1, tag2, tag3") tag_text = u", ".join(tags) diff --git a/plugins/notes.py b/plugins/notes.py index 6c6e450..ac85f48 100644 --- a/plugins/notes.py +++ b/plugins/notes.py @@ -4,7 +4,7 @@ import re db_inited = False -def cleanSQL(sql): +def clean_sql(sql): return re.sub(r'\s+', " ", sql).strip() @@ -20,7 +20,7 @@ def db_init(db): """).fetchone()[0] == 1 if not exists: - db.execute(cleanSQL(""" + db.execute(clean_sql(""" create virtual table todos using fts4( user, text, @@ -91,7 +91,7 @@ def db_search(db, nick, query): @hook.command("notes") @hook.command def note(inp, nick='', chan='', db=None, notice=None, bot=None): - "note(s) <add|del|list|search> args -- Manipulates your list of notes." + """note(s) <add|del|list|search> args -- Manipulates your list of notes.""" db_init(db) diff --git a/plugins/tell.py b/plugins/tell.py index 5e54c77..e8a06bb 100644 --- a/plugins/tell.py +++ b/plugins/tell.py @@ -50,7 +50,7 @@ def tellinput(paraml, input=None, notice=None, db=None, bot=None, nick=None, con @hook.command(autohelp=False) def showtells(inp, nick='', chan='', notice=None, db=None): - "showtells -- View all pending tell messages (sent in a notice)." + """showtells -- View all pending tell messages (sent in a notice).""" db_init(db) diff --git a/plugins/twitter.py b/plugins/twitter.py index 2ea8ab8..1499470 100644 --- a/plugins/twitter.py +++ b/plugins/twitter.py @@ -52,7 +52,7 @@ def twitter_url(match, bot=None): @hook.command("twatter") @hook.command def twitter(inp, bot=None): - "twitter <user> [n] -- Gets last/[n]th tweet from <user>" + """twitter <user> [n] -- Gets last/[n]th tweet from <user>""" api = get_api(bot) if not api: @@ -117,6 +117,9 @@ def twitter(inp, bot=None): tweet = random.choice(search) user = tweet.user + else: + # ??? + return "Unknown Error" text = " ".join(tweet.text.split()) diff --git a/plugins/utility.py b/plugins/utility.py index baa215b..c0a1659 100644 --- a/plugins/utility.py +++ b/plugins/utility.py @@ -89,7 +89,7 @@ def checkbase64(inp): recoded = decoded.encode('base64').strip() is_base64 = recoded == inp except: - is_base64 = False + return '"{}" is not base64 encoded'.format(inp) if is_base64: return '"{}" is base64 encoded'.format(recoded) diff --git a/requirements.txt b/requirements.txt index 94832f2..d436010 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,4 @@ +Crypto BeautifulSoup==3.2.1 lxml==3.1beta1 pyenchant==1.6.5 From 6169be6da1755e7bc68bd7ebca50438cf339d9fc Mon Sep 17 00:00:00 2001 From: Luke Rogers <lukeroge@gmail.com> Date: Fri, 14 Feb 2014 01:04:50 +1300 Subject: [PATCH 12/16] no message --- plugins/steam.py | 1 - 1 file changed, 1 deletion(-) diff --git a/plugins/steam.py b/plugins/steam.py index c18867d..cb7b9d5 100644 --- a/plugins/steam.py +++ b/plugins/steam.py @@ -53,7 +53,6 @@ def get_steam_info(url): data[title] = text continue - data["price"] = soup.find('div', {'class': 'game_purchase_price price'}).text.strip() return u"\x02{name}\x02: {desc}, \x02Genre\x02: {genre}, \x02Release Date\x02: {release date}," \ From 6086a7c6da89a5e36e006ddaad6f9b20d0c90f74 Mon Sep 17 00:00:00 2001 From: Dabo Ross <daboross@daboross.net> Date: Mon, 13 Jan 2014 23:18:39 -0800 Subject: [PATCH 13/16] Add per-channel regex filtering. --- plugins/regex_chans.py | 128 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 128 insertions(+) create mode 100644 plugins/regex_chans.py diff --git a/plugins/regex_chans.py b/plugins/regex_chans.py new file mode 100644 index 0000000..f49411a --- /dev/null +++ b/plugins/regex_chans.py @@ -0,0 +1,128 @@ +from util import hook + + +# Default value. +# If True, all channels without a setting will have regex enabled +# If False, all channels without a setting will have regex disabled +default_enabled = True + +db_already_initiated = False + + +def db_init(db): + global db_already_initiated + if not db_already_initiated: + db_already_initiated = True + db.execute("CREATE TABLE IF NOT EXISTS regexchans(channel PRIMARY KEY, status)") + db.commit() + + +def get_status(db, channel): + row = db.execute("SELECT status FROM regexchans WHERE channel = ?", [channel]).fetchone() + if row: + return row[0] + else: + return None + + +def set_status(db, channel, status): + row = db.execute("REPLACE INTO regexchans (channel, status) VALUES(?, ?)", [channel, status]) + db.commit() + + +def delete_status(db, channel): + row = db.execute("DELETE FROM regexchans WHERE channel = ?", [channel]) + db.commit() + + +def list_status(db): + row = db.execute("SELECT * FROM regexchans").fetchall() + result = None + for values in row: + if result: + result += u", {}: {}".format(values[0], values[1]) + else: + result = u"{}: {}".format(values[0], values[1]) + return result + + +@hook.sieve +def sieve_regex(bot, inp, func, kind, args): + db = bot.get_db_connection(inp.conn) + db_init(db) + if kind == 'regex' and inp.chan.startswith("#") and func.__name__ != 'factoid': + chanstatus = get_status(db, inp.chan) + if chanstatus != "ENABLED" and (chanstatus == "DISABLED" or not default_enabled): + print u"Denying input.raw={}, kind={}, args={} from {}".format(inp.raw, kind, args, inp.chan) + return None + print u"Allowing input.raw={}, kind={}, args={} from {}".format(inp.raw, kind, args, inp.chan) + + return inp + + +@hook.command(permissions=["botcontrol"]) +def enableregex(inp, db=None, message=None, notice=None, chan=None, nick=None): + db_init(db) + inp = inp.strip().lower() + if not inp: + channel = chan + elif inp.startswith("#"): + channel = inp + else: + channel = u"#{}".format(inp) + + message(u"Enabling regex matching (youtube, etc) (issued by {})".format(nick), target=channel) + notice(u"Enabling regex matching (youtube, etc) in channel {}".format(channel)) + set_status(db, channel, "ENABLED") + + +@hook.command(permissions=["botcontrol"]) +def disableregex(inp, db=None, message=None, notice=None, chan=None, nick=None): + db_init(db) + inp = inp.strip().lower() + if not inp: + channel = chan + elif inp.startswith("#"): + channel = inp + else: + channel = u"#{}".format(inp) + + message(u"Disabling regex matching (youtube, etc) (issued by {})".format(nick), target=channel) + notice(u"Disabling regex matching (youtube, etc) in channel {}".format(channel)) + set_status(db, channel, "DISABLED") + + +@hook.command(permissions=["botcontrol"]) +def resetregex(inp, db=None, message=None, notice=None, chan=None, nick=None): + db_init(db) + inp = inp.strip().lower() + if not inp: + channel = chan + elif inp.startswith("#"): + channel = inp + else: + channel = u"#{}".format(inp) + + message(u"Resetting regex matching setting (youtube, etc) (issued by {})".format(nick), target=channel) + notice(u"Resetting regex matching setting (youtube, etc) in channel {}".format(channel)) + delete_status(db, channel) + + +@hook.command(permissions=["botcontrol"]) +def regexstatus(inp, db=None, chan=None): + db_init(db) + inp = inp.strip().lower() + if not inp: + channel = chan + elif inp.startswith("#"): + channel = inp + else: + channel = u"#{}".format(inp) + + return u"Regex status for {}: {}".format(channel, get_status(db, channel)) + + +@hook.command(permissions=["botcontrol"]) +def listregex(inp, db=None): + db_init(db) + return list_status(db) From b4d7e200a36d0fb33787362e6e906437e8644cbb Mon Sep 17 00:00:00 2001 From: Luke Rogers <lukeroge@gmail.com> Date: Fri, 14 Feb 2014 16:21:00 +1300 Subject: [PATCH 14/16] Tweaks, improved reddit --- plugins/data/kills.json | 154 +++++++++++++++++++------------------- plugins/reddit.py | 6 +- plugins/rottentomatoes.py | 2 +- 3 files changed, 82 insertions(+), 80 deletions(-) diff --git a/plugins/data/kills.json b/plugins/data/kills.json index b657209..5f6d046 100644 --- a/plugins/data/kills.json +++ b/plugins/data/kills.json @@ -1,79 +1,79 @@ { - "templates":[ - "rips off {user}'s {limbs} and leaves them to die.", - "grabs {user}'s head and rips it clean off their body.", - "grabs a {gun} and riddles {user}'s body with bullets.", - "gags and ties {user} then throws them off a {tall_thing}.", - "crushes {user} with a huge spiked {spiked_thing}.", - "glares at {user} until they die of boredom.", - "stabs {user} in the heart a few times with a {weapon_stab}.", - "rams a {weapon_explosive} up {user}'s ass and lets off a few rounds.", - "crushes {user}'s skull in with a {weapon_crush}.", - "unleashes the armies of Isengard on {user}.", - "gags and ties {user} then throws them off a {tall_thing} to their death.", - "reaches out and punches right through {user}'s chest.", - "slices {user}'s limbs off with a {weapon_slice}.", - "throws {user} to Cthulu and watches them get ripped to shreds.", - "feeds {user} to an owlbear who then proceeds to maul them violently.", - "turns {user} into a snail and covers then in salt.", - "snacks on {user}'s dismembered body.", - "stuffs {bomb} up {user}'s ass and waits for it to go off.", - "puts {user} into a sack, throws the sack in the river, and hurls the river into space.", - "goes bowling with {user}'s bloody disembodied head.", - "sends {user} to /dev/null!", - "feeds {user} coke and mentos till they violently explode." - ], - "parts": { - "gun":[ - "AK47", - "machine gun", - "automatic pistol", - "Uzi" - ], - "limbs": [ - "legs", - "arms", - "limbs" - ], - "weapon_stab": [ - "knife", - "shard of glass", - "sword blade", - "butchers knife", - "corkscrew" - ], - "weapon_slice": [ - "sharpened katana", - "chainsaw", - "polished axe" - ], - "weapon_crush": [ - "spiked mace", - "baseball bat", - "wooden club", - "massive steel ball", - "heavy iron rod" - ], - "weapon_explosive": [ - "rocket launcher", - "grenade launcher", - "napalm launcher" - ], - "tall_thing": [ - "bridge", - "tall building", - "cliff", - "mountain" - ], - "spiked_thing": [ - "boulder", - "rock", - "barrel of rocks" - ], - "bomb": [ - "a bomb", - "some TNT", - "a bunch of C4" - ] - } + "templates": [ + "rips off {user}'s {limbs} and leaves them to die.", + "grabs {user}'s head and rips it clean off their body.", + "grabs a {gun} and riddles {user}'s body with bullets.", + "gags and ties {user} then throws them off a {tall_thing}.", + "crushes {user} with a huge spiked {spiked_thing}.", + "glares at {user} until they die of boredom.", + "stabs {user} in the heart a few times with a {weapon_stab}.", + "rams a {weapon_explosive} up {user}'s ass and lets off a few rounds.", + "crushes {user}'s skull in with a {weapon_crush}.", + "unleashes the armies of Isengard on {user}.", + "gags and ties {user} then throws them off a {tall_thing} to their death.", + "reaches out and punches right through {user}'s chest.", + "slices {user}'s limbs off with a {weapon_slice}.", + "throws {user} to Cthulu and watches them get ripped to shreds.", + "feeds {user} to an owlbear who then proceeds to maul them violently.", + "turns {user} into a snail and covers then in salt.", + "snacks on {user}'s dismembered body.", + "stuffs {bomb} up {user}'s ass and waits for it to go off.", + "puts {user} into a sack, throws the sack in the river, and hurls the river into space.", + "goes bowling with {user}'s bloody disembodied head.", + "sends {user} to /dev/null!", + "feeds {user} coke and mentos till they violently explode." + ], + "parts": { + "gun": [ + "AK47", + "machine gun", + "automatic pistol", + "Uzi" + ], + "limbs": [ + "legs", + "arms", + "limbs" + ], + "weapon_stab": [ + "knife", + "shard of glass", + "sword blade", + "butchers knife", + "corkscrew" + ], + "weapon_slice": [ + "sharpened katana", + "chainsaw", + "polished axe" + ], + "weapon_crush": [ + "spiked mace", + "baseball bat", + "wooden club", + "massive steel ball", + "heavy iron rod" + ], + "weapon_explosive": [ + "rocket launcher", + "grenade launcher", + "napalm launcher" + ], + "tall_thing": [ + "bridge", + "tall building", + "cliff", + "mountain" + ], + "spiked_thing": [ + "boulder", + "rock", + "barrel of rocks" + ], + "bomb": [ + "a bomb", + "some TNT", + "a bunch of C4" + ] + } } diff --git a/plugins/reddit.py b/plugins/reddit.py index add83d1..80fcb76 100644 --- a/plugins/reddit.py +++ b/plugins/reddit.py @@ -1,9 +1,11 @@ -from util import hook, http, text, timesince from datetime import datetime import re import random -reddit_re = (r'.*((www\.)?reddit\.com/r[^ ]+)', re.I) +from util import hook, http, text, timesince + + +reddit_re = (r'.*(((www\.)?reddit\.com/r|redd\.it)[^ ]+)', re.I) base_url = "http://reddit.com/r/{}/.json" short_url = "http://redd.it/{}" diff --git a/plugins/rottentomatoes.py b/plugins/rottentomatoes.py index 34e50d8..fae99dd 100644 --- a/plugins/rottentomatoes.py +++ b/plugins/rottentomatoes.py @@ -36,4 +36,4 @@ def rottentomatoes(inp, bot=None): rotten = review_count - fresh return u"{} - Critics Rating: \x02{}%\x02 ({} liked, {} disliked) " \ - "Audience Rating: \x02{}%\x02 - {}".format(title, critics_score, fresh, rotten, audience_score, url) + "Audience Rating: \x02{}%\x02 - {}".format(title, critics_score, fresh, rotten, audience_score, url) From 4447e6cd1f9b79829d2ce3e3b8db152afb783a51 Mon Sep 17 00:00:00 2001 From: Luke Rogers <lukeroge@gmail.com> Date: Fri, 14 Feb 2014 16:30:38 +1300 Subject: [PATCH 15/16] more little things --- disabled_stuff/mygengo_translate.py | 2 +- plugins/minecraft_bukget.py | 4 ++-- plugins/minecraft_items.py | 26 +++++++++++++------------- plugins/minecraft_ping.py | 1 + plugins/mlia.py | 4 ++-- plugins/password.py | 3 ++- plugins/ping.py | 1 + plugins/potato.py | 2 +- plugins/qrcode.py | 4 ++-- 9 files changed, 25 insertions(+), 22 deletions(-) diff --git a/disabled_stuff/mygengo_translate.py b/disabled_stuff/mygengo_translate.py index d61ab14..6e7b006 100644 --- a/disabled_stuff/mygengo_translate.py +++ b/disabled_stuff/mygengo_translate.py @@ -1,7 +1,7 @@ # BING translation plugin by Lukeroge and neersighted from util import hook from util import http -import re +import re import htmlentitydefs import mygengo diff --git a/plugins/minecraft_bukget.py b/plugins/minecraft_bukget.py index 31895ad..1222020 100644 --- a/plugins/minecraft_bukget.py +++ b/plugins/minecraft_bukget.py @@ -13,7 +13,7 @@ details_url = base_url + "plugins/bukkit/{}" categories = http.get_json("http://api.bukget.org/3/categories") count_total = sum([cat["count"] for cat in categories]) -count_categories = {cat["name"].lower() : int(cat["count"]) for cat in categories} # dict comps! +count_categories = {cat["name"].lower(): int(cat["count"]) for cat in categories} # dict comps! class BukgetError(Exception): @@ -88,7 +88,7 @@ def format_output(data): current_version = data['versions'][0] last_update = time.strftime('%d %B %Y %H:%M', - time.gmtime(current_version['date'])) + time.gmtime(current_version['date'])) version_number = data['versions'][0]['version'] bukkit_versions = ", ".join(current_version['game_versions']) diff --git a/plugins/minecraft_items.py b/plugins/minecraft_items.py index 97a6420..2031b14 100644 --- a/plugins/minecraft_items.py +++ b/plugins/minecraft_items.py @@ -42,29 +42,29 @@ with open("plugins/data/itemids.txt") as f: if line.startswith("//"): continue parts = line.strip().split() - id = parts[0] + itemid = parts[0] name = " ".join(parts[1:]) - ids.append((id, name)) + ids.append((itemid, name)) @hook.command("mcid") @hook.command -def mcitem(input, reply=None): +def mcitem(inp, reply=None): """mcitem <item/id> -- gets the id from an item or vice versa""" - input = input.lower().strip() + inp = inp.lower().strip() - if input == "": + if inp == "": reply("error: no input.") return results = [] - for id, name in ids: - if input == id: - results = ["\x02[{}]\x02 {}".format(id, name)] + for item_id, item_name in ids: + if inp == item_id: + results = ["\x02[{}]\x02 {}".format(item_id, item_name)] break - elif input in name.lower(): - results.append("\x02[{}]\x02 {}".format(id, name)) + elif inp in item_name.lower(): + results.append("\x02[{}]\x02 {}".format(item_id, item_name)) if not results: return "No matches found." @@ -80,12 +80,12 @@ def mcitem(input, reply=None): @hook.command("mccraft") @hook.command -def mcrecipe(input, reply=None): +def mcrecipe(inp, reply=None): """mcrecipe <item> -- gets the crafting recipe for an item""" - input = input.lower().strip() + inp = inp.lower().strip() results = [recipe.line for recipe in recipelist - if input in recipe.output] + if inp in recipe.output] if not results: return "No matches found." diff --git a/plugins/minecraft_ping.py b/plugins/minecraft_ping.py index 0042278..d7693da 100644 --- a/plugins/minecraft_ping.py +++ b/plugins/minecraft_ping.py @@ -1,3 +1,4 @@ +# TODO: Rewrite this whole mess from util import hook import socket import struct diff --git a/plugins/mlia.py b/plugins/mlia.py index 7153081..b44211b 100644 --- a/plugins/mlia.py +++ b/plugins/mlia.py @@ -25,9 +25,9 @@ refresh_cache() def mlia(inp, reply=None): """mlia -- Gets a random quote from MyLifeIsAverage.com.""" # grab the last item in the mlia cache and remove it - id, text = mlia_cache.pop() + mlia_id, text = mlia_cache.pop() # reply with the mlia we grabbed - reply('({}) {}'.format(id, text)) + reply('({}) {}'.format(mlia_id, text)) # refresh mlia cache if its getting empty if len(mlia_cache) < 3: refresh_cache() diff --git a/plugins/password.py b/plugins/password.py index 2187302..3fc6c45 100644 --- a/plugins/password.py +++ b/plugins/password.py @@ -1,4 +1,5 @@ -# based on password generation code by TheNoodle +# TODO: Add some kind of pronounceable password generation +# TODO: Improve randomness from util import hook import string import random diff --git a/plugins/ping.py b/plugins/ping.py index 746ea05..14b8787 100644 --- a/plugins/ping.py +++ b/plugins/ping.py @@ -13,6 +13,7 @@ def ping(inp, reply=None): if os.name == "nt": return "Sorry, this command is not supported on Windows systems." + # TODO: Rewrite this entire command to work on Windows, somehow args = inp.split(' ') host = args[0] diff --git a/plugins/potato.py b/plugins/potato.py index 4eb2e98..05eb00b 100644 --- a/plugins/potato.py +++ b/plugins/potato.py @@ -51,4 +51,4 @@ def potato(inp, action=None, input=None): side_dish = random.choice(['side salad', 'dollop of sour cream', 'piece of chicken', 'bowl of shredded bacon']) action("{} a {} {} {} potato for {} and serves it with a small {}!".format(method, flavor, size, potato_type, inp, - side_dish)) + side_dish)) diff --git a/plugins/qrcode.py b/plugins/qrcode.py index f14437f..9d481e0 100644 --- a/plugins/qrcode.py +++ b/plugins/qrcode.py @@ -8,9 +8,9 @@ def qrcode(inp): """qrcode [link] returns a link for a QR code.""" args = { - "cht": "qr", # chart type + "cht": "qr", # chart type (QR) "chs": "200x200", # dimensions - "chl": inp + "chl": inp # data } link = http.prepare_url("http://chart.googleapis.com/chart", args) From a76ff29d4bc03b33e3d6b9874a5783a3c92bc6ec Mon Sep 17 00:00:00 2001 From: Luke Rogers <lukeroge@gmail.com> Date: Fri, 14 Feb 2014 16:36:57 +1300 Subject: [PATCH 16/16] Tidy Imports --- plugins/admin.py | 3 ++- plugins/attacks.py | 4 +++- plugins/coin.py | 3 ++- plugins/core_ctcp.py | 2 ++ plugins/core_misc.py | 1 + plugins/core_sieve.py | 2 +- plugins/cypher.py | 1 + plugins/dictionary.py | 1 + plugins/drama.py | 4 +++- plugins/eightball.py | 2 ++ plugins/encrypt.py | 12 +++++++----- plugins/factoids.py | 4 +++- plugins/fishbans.py | 4 +++- plugins/fortune.py | 4 +++- plugins/geoip.py | 7 +++++-- plugins/github.py | 4 +++- plugins/google.py | 1 + plugins/google_translate.py | 1 + plugins/help.py | 1 + plugins/hulu.py | 4 +++- plugins/ignore.py | 3 ++- plugins/imdb.py | 4 +++- plugins/imgur.py | 3 ++- plugins/kernel.py | 3 ++- plugins/kill.py | 3 ++- plugins/lastfm.py | 4 +++- plugins/minecraft_bukget.py | 4 +++- plugins/minecraft_items.py | 4 +++- plugins/minecraft_ping.py | 4 +++- plugins/minecraft_status.py | 3 ++- plugins/minecraft_wiki.py | 4 +++- plugins/mlia.py | 1 + plugins/namegen.py | 3 ++- plugins/newegg.py | 4 +++- plugins/newgrounds.py | 2 ++ plugins/notes.py | 4 +++- plugins/osrc.py | 4 +++- plugins/password.py | 3 ++- plugins/ping.py | 4 +++- plugins/potato.py | 4 +++- plugins/pre.py | 3 ++- plugins/rdio.py | 4 +++- plugins/seen.py | 1 + plugins/slap.py | 3 ++- plugins/slogan.py | 3 ++- plugins/soundcloud.py | 4 +++- plugins/spellcheck.py | 5 +++-- plugins/spotify.py | 2 +- plugins/steam.py | 4 +++- plugins/steam_calc.py | 4 +++- plugins/system.py | 3 ++- plugins/time_plugin.py | 4 +++- plugins/title.py | 3 ++- plugins/tvdb.py | 1 + plugins/twitch.py | 4 +++- plugins/twitter.py | 7 +++++-- plugins/urban.py | 4 +++- plugins/utility.py | 4 +++- plugins/valvesounds.py | 3 ++- 59 files changed, 145 insertions(+), 54 deletions(-) diff --git a/plugins/admin.py b/plugins/admin.py index 7813b64..b90d4aa 100644 --- a/plugins/admin.py +++ b/plugins/admin.py @@ -1,4 +1,3 @@ -from util import hook import os import sys import re @@ -6,6 +5,8 @@ import json import time import subprocess +from util import hook + @hook.command(autohelp=False, permissions=["permissions_users"]) def permissions(inp, bot=None, notice=None): diff --git a/plugins/attacks.py b/plugins/attacks.py index 643a184..feb00b8 100644 --- a/plugins/attacks.py +++ b/plugins/attacks.py @@ -1,6 +1,8 @@ -from util import hook import random +from util import hook + + with open("plugins/data/larts.txt") as f: larts = [line.strip() for line in f.readlines() if not line.startswith("//")] diff --git a/plugins/coin.py b/plugins/coin.py index 104b3a7..7cc2a2a 100644 --- a/plugins/coin.py +++ b/plugins/coin.py @@ -1,6 +1,7 @@ -from util import hook import random +from util import hook + @hook.command(autohelp=False) def coin(inp, action=None): diff --git a/plugins/core_ctcp.py b/plugins/core_ctcp.py index 4f399f6..23834db 100644 --- a/plugins/core_ctcp.py +++ b/plugins/core_ctcp.py @@ -1,7 +1,9 @@ import time + from util import hook + # CTCP responses @hook.regex(r'^\x01VERSION\x01$') def ctcp_version(inp, notice=None): diff --git a/plugins/core_misc.py b/plugins/core_misc.py index bd71870..c1fafca 100644 --- a/plugins/core_misc.py +++ b/plugins/core_misc.py @@ -4,6 +4,7 @@ import re from util import hook + socket.setdefaulttimeout(10) nick_re = re.compile(":(.+?)!") diff --git a/plugins/core_sieve.py b/plugins/core_sieve.py index 4a6c809..9d41c54 100644 --- a/plugins/core_sieve.py +++ b/plugins/core_sieve.py @@ -1,7 +1,7 @@ import re +from fnmatch import fnmatch from util import hook -from fnmatch import fnmatch @hook.sieve diff --git a/plugins/cypher.py b/plugins/cypher.py index 55bea8c..b54248a 100644 --- a/plugins/cypher.py +++ b/plugins/cypher.py @@ -1,4 +1,5 @@ import base64 + from util import hook diff --git a/plugins/dictionary.py b/plugins/dictionary.py index ca74c36..b13db4b 100644 --- a/plugins/dictionary.py +++ b/plugins/dictionary.py @@ -1,5 +1,6 @@ # Plugin by GhettoWizard and Scaevolus import re + from util import hook from util import http diff --git a/plugins/drama.py b/plugins/drama.py index 351c5c8..d348cba 100644 --- a/plugins/drama.py +++ b/plugins/drama.py @@ -1,6 +1,8 @@ -from util import hook, http, text import re +from util import hook, http, text + + api_url = "http://encyclopediadramatica.se/api.php?action=opensearch" ed_url = "http://encyclopediadramatica.se/" diff --git a/plugins/eightball.py b/plugins/eightball.py index 0e039fb..8d91303 100644 --- a/plugins/eightball.py +++ b/plugins/eightball.py @@ -1,6 +1,8 @@ import random + from util import hook, text + color_codes = { "<r>": "\x02\x0305", "<g>": "\x02\x0303", diff --git a/plugins/encrypt.py b/plugins/encrypt.py index 7dccbf3..483ed48 100644 --- a/plugins/encrypt.py +++ b/plugins/encrypt.py @@ -1,13 +1,15 @@ -from util import hook -from Crypto import Random -from Crypto.Cipher import AES -from Crypto.Protocol.KDF import PBKDF2 - import os import base64 import json import hashlib +from Crypto import Random +from Crypto.Cipher import AES +from Crypto.Protocol.KDF import PBKDF2 + +from util import hook + + # helper functions to pad and unpad a string to a specified block size # <http://stackoverflow.com/questions/12524994/encrypt-decrypt-using-pycrypto-aes-256> BS = AES.block_size diff --git a/plugins/factoids.py b/plugins/factoids.py index 1d90e66..a924bf1 100644 --- a/plugins/factoids.py +++ b/plugins/factoids.py @@ -1,8 +1,10 @@ # Written by Scaevolus 2010 -from util import hook, http, text, pyexec import string import re +from util import hook, http, text, pyexec + + re_lineends = re.compile(r'[\r\n]*') # some simple "shortcodes" for formatting purposes diff --git a/plugins/fishbans.py b/plugins/fishbans.py index 7afe5e2..aa76676 100644 --- a/plugins/fishbans.py +++ b/plugins/fishbans.py @@ -1,6 +1,8 @@ -from util import hook, http from urllib import quote_plus +from util import hook, http + + api_url = "http://api.fishbans.com/stats/{}/" diff --git a/plugins/fortune.py b/plugins/fortune.py index c32efcb..5f1c478 100644 --- a/plugins/fortune.py +++ b/plugins/fortune.py @@ -1,6 +1,8 @@ -from util import hook import random +from util import hook + + with open("plugins/data/fortunes.txt") as f: fortunes = [line.strip() for line in f.readlines() if not line.startswith("//")] diff --git a/plugins/geoip.py b/plugins/geoip.py index a4fab57..172c90a 100644 --- a/plugins/geoip.py +++ b/plugins/geoip.py @@ -1,10 +1,13 @@ -from util import hook, http import os.path -import pygeoip import json import gzip from StringIO import StringIO +import pygeoip + +from util import hook, http + + # load region database with open("./plugins/data/geoip_regions.json", "rb") as f: diff --git a/plugins/github.py b/plugins/github.py index 025dc72..18033ef 100644 --- a/plugins/github.py +++ b/plugins/github.py @@ -1,7 +1,9 @@ -from util import hook, http import json import urllib2 +from util import hook, http + + shortcuts = {"cloudbot": "ClouDev/CloudBot"} diff --git a/plugins/google.py b/plugins/google.py index ebf6209..fe9e288 100644 --- a/plugins/google.py +++ b/plugins/google.py @@ -1,4 +1,5 @@ import random + from util import hook, http, text diff --git a/plugins/google_translate.py b/plugins/google_translate.py index 955cb53..a9d4ea3 100644 --- a/plugins/google_translate.py +++ b/plugins/google_translate.py @@ -8,6 +8,7 @@ import re from util import hook, http + max_length = 100 diff --git a/plugins/help.py b/plugins/help.py index 08001a5..805ab15 100644 --- a/plugins/help.py +++ b/plugins/help.py @@ -1,4 +1,5 @@ import re + from util import hook diff --git a/plugins/hulu.py b/plugins/hulu.py index 46d31ee..74e6b00 100644 --- a/plugins/hulu.py +++ b/plugins/hulu.py @@ -1,7 +1,9 @@ -from util import hook, http, timeformat from urllib import urlencode import re +from util import hook, http, timeformat + + hulu_re = (r'(.*://)(www.hulu.com|hulu.com)(.*)', re.I) diff --git a/plugins/ignore.py b/plugins/ignore.py index dc3f382..3bafbfb 100644 --- a/plugins/ignore.py +++ b/plugins/ignore.py @@ -1,7 +1,8 @@ import json -from util import hook from fnmatch import fnmatch +from util import hook + @hook.sieve def ignore_sieve(bot, input, func, type, args): diff --git a/plugins/imdb.py b/plugins/imdb.py index f7a0223..a577a9d 100644 --- a/plugins/imdb.py +++ b/plugins/imdb.py @@ -1,8 +1,10 @@ # IMDb lookup plugin by Ghetto Wizard (2011) and blha303 (2013) -from util import hook, http, text import re +from util import hook, http, text + + id_re = re.compile("tt\d+") imdb_re = (r'(.*:)//(imdb.com|www.imdb.com)(:[0-9]+)?(.*)', re.I) diff --git a/plugins/imgur.py b/plugins/imgur.py index 8db3b96..603f106 100644 --- a/plugins/imgur.py +++ b/plugins/imgur.py @@ -1,7 +1,8 @@ -from util import hook, http, web import re import random +from util import hook, http, web + base_url = "http://reddit.com/r/{}/.json" imgur_re = re.compile(r'http://(?:i\.)?imgur\.com/(a/)?(\w+\b(?!/))\.?\w?') diff --git a/plugins/kernel.py b/plugins/kernel.py index 7ade46e..90cbed5 100644 --- a/plugins/kernel.py +++ b/plugins/kernel.py @@ -1,6 +1,7 @@ -from util import hook, http import re +from util import hook, http + @hook.command(autohelp=False) def kernel(inp, reply=None): diff --git a/plugins/kill.py b/plugins/kill.py index d264682..d25228e 100644 --- a/plugins/kill.py +++ b/plugins/kill.py @@ -1,6 +1,7 @@ -from util import hook, textgen import json +from util import hook, textgen + def get_generator(_json, variables): data = json.loads(_json) diff --git a/plugins/lastfm.py b/plugins/lastfm.py index 4f56ee3..f126dbe 100644 --- a/plugins/lastfm.py +++ b/plugins/lastfm.py @@ -1,6 +1,8 @@ -from util import hook, http, timesince from datetime import datetime +from util import hook, http, timesince + + api_url = "http://ws.audioscrobbler.com/2.0/?format=json" diff --git a/plugins/minecraft_bukget.py b/plugins/minecraft_bukget.py index 1222020..352d5d8 100644 --- a/plugins/minecraft_bukget.py +++ b/plugins/minecraft_bukget.py @@ -1,7 +1,9 @@ -from util import hook, http, web, text import time import random +from util import hook, http, web, text + + ## CONSTANTS base_url = "http://api.bukget.org/3/" diff --git a/plugins/minecraft_items.py b/plugins/minecraft_items.py index 2031b14..f1e94f9 100644 --- a/plugins/minecraft_items.py +++ b/plugins/minecraft_items.py @@ -1,9 +1,11 @@ """ plugin by _303 (?) """ -from util import hook import re +from util import hook + + pattern = re.compile(r'^(?P<count>\d+)x (?P<name>.+?): (?P<ingredients>.*)$') recipelist = [] diff --git a/plugins/minecraft_ping.py b/plugins/minecraft_ping.py index d7693da..4ffb318 100644 --- a/plugins/minecraft_ping.py +++ b/plugins/minecraft_ping.py @@ -1,9 +1,11 @@ # TODO: Rewrite this whole mess -from util import hook import socket import struct import json +from util import hook + + try: import DNS # Please remember to install the dependancy 'pydns' diff --git a/plugins/minecraft_status.py b/plugins/minecraft_status.py index 98fce4a..8bb7e07 100644 --- a/plugins/minecraft_status.py +++ b/plugins/minecraft_status.py @@ -1,6 +1,7 @@ -from util import hook, http import json +from util import hook, http + @hook.command(autohelp=False) def mcstatus(inp): diff --git a/plugins/minecraft_wiki.py b/plugins/minecraft_wiki.py index 878f434..072a8ac 100644 --- a/plugins/minecraft_wiki.py +++ b/plugins/minecraft_wiki.py @@ -1,6 +1,8 @@ -from util import hook, http, text import re +from util import hook, http, text + + api_url = "http://minecraft.gamepedia.com/api.php?action=opensearch" mc_url = "http://minecraft.gamepedia.com/" diff --git a/plugins/mlia.py b/plugins/mlia.py index b44211b..feea642 100644 --- a/plugins/mlia.py +++ b/plugins/mlia.py @@ -1,6 +1,7 @@ # Plugin by Infinity - <https://github.com/infinitylabs/UguuBot> import random + from util import hook, http diff --git a/plugins/namegen.py b/plugins/namegen.py index 0a95f36..7a1f0e6 100644 --- a/plugins/namegen.py +++ b/plugins/namegen.py @@ -1,7 +1,8 @@ -from util import hook, text, textgen import json import os +from util import hook, text, textgen + GEN_DIR = "./plugins/data/name_files/" diff --git a/plugins/newegg.py b/plugins/newegg.py index 00271f8..68d604d 100644 --- a/plugins/newegg.py +++ b/plugins/newegg.py @@ -1,7 +1,9 @@ -from util import hook, http, text, web import json import re +from util import hook, http, text, web + + ## CONSTANTS ITEM_URL = "http://www.newegg.com/Product/Product.aspx?Item={}" diff --git a/plugins/newgrounds.py b/plugins/newgrounds.py index 7bfdb97..b26ffe4 100644 --- a/plugins/newgrounds.py +++ b/plugins/newgrounds.py @@ -1,6 +1,8 @@ import re + from util import hook, http + newgrounds_re = (r'(.*:)//(www.newgrounds.com|newgrounds.com)(:[0-9]+)?(.*)', re.I) valid = set('0123456789') diff --git a/plugins/notes.py b/plugins/notes.py index ac85f48..63a671c 100644 --- a/plugins/notes.py +++ b/plugins/notes.py @@ -1,6 +1,8 @@ -from util import hook import re +from util import hook + + db_inited = False diff --git a/plugins/osrc.py b/plugins/osrc.py index e2a2006..7df2085 100644 --- a/plugins/osrc.py +++ b/plugins/osrc.py @@ -1,6 +1,8 @@ -from util import hook, http, web from bs4 import BeautifulSoup +from util import hook, http, web + + api_url = "http://osrc.dfm.io/{}/stats" user_url = "http://osrc.dfm.io/{}" diff --git a/plugins/password.py b/plugins/password.py index 3fc6c45..34a379b 100644 --- a/plugins/password.py +++ b/plugins/password.py @@ -1,9 +1,10 @@ # TODO: Add some kind of pronounceable password generation # TODO: Improve randomness -from util import hook import string import random +from util import hook + @hook.command def password(inp, notice=None): diff --git a/plugins/ping.py b/plugins/ping.py index 14b8787..f5127d0 100644 --- a/plugins/ping.py +++ b/plugins/ping.py @@ -1,9 +1,11 @@ # ping plugin by neersighted -from util import hook import subprocess import re import os +from util import hook + + ping_regex = re.compile(r"(\d+.\d+)/(\d+.\d+)/(\d+.\d+)/(\d+.\d+)") diff --git a/plugins/potato.py b/plugins/potato.py index 05eb00b..dbef4ec 100644 --- a/plugins/potato.py +++ b/plugins/potato.py @@ -1,8 +1,10 @@ # coding=utf-8 -from util import hook import re import random +from util import hook + + potatoes = ['AC Belmont', 'AC Blue Pride', 'AC Brador', 'AC Chaleur', 'AC Domino', 'AC Dubuc', 'AC Glacier Chip', 'AC Maple Gold', 'AC Novachip', 'AC Peregrine Red', 'AC Ptarmigan', 'AC Red Island', 'AC Saguenor', 'AC Stampede Russet', 'AC Sunbury', 'Abeille', 'Abnaki', 'Acadia', 'Acadia Russet', 'Accent', diff --git a/plugins/pre.py b/plugins/pre.py index 0e443f9..f4e61a3 100644 --- a/plugins/pre.py +++ b/plugins/pre.py @@ -1,6 +1,7 @@ -from util import hook, http, timesince import datetime +from util import hook, http, timesince + @hook.command("scene") @hook.command diff --git a/plugins/rdio.py b/plugins/rdio.py index 6220a24..2677090 100644 --- a/plugins/rdio.py +++ b/plugins/rdio.py @@ -1,9 +1,11 @@ import urllib import json import re -from util import hook + import oauth2 as oauth +from util import hook + def getdata(inp, types, api_key, api_secret): consumer = oauth.Consumer(api_key, api_secret) diff --git a/plugins/seen.py b/plugins/seen.py index 29af742..85d433a 100644 --- a/plugins/seen.py +++ b/plugins/seen.py @@ -5,6 +5,7 @@ import re from util import hook, timesince + db_ready = False diff --git a/plugins/slap.py b/plugins/slap.py index 5371a0a..37dfbbd 100644 --- a/plugins/slap.py +++ b/plugins/slap.py @@ -1,6 +1,7 @@ -from util import hook, textgen import json +from util import hook, textgen + def get_generator(_json, variables): data = json.loads(_json) diff --git a/plugins/slogan.py b/plugins/slogan.py index 50ccbc1..279c41d 100644 --- a/plugins/slogan.py +++ b/plugins/slogan.py @@ -1,6 +1,7 @@ -from util import hook, text import random +from util import hook, text + with open("plugins/data/slogans.txt") as f: slogans = [line.strip() for line in f.readlines() diff --git a/plugins/soundcloud.py b/plugins/soundcloud.py index 034a2f5..d31f103 100644 --- a/plugins/soundcloud.py +++ b/plugins/soundcloud.py @@ -1,7 +1,9 @@ -from util import hook, http, web, text from urllib import urlencode import re +from util import hook, http, web, text + + sc_re = (r'(.*:)//(www.)?(soundcloud.com)(.*)', re.I) api_url = "http://api.soundcloud.com" sndsc_re = (r'(.*:)//(www.)?(snd.sc)(.*)', re.I) diff --git a/plugins/spellcheck.py b/plugins/spellcheck.py index 7ab188d..1630a0d 100644 --- a/plugins/spellcheck.py +++ b/plugins/spellcheck.py @@ -1,8 +1,9 @@ -from util import hook from enchant.checker import SpellChecker - import enchant +from util import hook + + locale = "en_US" diff --git a/plugins/spotify.py b/plugins/spotify.py index c113a06..ae0b339 100644 --- a/plugins/spotify.py +++ b/plugins/spotify.py @@ -1,7 +1,7 @@ import re +from urllib import urlencode from util import hook, http, web -from urllib import urlencode gateway = 'http://open.spotify.com/{}/{}' # http spotify gw address spuri = 'spotify:{}:{}' diff --git a/plugins/steam.py b/plugins/steam.py index cb7b9d5..3bc06c2 100644 --- a/plugins/steam.py +++ b/plugins/steam.py @@ -1,7 +1,9 @@ import re + +from bs4 import BeautifulSoup, NavigableString, Tag + from util import hook, http, web from util.text import truncate_str -from bs4 import BeautifulSoup, NavigableString, Tag steam_re = (r'(.*:)//(store.steampowered.com)(:[0-9]+)?(.*)', re.I) diff --git a/plugins/steam_calc.py b/plugins/steam_calc.py index 2fe2825..2aef985 100644 --- a/plugins/steam_calc.py +++ b/plugins/steam_calc.py @@ -1,7 +1,9 @@ -from util import hook, http, text import csv import StringIO +from util import hook, http, text + + gauge_url = "http://www.mysteamgauge.com/search?username={}" api_url = "http://mysteamgauge.com/user/{}.csv" diff --git a/plugins/system.py b/plugins/system.py index e8489d1..08891fd 100644 --- a/plugins/system.py +++ b/plugins/system.py @@ -2,9 +2,10 @@ import os import re import time import platform -from util import hook from datetime import timedelta +from util import hook + def convert_kilobytes(kilobytes): if kilobytes >= 1024: diff --git a/plugins/time_plugin.py b/plugins/time_plugin.py index 93dd2f2..885208b 100644 --- a/plugins/time_plugin.py +++ b/plugins/time_plugin.py @@ -1,7 +1,9 @@ -from util import hook, http import time + +from util import hook, http from util.text import capitalize_first + api_url = 'http://api.wolframalpha.com/v2/query?format=plaintext' diff --git a/plugins/title.py b/plugins/title.py index 6b912a3..4264188 100644 --- a/plugins/title.py +++ b/plugins/title.py @@ -1,6 +1,7 @@ -from util import hook, http, urlnorm from bs4 import BeautifulSoup +from util import hook, http, urlnorm + @hook.command def title(inp): diff --git a/plugins/tvdb.py b/plugins/tvdb.py index fa7584c..6a78502 100644 --- a/plugins/tvdb.py +++ b/plugins/tvdb.py @@ -9,6 +9,7 @@ from zipfile import ZipFile from cStringIO import StringIO from lxml import etree + from util import hook, http diff --git a/plugins/twitch.py b/plugins/twitch.py index 3e4e248..7e1a56a 100644 --- a/plugins/twitch.py +++ b/plugins/twitch.py @@ -1,7 +1,9 @@ import re -from util import hook, http from HTMLParser import HTMLParser +from util import hook, http + + twitch_re = (r'(.*:)//(twitch.tv|www.twitch.tv)(:[0-9]+)?(.*)', re.I) multitwitch_re = (r'(.*:)//(www.multitwitch.tv|multitwitch.tv)/(.*)', re.I) diff --git a/plugins/twitter.py b/plugins/twitter.py index 1499470..1983cef 100644 --- a/plugins/twitter.py +++ b/plugins/twitter.py @@ -1,9 +1,12 @@ -from util import hook, timesince -import tweepy import re import random from datetime import datetime +import tweepy + +from util import hook, timesince + + TWITTER_RE = (r"(?:(?:www.twitter.com|twitter.com)/(?:[-_a-zA-Z0-9]+)/status/)([0-9]+)", re.I) diff --git a/plugins/urban.py b/plugins/urban.py index 7374145..e64ea80 100644 --- a/plugins/urban.py +++ b/plugins/urban.py @@ -1,6 +1,8 @@ -from util import hook, http, text import re +from util import hook, http, text + + base_url = 'http://www.urbandictionary.com/iphone/search/define' diff --git a/plugins/utility.py b/plugins/utility.py index c0a1659..6a558f6 100644 --- a/plugins/utility.py +++ b/plugins/utility.py @@ -1,8 +1,10 @@ -from util import hook, text import hashlib import collections import re +from util import hook, text + + # variables colors = collections.OrderedDict([ diff --git a/plugins/valvesounds.py b/plugins/valvesounds.py index d8a9842..88bc8ce 100644 --- a/plugins/valvesounds.py +++ b/plugins/valvesounds.py @@ -1,7 +1,8 @@ -from util import hook, http, web import json import urllib2 +from util import hook, http, web + def get_sound_info(game, search): search = search.replace(" ", "+")