Merge pull request #138 from thenoodle68/develop
Pull some more noodlecode
This commit is contained in:
commit
a44e0bb7bf
2 changed files with 71 additions and 13 deletions
47
plugins/puush.py
Normal file
47
plugins/puush.py
Normal file
|
@ -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 [1-5] -- Returns a number of random puu.sh entries."""
|
||||||
|
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)
|
|
@ -6,22 +6,33 @@ locale = "en_US"
|
||||||
|
|
||||||
@hook.command
|
@hook.command
|
||||||
def spell(inp):
|
def spell(inp):
|
||||||
"""spell <word> -- Check spelling of <word>."""
|
"""spell <word/sentence> -- Check spelling of a word or sentence."""
|
||||||
|
words = inp.split(" ")
|
||||||
if ' ' in inp:
|
if words[0] == "":
|
||||||
return "This command only supports one word at a time."
|
words = []
|
||||||
|
|
||||||
if not enchant.dict_exists(locale):
|
if not enchant.dict_exists(locale):
|
||||||
return "Could not find dictionary: {}".format(locale)
|
return "Could not find dictionary: {}".format(locale)
|
||||||
|
|
||||||
dictionary = enchant.Dict(locale)
|
dictionary = enchant.Dict(locale)
|
||||||
is_correct = dictionary.check(inp)
|
|
||||||
suggestions = dictionary.suggest(inp)
|
|
||||||
s_string = ', '.join(suggestions[:10])
|
|
||||||
|
|
||||||
if is_correct:
|
if len(words) > 1:
|
||||||
return '"{}" appears to be \x02valid\x02! ' \
|
out = []
|
||||||
'(suggestions: {})'.format(inp, s_string)
|
for x in words:
|
||||||
|
is_correct = dictionary.check(x)
|
||||||
|
suggestions = dictionary.suggest(x)
|
||||||
|
s_string = '/'.join(suggestions[:3])
|
||||||
|
if is_correct:
|
||||||
|
out.append(x)
|
||||||
|
else:
|
||||||
|
out.append('\x02' + s_string + '\x02')
|
||||||
|
return " ".join(out)
|
||||||
else:
|
else:
|
||||||
return '"{}" appears to be \x02invalid\x02! ' \
|
is_correct = dictionary.check(words[0])
|
||||||
'(suggestions: {})'.format(inp, s_string)
|
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)
|
||||||
|
|
Reference in a new issue