29 lines
1.2 KiB
Python
29 lines
1.2 KiB
Python
|
"""An echobox is a device that, upon feeding it an input, stores it and
|
||
|
outputs a previously submitted input.
|
||
|
Usage: !echobox input"""
|
||
|
|
||
|
import random
|
||
|
import urllib
|
||
|
import urllib2
|
||
|
|
||
|
def echobox(nick,channel,tenquestionmarks,input):
|
||
|
"""The echobox command submits some text into an "echobox", or
|
||
|
a collection of quotes. After doing so, it outputs a random
|
||
|
quote from that colleciton."""
|
||
|
|
||
|
if input == None or input == "":
|
||
|
return tenquestionmarks.html("<b>Echobox error</b>: You need to type something after !echobox, because I'm too lazy to come up with something for you.")
|
||
|
|
||
|
result = ""
|
||
|
if "web_echobox_url" in tenquestionmarks.config()["echobox"]:
|
||
|
service_target = "%s?%s" % (tenquestionmarks.config()["echobox"]["web_echobox_url"],urllib.urlencode({"input": input, "nick": nick, "chan": channel}))
|
||
|
result = urllib2.urlopen(service_target).read()
|
||
|
else:
|
||
|
echobox = tenquestionmarks.get_json("echobox.json")
|
||
|
if "echoes" not in echobox:
|
||
|
echobox["echoes"] = []
|
||
|
echobox["echoes"].append(input)
|
||
|
tenquestionmarks.put_json("echobox.json",echobox)
|
||
|
result = random.choice(echobox["echoes"])
|
||
|
return tenquestionmarks.html("<b>Echobox</b>: %s" % (result))
|