forked from yagop/telegram-bot
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request yagop#273 from psycholyzern/patch-7
Update chuck_norris.lua
Showing
1 changed file
with
32 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,36 @@ | ||
local function chuck() | ||
local random = http.request("http://api.icndb.com/jokes/random") | ||
local decode = json:decode(random) | ||
local joke = decode.value.joke | ||
return joke | ||
end | ||
do | ||
|
||
local function run(msg) | ||
local joke = chuck() | ||
return unescape_html(joke) | ||
end | ||
local 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 | ||
|
||
return { | ||
description = "Get random Chuck Norris jokes.", | ||
usage = "!chuck", | ||
patterns = { | ||
"^!chuck$" | ||
function run(msg) | ||
local joke = chuck() | ||
return joke | ||
end | ||
|
||
return { | ||
description = "Get random Chuck Norris jokes.", | ||
usage = "!chuck", | ||
patterns = { | ||
"^!chuck$" | ||
}, | ||
run = run | ||
} | ||
} | ||
|
||
end |