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.
I missed an open bracket in my PR and resulting this plugin not working as expectedly. I added back unescape function which already fixed. you can test the plugin on my bot ```@botix```
- Loading branch information
psycholyzern
committed
Jun 22, 2015
1 parent
0df0a42
commit c902475
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 |