forked from CopierTeam/Umbrella-Cp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchuck_norris.lua
36 lines (31 loc) · 927 Bytes
/
chuck_norris.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
do
function unescape(str)
str = string.gsub( str, '<', '<' )
str = string.gsub( str, '>', '>' )
str = string.gsub( str, '"', '"' )
str = string.gsub( str, ''', "'" )
str = string.gsub( str, '&#(%d+);', function(n) return string.char(n) end )
str = string.gsub( str, '&#x(%d+);', function(n) return string.char(tonumber(n,16)) end )
str = string.gsub( str, '&', '&' ) -- Be sure to do this after all others
return str
end
local function chuck()
local random = http.request("http://api.icndb.com/jokes/random")
local decode = json:decode(random)
local joke = decode.value.joke
local unescape = unescape(joke)
return unescape
end
local function run(msg)
local joke = chuck()
return joke
end
return {
description = "Get random Chuck Norris jokes.",
usage = "!chuck",
patterns = {
"^!chuck$"
},
run = run
}
end