This repository has been archived on 2021-04-24. You can view files and clone it, but cannot push or open issues or pull requests.
Mikubot-2/miku/plugins/chucknorris.lua
2016-08-24 17:18:17 +02:00

29 lines
759 B
Lua

local chucknorris = {}
chucknorris.command = 'cn'
function chucknorris:init(config)
chucknorris.triggers = utilities.triggers(self.info.username, config.cmd_pat):t('cn', true).table
chucknorris.doc = [[*
]]..config.cmd_pat..[[cn*: Postet einen zufälligen Chuck-Norris-Witz]]
end
function chucknorris:get_joke()
local url = 'http://api.icndb.com/jokes/random'
local res, code = http.request(url)
if code ~= 200 then return nil end
local data = json.decode(res)
local text = data.value.joke
return text
end
function chucknorris:action(msg, config)
local text = chucknorris:get_joke()
if not text then
utilities.send_reply(msg, config.errors.connection)
return
end
utilities.send_reply(msg, unescape(text))
end
return chucknorris