From 30f0b007807e8c8da01f696065ca3d1511557b63 Mon Sep 17 00:00:00 2001 From: Sahri Riza Umami Date: Sat, 16 Jul 2016 01:29:18 +0700 Subject: [PATCH] Bug fixes - 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. --- bot/utils.lua | 2 +- plugins/bing.lua | 2 +- plugins/isup.lua | 2 +- plugins/kbbi.lua | 4 ++-- plugins/reddit.lua | 4 ++-- plugins/translate.lua | 4 ++-- plugins/urbandictionary.lua | 8 ++++---- plugins/webshot.lua | 2 +- plugins/whois.lua | 22 ++++++++++++++-------- plugins/yify.lua | 2 +- 10 files changed, 29 insertions(+), 23 deletions(-) diff --git a/bot/utils.lua b/bot/utils.lua index 1cad88e..de19868 100644 --- a/bot/utils.lua +++ b/bot/utils.lua @@ -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 diff --git a/plugins/bing.lua b/plugins/bing.lua index 61bc0c0..2ba6142 100644 --- a/plugins/bing.lua +++ b/plugins/bing.lua @@ -30,7 +30,7 @@ do for i = 1, #jresult do local result = jresult[i] reslist[i] = '' .. i .. '. ' - .. '' .. result.Title .. '' + .. '' .. result.Title .. '' end local reslist = table.concat(reslist, '\n') diff --git a/plugins/isup.lua b/plugins/isup.lua index 7775d62..84f390a 100644 --- a/plugins/isup.lua +++ b/plugins/isup.lua @@ -107,7 +107,7 @@ do elseif isup(matches[1]) then send_message(msg, matches[1] .. ' looks UP from here. 😃', 'html') else - send_message(msg, matches[1] .. ' looks DOWN from here. 😃', 'html') + send_message(msg, matches[1] .. ' looks DOWN from here. 😱', 'html') end end diff --git a/plugins/kbbi.lua b/plugins/kbbi.lua index 321c74a..482f49f 100644 --- a/plugins/kbbi.lua +++ b/plugins/kbbi.lua @@ -52,7 +52,7 @@ do end local function run(msg, matches) - get_kbbi(msg, matches[1]) + get_kbbi(msg, URL.escape(matches[1])) end -------------------------------------------------------------------------------- @@ -64,7 +64,7 @@ do 'Menampilkan arti dari [lema]' }, patterns = { - '^!kbbi (%g+)$' + '^!kbbi (.*)$' }, run = run } diff --git a/plugins/reddit.lua b/plugins/reddit.lua index 43d6692..08685ca 100644 --- a/plugins/reddit.lua +++ b/plugins/reddit.lua @@ -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) @@ -62,7 +62,7 @@ do local subreddit = '' .. (matches[2] or 'redd.it') .. '\n\n' local subreddit = subreddit .. threadit - if threadit == '' then + if not threadit:match('%w+') then send_message(msg, 'You must be 18+ to view this community.', 'html') else bot_sendMessage(get_receiver_api(msg), subreddit, true, msg.id, 'html') diff --git a/plugins/translate.lua b/plugins/translate.lua index b539d71..0223063 100644 --- a/plugins/translate.lua +++ b/plugins/translate.lua @@ -110,7 +110,7 @@ do description = "Translate some text", usage = { '!trans text', - 'Translate the text to English.', + 'Translate the text into the default language (or english).', '', '!trans target_lang text', 'Translate the text to target_lang.', @@ -120,7 +120,7 @@ do '', 'Use !translate when reply!', '!translate', - 'By reply. Translate the replied text into default language (or english).', + 'By reply. Translate the replied text into the default language (or english).', '', '!translate target_lang', 'By reply. Translate the replied text into target_lang.', diff --git a/plugins/urbandictionary.lua b/plugins/urbandictionary.lua index ee3e083..13da65f 100644 --- a/plugins/urbandictionary.lua +++ b/plugins/urbandictionary.lua @@ -11,7 +11,7 @@ do local jdat = json:decode(jstr) if jdat.result_type == 'no_results' then - send_message(msg, 'No result', 'html') + send_message(msg, "There aren't any definitions for " .. matches .. " yet.", 'html') return end @@ -63,9 +63,9 @@ do '^!(urbandictionary)$', '^!(ud)$', '^!(urban)$', - '^!urbandictionary (%g+)$', - '^!ud (%g+)$', - '^!urban (%g+)$' + '^!urbandictionary (.+)$', + '^!ud (.+)$', + '^!urban (.+)$' }, run = run } diff --git a/plugins/webshot.lua b/plugins/webshot.lua index fb9d540..38b9091 100644 --- a/plugins/webshot.lua +++ b/plugins/webshot.lua @@ -57,7 +57,7 @@ do description = 'Send an screenshot of a website.', usage = { '!webshot [url]', - 'Take an screenshot of the web and send it back to you.' + 'Take an screenshot of the [url] and send it back to you.' }, patterns = { '^!webshot (https?://[%w-_%.%?%.:/%+=&]+)$', diff --git a/plugins/whois.lua b/plugins/whois.lua index fa929cb..045a04e 100644 --- a/plugins/whois.lua +++ b/plugins/whois.lua @@ -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, 'sh: 1: whois: not found.\n' + if not result then + if whoinfo():match('no match') then + send_message(msg, 'No match for ' .. 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, 'sh: 1: whois: not found.\n' .. 'Please install whois package on your system.', 'html') + end return end @@ -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 diff --git a/plugins/yify.lua b/plugins/yify.lua index 512fc41..a2920bd 100644 --- a/plugins/yify.lua +++ b/plugins/yify.lua @@ -27,7 +27,7 @@ do local title = '' .. yify.title_long .. '' local output = title .. '\n\n' .. '' .. yify.year .. ' | ' .. yify.rating .. '/10 | ' .. yify.runtime .. ' min\n\n' - .. torrlist .. yify.synopsis:sub(1, 2000) .. ' More on yts.ag ...' + .. torrlist .. '\n\n' .. yify.synopsis:sub(1, 2000) .. ' More on yts.ag ...' bot_sendMessage(get_receiver_api(msg), output, false, msg.id, 'html') end