diff --git a/README.md b/README.md index 793a472..b7f535d 100755 --- a/README.md +++ b/README.md @@ -21,6 +21,12 @@ Below are listed many (but not all) of otouto's plugins. This list will be updat >**Notes:** Replaces letters with corresponding characters from the Cyrillic alphabet. +###**ping.lua** + +>**Command:** /ping + +>**Function:** The simplest plugin ever! + ###**gSearch.lua** >**Command:** /google [query] diff --git a/bindings.lua b/bindings.lua index 2417428..1e08228 100755 --- a/bindings.lua +++ b/bindings.lua @@ -40,7 +40,7 @@ getUpdates = function(offset) end -sendMessage = function(chat_id, text, disable_web_page_preview, reply_to_message_id) +sendMessage = function(chat_id, text, disable_web_page_preview, reply_to_message_id, use_markdown) local url = BASE_URL .. '/sendMessage?chat_id=' .. chat_id .. '&text=' .. URL.escape(text) @@ -52,6 +52,10 @@ sendMessage = function(chat_id, text, disable_web_page_preview, reply_to_message url = url .. '&reply_to_message_id=' .. reply_to_message_id end + if use_markdown then + url = url .. '&parse_mode=Markdown' + end + return sendRequest(url) end diff --git a/bot.lua b/bot.lua index 873ef78..a2918e7 100755 --- a/bot.lua +++ b/bot.lua @@ -74,7 +74,7 @@ while is_started do -- Start a loop while the bot should be running. local res = getUpdates(last_update+1) -- Get the latest updates! if res then - for i,v in ipairs(res.result) do -- Go through every new damned message. + for i,v in ipairs(res.result) do -- Go through every new message. last_update = v.update_id on_msg_receive(v.message) end diff --git a/config.lua b/config.lua index 653ade2..221a7d8 100755 --- a/config.lua +++ b/config.lua @@ -65,6 +65,7 @@ telegram.me/otouto 'floodcontrol.lua', 'admin.lua', 'about.lua', + 'ping.lua', 'whoami.lua', 'nick.lua', 'echo.lua', diff --git a/plugins/chatter.lua b/plugins/chatter.lua index c62b90f..08460fd 100755 --- a/plugins/chatter.lua +++ b/plugins/chatter.lua @@ -13,6 +13,8 @@ local action = function(msg) -- This is awkward, but if you have a better way, please share. if msg.text_lower:match('^' .. bot.first_name .. ',') then elseif msg.text_lower:match('^@' .. bot.username .. ',') then + elseif msg.text:match('^/') then + return true -- Uncomment the following line for Al Gore-like reply chatter. -- elseif msg.reply_to_message and msg.reply_to_message.from.id == bot.id then elseif msg.from.id == msg.chat.id then diff --git a/plugins/fortune.lua b/plugins/fortune.lua index edcb38d..68aefbd 100755 --- a/plugins/fortune.lua +++ b/plugins/fortune.lua @@ -1,7 +1,7 @@ -- Requires that the "fortune" program is installed on your computer. - local s = io.popen('fortune'):read('*all') - if s:match('fortune: command not found') then +local s = io.popen('fortune'):read('*all') +if s:match('fortune: command not found') then print('fortune is not installed on this computer.') print('fortune.lua will not be enabled.') return diff --git a/plugins/lastfm.lua b/plugins/lastfm.lua index 40f2fc7..1980ae9 100755 --- a/plugins/lastfm.lua +++ b/plugins/lastfm.lua @@ -90,7 +90,7 @@ local action = function(msg) end message = message .. title .. ' - ' .. artist - sendReply(msg, message) + sendMessage(msg.chat.id, message) end diff --git a/plugins/ping.lua b/plugins/ping.lua new file mode 100644 index 0000000..d176e47 --- /dev/null +++ b/plugins/ping.lua @@ -0,0 +1,14 @@ + -- Actually the simplest plugin ever! + +local triggers = { + '^/ping[@'..bot.username..']*' +} + +local action = function(msg) + sendMessage(msg.chat.id, 'Pong!') +end + +return { + action = action, + triggers = triggers +}