Skip to content

Commit

Permalink
Bug fixes
Browse files Browse the repository at this point in the history
- bing.lua; escaping ! in URL.
- isup.lua; change emoji for site is down message.
- kbbi.lua; pattern will match every characters.
- reddit.lua; (a) nsfw warning, and (b) remove unnecessary newline.
- translate.lua, rewords the usage sentences.
- urbandictionary.lua; pattern will match every characters.
- utils.lua; quote message when api bot privately messaged.
- webshot.lua; reword the help section.
- whois.lua; better error handling.
- yify.lua; add newline before synopsis.
  • Loading branch information
Sahri Riza Umami committed Jul 15, 2016
1 parent f8111b0 commit 30f0b00
Show file tree
Hide file tree
Showing 10 changed files with 29 additions and 23 deletions.
2 changes: 1 addition & 1 deletion bot/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ end
function send_message(msg, text, markdown)
if msg.from.api then
if msg.reply_to_message then
msg.id = msg.reply_to_message
msg.id = msg.reply_to_message.message_id
end
bot_sendMessage(get_receiver_api(msg), text, true, msg.id, markdown)
else
Expand Down
2 changes: 1 addition & 1 deletion plugins/bing.lua
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ do
for i = 1, #jresult do
local result = jresult[i]
reslist[i] = '<b>' .. i .. '</b>. '
.. '<a href="' .. result.Url .. '">' .. result.Title .. '</a>'
.. '<a href="' .. result.Url:gsub('[!]', '%%21') .. '">' .. result.Title .. '</a>'
end

local reslist = table.concat(reslist, '\n')
Expand Down
2 changes: 1 addition & 1 deletion plugins/isup.lua
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ do
elseif isup(matches[1]) then
send_message(msg, matches[1] .. ' looks <b>UP</b> from here. 😃', 'html')
else
send_message(msg, matches[1] .. ' looks <b>DOWN</b> from here. 😃', 'html')
send_message(msg, matches[1] .. ' looks <b>DOWN</b> from here. 😱', 'html')
end
end

Expand Down
4 changes: 2 additions & 2 deletions plugins/kbbi.lua
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ do
end

local function run(msg, matches)
get_kbbi(msg, matches[1])
get_kbbi(msg, URL.escape(matches[1]))
end

--------------------------------------------------------------------------------
Expand All @@ -64,7 +64,7 @@ do
'Menampilkan arti dari <code>[lema]</code>'
},
patterns = {
'^!kbbi (%g+)$'
'^!kbbi (.*)$'
},
run = run
}
Expand Down
4 changes: 2 additions & 2 deletions plugins/reddit.lua
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ do
end

local threadit = {}
local long_url = ''

for k=1, #jdata_child do
local redd = jdata_child[k].data
local long_url = '\n'

if not redd.is_self then
local link = URL.parse(redd.url)
Expand All @@ -62,7 +62,7 @@ do
local subreddit = '<b>' .. (matches[2] or 'redd.it') .. '</b>\n\n'
local subreddit = subreddit .. threadit

if threadit == '' then
if not threadit:match('%w+') then
send_message(msg, '<b>You must be 18+ to view this community.</b>', 'html')
else
bot_sendMessage(get_receiver_api(msg), subreddit, true, msg.id, 'html')
Expand Down
4 changes: 2 additions & 2 deletions plugins/translate.lua
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ do
description = "Translate some text",
usage = {
'<code>!trans text</code>',
'Translate the <code>text</code> to English.',
'Translate the <code>text</code> into the default language (or english).',
'',
'<code>!trans target_lang text</code>',
'Translate the <code>text</code> to <code>target_lang</code>.',
Expand All @@ -120,7 +120,7 @@ do
'',
'<b>Use !translate when reply!</b>',
'<code>!translate</code>',
'By reply. Translate the replied text into default language (or english).',
'By reply. Translate the replied text into the default language (or english).',
'',
'<code>!translate target_lang</code>',
'By reply. Translate the replied text into <code>target_lang</code>.',
Expand Down
8 changes: 4 additions & 4 deletions plugins/urbandictionary.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ do

local jdat = json:decode(jstr)
if jdat.result_type == 'no_results' then
send_message(msg, '<b>No result</b>', 'html')
send_message(msg, "There aren't any definitions for <i>" .. matches .. "</i> yet.", 'html')
return
end

Expand Down Expand Up @@ -63,9 +63,9 @@ do
'^!(urbandictionary)$',
'^!(ud)$',
'^!(urban)$',
'^!urbandictionary (%g+)$',
'^!ud (%g+)$',
'^!urban (%g+)$'
'^!urbandictionary (.+)$',
'^!ud (.+)$',
'^!urban (.+)$'
},
run = run
}
Expand Down
2 changes: 1 addition & 1 deletion plugins/webshot.lua
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ do
description = 'Send an screenshot of a website.',
usage = {
'<code>!webshot [url]</code>',
'Take an screenshot of the web and send it back to you.'
'Take an screenshot of the <code>[url]</code> and send it back to you.'
},
patterns = {
'^!webshot (https?://[%w-_%.%?%.:/%+=&]+)$',
Expand Down
22 changes: 14 additions & 8 deletions plugins/whois.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,25 @@ do

local whofile = '/tmp/whois.txt'

local function read_file(file)
local file = io.open(file, 'r')
local function whoinfo()
local file = io.open(whofile, 'r')
local content = file:read "*a"
file:close()
return content
return content:sub(1, 4000)
end

local function run(msg, matches)
local whoinfo = os.execute('whois ' .. matches[1] .. ' > ' .. whofile)
local result = os.execute('whois ' .. matches[1] .. ' > ' .. whofile)

if not whoinfo then
send_message(msg, '<b>sh: 1: whois: not found</b>.\n'
if not result then
if whoinfo():match('no match') then
send_message(msg, '<b>No match for</b> ' .. matches[1] .. '\n'
.. '* type the URL correctly\n'
.. '* exclude http(s) and www from the URL.', 'html')
elseif not os.execute('which whois') then
send_message(msg, '<b>sh: 1: whois: not found</b>.\n'
.. 'Please install <code>whois</code> package on your system.', 'html')
end
return
end

Expand All @@ -30,13 +36,13 @@ do
end
end
if matches[2] == 'pm' and is_chat_msg(msg) then
bot_sendMessage(msg.from.peer_id, read_file(whofile), true, nil, nil)
bot_sendMessage(msg.from.peer_id, whoinfo(), true, nil, nil)
end
if matches[2] == 'pmtxt' and is_chat_msg(msg) then
bot_sendDocument(msg.from.peer_id, whofile, nil, true, nil)
end
else
send_message(msg, read_file(whofile), nil)
send_message(msg, whoinfo(), nil)
end
end

Expand Down
2 changes: 1 addition & 1 deletion plugins/yify.lua
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ do
local title = '<a href="' .. yify.large_cover_image .. '">' .. yify.title_long .. '</a>'
local output = title .. '\n\n'
.. '<code>' .. yify.year .. ' | ' .. yify.rating .. '/10 | ' .. yify.runtime .. '</code> min\n\n'
.. torrlist .. yify.synopsis:sub(1, 2000) .. '<a href="' .. yify.url .. '"> More on yts.ag ...</a>'
.. torrlist .. '\n\n' .. yify.synopsis:sub(1, 2000) .. '<a href="' .. yify.url .. '"> More on yts.ag ...</a>'

bot_sendMessage(get_receiver_api(msg), output, false, msg.id, 'html')
end
Expand Down

0 comments on commit 30f0b00

Please sign in to comment.