76c285910a
- Chucknorris - Dogify
29 lines
771 B
Lua
29 lines
771 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(self, msg, config.errors.connection)
|
|
return
|
|
end
|
|
utilities.send_reply(self, msg, unescape(text))
|
|
end
|
|
|
|
return chucknorris |