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
771 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
utilities.send_reply(self, msg, config.errors.connection)
return
end
utilities.send_reply(self, msg, unescape(text))
end
return chucknorris