add legacy version of tenquestionmarks irc bot
This commit is contained in:
28
modules/echobox.py
Executable file
28
modules/echobox.py
Executable file
@@ -0,0 +1,28 @@
|
||||
"""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))
|
Reference in New Issue
Block a user