- @bot.say(m.replyto, confession)
- rescue
- m.reply "failed to connect to grouphug.us"
+ def confess(m, params)
+ opts = { :cache => false }
+ path = "random"
+ begin
+ # Fetch a specific question - separate from cache
+ if params[:num]
+ path = "confessions/#{params[:num]}"
+ opts.delete(:cache)
+ data = @bot.httputil.get("http://grouphug.us/#{path}", opts)
+ confessions = get_confessions(data)
+ if confessions.length > 1
+ warn "more than one confession found!"
+ warn confessions
+ end
+ confessions << "no confession ##{params[:num]} found" if confessions.empty?
+ m.reply confessions.first
+ else # Cache random confessions
+ if @confessions.empty?
+ data = @bot.httputil.get("http://grouphug.us/#{path}", opts)
+ @confessions.replace get_confessions(data)