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

29 lines
759 B
Lua
Raw Normal View History

2016-08-22 22:11:29 +02:00
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
2016-08-24 17:18:17 +02:00
utilities.send_reply(msg, config.errors.connection)
2016-08-22 22:11:29 +02:00
return
end
2016-08-24 17:18:17 +02:00
utilities.send_reply(msg, unescape(text))
2016-08-22 22:11:29 +02:00
end
return chucknorris