From d58646628c61ffe0540982264178addb46fe261b Mon Sep 17 00:00:00 2001 From: Fletcher Boyd Date: Wed, 4 Sep 2013 22:49:55 +0800 Subject: [PATCH 1/5] Add random puu.sh fetcher. --- plugins/puush.py | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 plugins/puush.py diff --git a/plugins/puush.py b/plugins/puush.py new file mode 100644 index 0000000..202aa89 --- /dev/null +++ b/plugins/puush.py @@ -0,0 +1,47 @@ +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: + x = urllib2.urlopen(make_url(code)) + return True + except: + return False # sorry <3 + + +def make_url(code): + return "http://puu.sh/" + code + + +@hook.command(autohelp=False) +def puush(inp): + """puush -- Returns a random puush entry.""" + out = "" + num = 0 + if not inp: + inp = "1" + if inp[0] not in "123456789": + 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 range(num): + ran = make_string() + while not check_url(ran): + ran = make_string() + images.append(make_url(ran)) + return out + " ".join(images) From 9d6aef731e0f2316c4ee58f83744531e2631114e Mon Sep 17 00:00:00 2001 From: Fletcher Boyd Date: Wed, 4 Sep 2013 22:53:18 +0800 Subject: [PATCH 2/5] Update docstring --- plugins/puush.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/puush.py b/plugins/puush.py index 202aa89..de6b597 100644 --- a/plugins/puush.py +++ b/plugins/puush.py @@ -25,7 +25,7 @@ def make_url(code): @hook.command(autohelp=False) def puush(inp): - """puush -- Returns a random puush entry.""" + """puush [1-5] -- Returns a number of random puu.sh entries.""" out = "" num = 0 if not inp: From 253ffaafdab72b887cadb91a23fd9225f677e66a Mon Sep 17 00:00:00 2001 From: Fletcher Boyd Date: Wed, 4 Sep 2013 23:48:56 +0800 Subject: [PATCH 3/5] Added multiword support. --- plugins/spellcheck.py | 36 ++++++++++++++++++++++++------------ 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/plugins/spellcheck.py b/plugins/spellcheck.py index 95b1699..2b116dc 100755 --- a/plugins/spellcheck.py +++ b/plugins/spellcheck.py @@ -7,21 +7,33 @@ locale = "en_US" @hook.command def spell(inp): """spell -- Check spelling of .""" - - if ' ' in inp: - return "This command only supports one word at a time." - + words = inp.split(" ") + if words[0] == "": + words = [] if not enchant.dict_exists(locale): return "Could not find dictionary: {}".format(locale) dictionary = enchant.Dict(locale) - is_correct = dictionary.check(inp) - suggestions = dictionary.suggest(inp) - s_string = ', '.join(suggestions[:10]) - if is_correct: - return '"{}" appears to be \x02valid\x02! ' \ - '(suggestions: {})'.format(inp, s_string) + if len(words) > 1: + out = [] + for x in words: + is_correct = dictionary.check(x) + suggestions = dictionary.suggest(x) + s_string = '/'.join(suggestions[:2]) + if is_correct: + out.append(x) + else: + out.append('\x02'+s_string+'\x02') + return " ".join(out) else: - return '"{}" appears to be \x02invalid\x02! ' \ - '(suggestions: {})'.format(inp, s_string) + is_correct = dictionary.check(words[0]) + suggestions = dictionary.suggest(words[0]) + s_string = ', '.join(suggestions[:10]) + if is_correct: + return '"{}" appears to be \x02valid\x02! ' \ + '(suggestions: {})'.format(inp, s_string) + else: + return '"{}" appears to be \x02invalid\x02! ' \ + '(suggestions: {})'.format(inp, s_string) + From d5a5237fb86f7c9076c3ad9d427eacd8a558131e Mon Sep 17 00:00:00 2001 From: Fletcher Boyd Date: Wed, 4 Sep 2013 23:50:57 +0800 Subject: [PATCH 4/5] Formatting and updating docstring. --- plugins/spellcheck.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/plugins/spellcheck.py b/plugins/spellcheck.py index 2b116dc..3c0ac9d 100755 --- a/plugins/spellcheck.py +++ b/plugins/spellcheck.py @@ -6,7 +6,7 @@ locale = "en_US" @hook.command def spell(inp): - """spell -- Check spelling of .""" + """spell -- Check spelling of a word or sentence.""" words = inp.split(" ") if words[0] == "": words = [] @@ -24,7 +24,7 @@ def spell(inp): if is_correct: out.append(x) else: - out.append('\x02'+s_string+'\x02') + out.append('\x02' + s_string + '\x02') return " ".join(out) else: is_correct = dictionary.check(words[0]) @@ -32,8 +32,7 @@ def spell(inp): s_string = ', '.join(suggestions[:10]) if is_correct: return '"{}" appears to be \x02valid\x02! ' \ - '(suggestions: {})'.format(inp, s_string) + '(suggestions: {})'.format(inp, s_string) else: return '"{}" appears to be \x02invalid\x02! ' \ - '(suggestions: {})'.format(inp, s_string) - + '(suggestions: {})'.format(inp, s_string) From 4b4541dd9949bfaf5f09665ae009d77fea62ca7c Mon Sep 17 00:00:00 2001 From: Fletcher Boyd Date: Thu, 5 Sep 2013 00:25:46 +0800 Subject: [PATCH 5/5] things look better in threes. --- plugins/spellcheck.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/spellcheck.py b/plugins/spellcheck.py index 3c0ac9d..244ec9f 100755 --- a/plugins/spellcheck.py +++ b/plugins/spellcheck.py @@ -20,7 +20,7 @@ def spell(inp): for x in words: is_correct = dictionary.check(x) suggestions = dictionary.suggest(x) - s_string = '/'.join(suggestions[:2]) + s_string = '/'.join(suggestions[:3]) if is_correct: out.append(x) else: