diff --git a/modules/active/get_quote.py b/modules/active/get_quote.py index ecdedf1..422a9c1 100644 --- a/modules/active/get_quote.py +++ b/modules/active/get_quote.py @@ -74,17 +74,21 @@ def search_wiki(code,term): return results def quote(msg,args): - if len(args)!=3: - brathuhn.sendMsg(brathuhn.ROOM,"Usage: "+args[0]+" language (two letter code) topic",'groupchat') + if len(args)!=2: + brathuhn.sendMsg(brathuhn.ROOM,"Usage: "+args[0]+" language (two letter code) [topic]",'groupchat') else: try: - brathuhn.sendMsg(brathuhn.ROOM,'searching for "'+ args[2] +'"...','groupchat') - search_results = search_wiki(args[1],args[2]) - if len( search_results )==0: - brathuhn.sendMsg(brathuhn.ROOM,"No quotes found",'groupchat') - + if args==2: + brathuhn.sendMsg(brathuhn.ROOM,'fetching random page...','groupchat') + url = "http://"+args[1][0:2]+".wikiquote.org/wiki/Special:Random" + else: + brathuhn.sendMsg(brathuhn.ROOM,'searching for "'+ args[2] +'"...','groupchat') + search_results = search_wiki(args[1],args[2]) + if len( search_results )==0: + brathuhn.sendMsg(brathuhn.ROOM,"No quotes found",'groupchat') + url = "http://"+args[1][0:2]+".wikiquote.org/wiki/" + urllib2.quote(search_results[0]) - url = "http://"+args[1][0:2]+".wikiquote.org/wiki/" + urllib2.quote(search_results[0]) + req = urllib2.Request(url, headers={'User-Agent' : "Magic Browser"}) con = urllib2.urlopen( req ) @@ -104,4 +108,4 @@ def quote(msg,args): except exceptions.Exception as e: brathuhn.sendMsg(brathuhn.ROOM,"Network Error "+unicode(e),'groupchat') -brathuhn.addCommand("quote","Usage: !quote language (two letter code) topic",quote) +brathuhn.addCommand("quote","Usage: !quote language (two letter code) [topic]",quote)