Some changes on giphy plugin
This commit is contained in:
parent
f39e51c0f8
commit
3b59be34c5
@ -1,27 +1,31 @@
|
||||
-- Idea by https://github.com/asdofindia/telegram-bot/
|
||||
-- See http://api.giphy.com/
|
||||
|
||||
do
|
||||
|
||||
local BASE_URL = 'http://api.giphy.com/v1'
|
||||
local API_KEY = 'dc6zaTOxFJmzC' -- public beta key
|
||||
|
||||
function get_random_top()
|
||||
local api_key = "dc6zaTOxFJmzC" -- public beta key
|
||||
local b = http.request("http://api.giphy.com/v1/gifs/trending?api_key="..api_key)
|
||||
local images = json:decode(b).data
|
||||
local res, code = http.request(BASE_URL.."/gifs/trending?api_key="..API_KEY)
|
||||
if code ~= 200 then return nil end
|
||||
local images = json:decode(res).data
|
||||
local i = math.random(0,#images)
|
||||
return images[i].images.downsized.url
|
||||
end
|
||||
|
||||
function search(text)
|
||||
local api_key = "dc6zaTOxFJmzC" -- public beta key
|
||||
b = http.request("http://api.giphy.com/v1/gifs/search?q="..text.."&api_key="..api_key)
|
||||
local images = json:decode(b).data
|
||||
local res, code = http.request(BASE_URL.."/gifs/search?q="..text.."&api_key="..API_KEY)
|
||||
local images = json:decode(res).data
|
||||
if #images == 0 then return nil end -- No images
|
||||
math.randomseed(os.time())
|
||||
local i = math.random(0,#images)
|
||||
return images[i].images.downsized.url
|
||||
end
|
||||
|
||||
function run(msg, matches)
|
||||
-- If no search data, a cat gif will be sended
|
||||
-- Because everyone loves pussies
|
||||
local gif_url = ''
|
||||
|
||||
-- If no search data, a random trending GIF will be sended
|
||||
if matches[1] == "!gif" or matches[1] == "!giphy" then
|
||||
gif_url = get_random_top()
|
||||
else
|
||||
@ -50,4 +54,6 @@ return {
|
||||
"^!giphy$"
|
||||
},
|
||||
run = run
|
||||
}
|
||||
}
|
||||
|
||||
end
|
Reference in New Issue
Block a user