21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
# File 'lib/cinch/plugins/lmgtfy.rb', line 21
def execute m, user, query
if not config["username"] or not config["api_key"]
@bot.debug "either 'username' or 'api_key' is not set, please add these options"
return
end
search = LmgtfyUrl % [query.dup.gsub(/\s+/, "+")]
short = ShortnerUrl % [config["username"], config["api_key"], URI.escape(search)]
call = Curl::Easy.perform(short)
json = JSON.parse call.body_str
if json["status_code"] == 200
url = json["data"]["url"]
m.reply "#{user} check this out: #{url}"
else
error = json["status_txt"]
@bot.debug "Something went wrong: #{error}"
end
end
|