Rewrote help.lua and added markup support to several plugins.
help.lua has been rewritten to support "/help command". New variable "command" has been added to plugins for the syntax (w/out slash) to be displayed in main help message. "doc" will be displayed upon "/help command". Output of >12 plugins has been reformated to utilize markup. There is a fairly standard style throughout plugins. get_word() in utilities.lua now has defaults for nil arguments.
This commit is contained in:
parent
9070a44c8f
commit
26c1299374
@ -119,13 +119,14 @@ For support for otouto and bots in general, join my Bot Development group. Follo
|
||||
##Development
|
||||
Everybody is free to contribute to otouto. Here I will explain various things that are important to know about the plugin system.
|
||||
|
||||
A plugin can have four components, and two of them are optional: action, triggers, doc, cron.
|
||||
A plugin can have five components, and three of them are optional: action, triggers, doc, command, and cron.
|
||||
|
||||
| Component | Description | Optional? |
|
||||
|-----------|-------------|-----------|
|
||||
| action | The main function of a plugin. It accepts the `msg` table. | No. |
|
||||
| triggers | A table of strings which, when one is matched in a message's text, will cause `action` to be run. | No. |
|
||||
| doc | The help text to be returned when a plugin is run with improper syntax or arguments. The first line is also what goes in the help text. | Yes |
|
||||
| doc | The help text to be returned when a plugin is run with improper syntax or arguments. | Yes |
|
||||
| command | The command with its syntax, without the slash. This is used to generate the help text. | Yes |
|
||||
| cron | A function to be run every five seconds. | Yes |
|
||||
|
||||
The on_msg_receive function adds a few variables to the "msg" table: msg.from.id_str, msg.to.id_str, msg.text_lower. These are self-explanatory and can make your code a lot neater.
|
||||
|
@ -1,7 +1,5 @@
|
||||
local doc = [[
|
||||
/about
|
||||
Get info about the bot.
|
||||
]]
|
||||
local command = 'about'
|
||||
local doc = '`Returns information about the bot.`'
|
||||
|
||||
local triggers = {
|
||||
''
|
||||
@ -26,5 +24,6 @@ end
|
||||
return {
|
||||
action = action,
|
||||
triggers = triggers,
|
||||
doc = doc
|
||||
doc = doc,
|
||||
command = command
|
||||
}
|
||||
|
@ -1,7 +1,8 @@
|
||||
local doc = [[
|
||||
/bandersnatch
|
||||
Shun the frumious Bandersnatch.
|
||||
]]
|
||||
local command = 'bandersnatch'
|
||||
local doc = [[```
|
||||
Shun the frumious Bandersnatch.
|
||||
Alias: /bc
|
||||
```]]
|
||||
|
||||
local triggers = {
|
||||
'^/bandersnatch[@'..bot.username..']*',
|
||||
@ -31,5 +32,6 @@ end
|
||||
return {
|
||||
action = action,
|
||||
triggers = triggers,
|
||||
doc = doc
|
||||
command = command,
|
||||
desc = desc
|
||||
}
|
||||
|
@ -4,10 +4,12 @@ if not config.biblia_api_key then
|
||||
return
|
||||
end
|
||||
|
||||
local doc = [[
|
||||
/bible <reference>
|
||||
Returns a verse from the American Standard Version of the Bible, or an apocryphal verse from the King James Version. Results from biblia.com.
|
||||
]]
|
||||
local command = 'bible <reference>'
|
||||
local doc = [[```
|
||||
/bible <reference>
|
||||
Returns a verse from the American Standard Version of the Bible, or an apocryphal verse from the King James Version. Results from biblia.com.
|
||||
Alias: /b
|
||||
```]]
|
||||
|
||||
local triggers = {
|
||||
'^/bible*[@'..bot.username..']*',
|
||||
@ -19,7 +21,7 @@ local action = function(msg)
|
||||
|
||||
local input = msg.text:input()
|
||||
if not input then
|
||||
sendReply(msg, doc)
|
||||
sendMessage(msg.chat.id, doc, true, msg.message_id, true)
|
||||
return
|
||||
end
|
||||
|
||||
@ -47,5 +49,6 @@ end
|
||||
return {
|
||||
action = action,
|
||||
triggers = triggers,
|
||||
command = command,
|
||||
doc = doc
|
||||
}
|
||||
|
@ -1,7 +1,8 @@
|
||||
local doc = [[
|
||||
/calc <expression>
|
||||
Returns solutions to mathematical expressions and conversions between common units. Results provided by mathjs.org.
|
||||
]]
|
||||
local command = 'calc <expression>'
|
||||
local doc = [[```
|
||||
/calc <expression>
|
||||
Returns solutions to mathematical expressions and conversions between common units. Results provided by mathjs.org.
|
||||
```]]
|
||||
|
||||
local triggers = {
|
||||
'^/calc[@'..bot.username..']*'
|
||||
@ -14,25 +15,28 @@ local action = function(msg)
|
||||
if msg.reply_to_message and msg.reply_to_message.text then
|
||||
input = msg.reply_to_message.text
|
||||
else
|
||||
sendReply(msg, doc)
|
||||
sendMessage(msg.chat.id, doc, true, msg.message_id, true)
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
local url = 'https://api.mathjs.org/v1/?expr=' .. URL.escape(input)
|
||||
|
||||
local ans, res = HTTPS.request(url)
|
||||
if not ans then
|
||||
local output = HTTPS.request(url)
|
||||
if not output then
|
||||
sendReply(msg, config.errors.connection)
|
||||
return
|
||||
end
|
||||
|
||||
sendReply(msg, ans)
|
||||
output = '`' .. output .. '`'
|
||||
|
||||
sendMessage(msg.chat.id, output, true, msg.message_id, true)
|
||||
|
||||
end
|
||||
|
||||
return {
|
||||
action = action,
|
||||
triggers = triggers,
|
||||
command = command,
|
||||
doc = doc
|
||||
}
|
||||
|
@ -3,10 +3,8 @@ if not config.thecatapi_key then
|
||||
print('cats.lua will be enabled, but there are more features with a key.')
|
||||
end
|
||||
|
||||
local doc = [[
|
||||
/cat
|
||||
Returns a cat!
|
||||
]]
|
||||
local command = 'cat'
|
||||
local doc = '`Returns a cat!`'
|
||||
|
||||
local triggers = {
|
||||
'^/cat[@'..bot.username..']*$'
|
||||
@ -34,5 +32,6 @@ end
|
||||
return {
|
||||
action = action,
|
||||
triggers = triggers,
|
||||
doc = doc
|
||||
doc = doc,
|
||||
command = command
|
||||
}
|
||||
|
@ -1,9 +1,7 @@
|
||||
-- Commits from https://github.com/ngerakines/commitment.
|
||||
|
||||
local doc = [[
|
||||
/commit
|
||||
Returns a commit message from whatthecommit.com.
|
||||
]]
|
||||
local command = 'commit'
|
||||
local doc = '`Returns a commit message from whatthecommit.com.`'
|
||||
|
||||
local triggers = {
|
||||
'^/commit[@'..bot.username..']*'
|
||||
@ -414,12 +412,13 @@ local commits = {
|
||||
|
||||
local action = function(msg)
|
||||
|
||||
sendMessage(msg.chat.id, commits[math.random(#commits)])
|
||||
sendMessage(msg.chat.id, '`'..commits[math.random(#commits)]..'`', true, nil, true)
|
||||
|
||||
end
|
||||
|
||||
return {
|
||||
action = action,
|
||||
triggers = triggers,
|
||||
doc = doc
|
||||
doc = doc,
|
||||
command = command
|
||||
}
|
||||
|
@ -1,8 +1,9 @@
|
||||
local doc = [[
|
||||
/cash [amount] <from> to <to>
|
||||
Example: /cash 5 USD to EUR
|
||||
Returns exchange rates for various currencies.
|
||||
]]
|
||||
local command = 'cash [amount] <from> to <to>'
|
||||
local doc = [[```
|
||||
/cash [amount] <from> to <to>
|
||||
Example: /cash 5 USD to EUR
|
||||
Returns exchange rates for various currencies.
|
||||
```]]
|
||||
|
||||
local triggers = {
|
||||
'^/cash[@'..bot.username..']*'
|
||||
@ -12,7 +13,7 @@ local action = function(msg)
|
||||
|
||||
local input = msg.text:upper()
|
||||
if not input:match('%a%a%a TO %a%a%a') then
|
||||
sendReply(msg, doc)
|
||||
sendMessage(msg.chat.id, doc, true, msg.message_id, true)
|
||||
return
|
||||
end
|
||||
|
||||
@ -42,13 +43,17 @@ local action = function(msg)
|
||||
|
||||
end
|
||||
|
||||
local message = amount .. ' ' .. from .. ' = ' .. result .. ' ' .. to
|
||||
sendReply(msg, message)
|
||||
local output = amount .. ' ' .. from .. ' = ' .. result .. ' ' .. to .. '\n'
|
||||
output = output .. os.date('!%F %T UTC')
|
||||
output = '`' .. output .. '`'
|
||||
|
||||
sendMessage(msg.chat.id, output, true, nil, true)
|
||||
|
||||
end
|
||||
|
||||
return {
|
||||
action = action,
|
||||
triggers = triggers,
|
||||
doc = doc
|
||||
doc = doc,
|
||||
command = command
|
||||
}
|
||||
|
@ -1,7 +1,8 @@
|
||||
local doc = [[
|
||||
/roll <nDr>
|
||||
Returns a set of dice rolls, where n is the number of rolls and r is the range. If only a range is given, returns only one roll.
|
||||
]]
|
||||
local command = 'roll <nDr>'
|
||||
local doc = [[```
|
||||
/roll <nDr>
|
||||
Returns a set of dice rolls, where n is the number of rolls and r is the range. If only a range is given, returns only one roll.
|
||||
```]]
|
||||
|
||||
local triggers = {
|
||||
'^/roll[@'..bot.username..']*'
|
||||
@ -11,7 +12,7 @@ local action = function(msg)
|
||||
|
||||
local input = msg.text_lower:input()
|
||||
if not input then
|
||||
sendReply(msg, doc)
|
||||
sendMessage(msg.chat.id, doc, true, msg.message_id, true)
|
||||
return
|
||||
end
|
||||
|
||||
@ -22,7 +23,7 @@ local action = function(msg)
|
||||
count = 1
|
||||
range = input:match('^d?([%d]+)$')
|
||||
else
|
||||
sendReply(msg, doc)
|
||||
sendMessage(msg.chat.id, doc, true, msg.message_id, true)
|
||||
return
|
||||
end
|
||||
|
||||
@ -38,17 +39,19 @@ local action = function(msg)
|
||||
return
|
||||
end
|
||||
|
||||
local message = ''
|
||||
local output = '*' .. count .. 'd' .. range .. '*\n`'
|
||||
for i = 1, count do
|
||||
message = message .. math.random(range) .. '\t'
|
||||
output = output .. math.random(range) .. '\t'
|
||||
end
|
||||
output = output .. '`'
|
||||
|
||||
sendReply(msg, message)
|
||||
sendMessage(msg.chat.id, output, true, msg.message_id, true)
|
||||
|
||||
end
|
||||
|
||||
return {
|
||||
action = action,
|
||||
triggers = triggers,
|
||||
doc = doc
|
||||
doc = doc,
|
||||
command = command
|
||||
}
|
||||
|
@ -1,7 +1,8 @@
|
||||
local doc = [[
|
||||
/echo <text>
|
||||
Repeat a string of text!
|
||||
]]
|
||||
local command = 'echo <text>'
|
||||
local doc = [[```
|
||||
/echo <text>
|
||||
Repeats a string of text.
|
||||
```]]
|
||||
|
||||
local triggers = {
|
||||
'^/echo[@'..bot.username..']*'
|
||||
@ -14,7 +15,7 @@ local action = function(msg)
|
||||
if input then
|
||||
sendMessage(msg.chat.id, latcyr(input))
|
||||
else
|
||||
sendReply(msg, doc)
|
||||
sendMessage(msg.chat.id, doc, true, msg.message_id, true)
|
||||
end
|
||||
|
||||
end
|
||||
@ -22,5 +23,6 @@ end
|
||||
return {
|
||||
action = action,
|
||||
triggers = triggers,
|
||||
doc = doc
|
||||
doc = doc,
|
||||
command = command
|
||||
}
|
||||
|
@ -1,7 +1,5 @@
|
||||
local doc = [[
|
||||
/8ball
|
||||
Returns an answer from a magic 8-ball!
|
||||
]]
|
||||
local command = '8ball'
|
||||
local doc = '`Returns an answer from a magic 8-ball!`'
|
||||
|
||||
local triggers = {
|
||||
'^/8ball',
|
||||
@ -60,5 +58,6 @@ end
|
||||
return {
|
||||
action = action,
|
||||
triggers = triggers,
|
||||
doc = doc
|
||||
doc = doc,
|
||||
command = command
|
||||
}
|
||||
|
@ -7,10 +7,8 @@ if s:match('fortune: command not found') then
|
||||
return
|
||||
end
|
||||
|
||||
local doc = [[
|
||||
/fortune
|
||||
Returns a UNIX fortune.
|
||||
]]
|
||||
local command = 'fortune'
|
||||
local doc = '`Returns a UNIX fortune.`'
|
||||
|
||||
local triggers = {
|
||||
'^/fortune[@'..bot.username..']*'
|
||||
@ -26,5 +24,6 @@ end
|
||||
return {
|
||||
action = action,
|
||||
triggers = triggers,
|
||||
doc = doc
|
||||
doc = doc,
|
||||
command = command
|
||||
}
|
||||
|
@ -11,10 +11,12 @@ elseif not config.google_cse_key then
|
||||
return
|
||||
end
|
||||
|
||||
local doc = [[
|
||||
/image <query>
|
||||
Returns a randomized top result from Google Images. Safe search is enabled by default; use "/insfw" to disable it. NSFW results will not display an image preview.
|
||||
]]
|
||||
local command = 'image <query>'
|
||||
local doc = [[```
|
||||
/image <query>
|
||||
Returns a randomized top result from Google Images. Safe search is enabled by default; use "/insfw" to disable it. NSFW results will not display an image preview.
|
||||
Alias: /i
|
||||
```]]
|
||||
|
||||
local triggers = {
|
||||
'^/image[@'..bot.username..']*',
|
||||
@ -30,7 +32,7 @@ local action = function(msg)
|
||||
if msg.reply_to_message and msg.reply_to_message.text then
|
||||
input = msg.reply_to_message.text
|
||||
else
|
||||
sendReply(msg, doc)
|
||||
sendMessage(msg.chat.id, doc, true, msg.message_id, true)
|
||||
return
|
||||
end
|
||||
end
|
||||
@ -69,5 +71,6 @@ end
|
||||
return {
|
||||
action = action,
|
||||
triggers = triggers,
|
||||
doc = doc
|
||||
doc = doc,
|
||||
command = command
|
||||
}
|
||||
|
@ -1,7 +1,9 @@
|
||||
local doc = [[
|
||||
/location <query>
|
||||
Returns a location from Google Maps.
|
||||
]]
|
||||
local command = 'location <query>'
|
||||
local doc = [[```
|
||||
/location <query>
|
||||
Returns a location from Google Maps.
|
||||
Alias: /loc
|
||||
```]]
|
||||
|
||||
triggers = {
|
||||
'^/location[@'..bot.username..']*',
|
||||
@ -16,7 +18,7 @@ local action = function(msg)
|
||||
if msg.reply_to_message and msg.reply_to_message.text then
|
||||
input = msg.reply_to_message.text
|
||||
else
|
||||
sendReply(msg, doc)
|
||||
sendMessage(msg.chat.id, doc, true, msg.message_id, true)
|
||||
return
|
||||
end
|
||||
end
|
||||
@ -34,5 +36,6 @@ end
|
||||
return {
|
||||
action = action,
|
||||
triggers = triggers,
|
||||
doc = doc
|
||||
doc = doc,
|
||||
command = command
|
||||
}
|
||||
|
@ -1,7 +1,9 @@
|
||||
local doc = [[
|
||||
/google <query>
|
||||
Returns four (if group) or eight (if private message) results from Google. Safe search is enabled by default, use "/gnsfw" to disable it.
|
||||
]]
|
||||
local command = 'google <query>'
|
||||
local doc = [[```
|
||||
/google <query>
|
||||
Returns four (if group) or eight (if private message) results from Google. Safe search is enabled by default, use "/gnsfw" to disable it.
|
||||
Alias: /g
|
||||
```]]
|
||||
|
||||
local triggers = {
|
||||
'^/g[@'..bot.username..']*$',
|
||||
@ -17,7 +19,7 @@ local action = function(msg)
|
||||
if msg.reply_to_message and msg.reply_to_message.text then
|
||||
input = msg.reply_to_message.text
|
||||
else
|
||||
sendReply(msg, doc)
|
||||
sendMessage(msg.chat.id, doc, true, msg.message_id, true)
|
||||
return
|
||||
end
|
||||
end
|
||||
@ -43,22 +45,36 @@ local action = function(msg)
|
||||
end
|
||||
|
||||
local jdat = JSON.decode(jstr)
|
||||
if #jdat.responseData.results < 1 then
|
||||
if not jdat.responseData then
|
||||
sendReply(msg, config.errors.connection)
|
||||
return
|
||||
end
|
||||
if not jdat.responseData.results[1] then
|
||||
sendReply(msg, config.errors.results)
|
||||
return
|
||||
end
|
||||
|
||||
local message = ''
|
||||
local output = '*Google: Results for* _' .. input .. '_ *:*\n'
|
||||
for i,v in ipairs(jdat.responseData.results) do
|
||||
message = message .. jdat.responseData.results[i].titleNoFormatting .. '\n ' .. jdat.responseData.results[i].unescapedUrl .. '\n'
|
||||
local title = jdat.responseData.results[i].titleNoFormatting:gsub('%[.+%]', ''):gsub('&', '&')
|
||||
if title:len() > 48 then
|
||||
title = title:sub(1, 45) .. '...'
|
||||
end
|
||||
local url = jdat.responseData.results[i].unescapedUrl
|
||||
if url:find('%)') then
|
||||
output = output .. '• ' .. title .. '\n' .. url:gsub('_', '\\_') .. '\n'
|
||||
else
|
||||
output = output .. '• [' .. title .. '](' .. url .. ')\n'
|
||||
end
|
||||
end
|
||||
|
||||
sendReply(msg, message)
|
||||
sendMessage(msg.chat.id, output, true, nil, true)
|
||||
|
||||
end
|
||||
|
||||
return {
|
||||
action = action,
|
||||
triggers = triggers,
|
||||
doc = doc
|
||||
doc = doc,
|
||||
command = command
|
||||
}
|
||||
|
@ -1,7 +1,8 @@
|
||||
local doc = [[
|
||||
/hackernews
|
||||
Returns four (if group) or eight (if private message) top stories from Hacker News.
|
||||
]]
|
||||
local command = 'hackernews'
|
||||
local doc = [[```
|
||||
Returns four (if group) or eight (if private message) top stories from Hacker News.
|
||||
Alias: /hn
|
||||
```]]
|
||||
|
||||
local triggers = {
|
||||
'^/hackernews[@'..bot.username..']*',
|
||||
@ -25,7 +26,7 @@ local action = function(msg)
|
||||
res_count = 8
|
||||
end
|
||||
|
||||
local message = ''
|
||||
local output = '*Hacker News:*\n'
|
||||
for i = 1, res_count do
|
||||
local res_url = 'https://hacker-news.firebaseio.com/v0/item/' .. jdat[i] .. '.json'
|
||||
jstr, res = HTTPS.request(res_url)
|
||||
@ -34,15 +35,26 @@ local action = function(msg)
|
||||
return
|
||||
end
|
||||
local res_jdat = JSON.decode(jstr)
|
||||
message = message .. res_jdat.title .. '\n ' .. res_jdat.url .. '\n'
|
||||
local title = res_jdat.title:gsub('%[.+%]', ''):gsub('%(.+%)', ''):gsub('&', '&')
|
||||
if title:len() > 48 then
|
||||
title = title:sub(1, 45) .. '...'
|
||||
end
|
||||
local url = res_jdat.url
|
||||
if url:find('%(') then
|
||||
output = output .. '• ' .. title .. '\n' .. url:gsub('_', '\\_') .. '\n'
|
||||
else
|
||||
output = output .. '• [' .. title .. '](' .. url .. ')\n'
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
sendReply(msg, message)
|
||||
sendMessage(msg.chat.id, output, true, nil, true)
|
||||
|
||||
end
|
||||
|
||||
return {
|
||||
action = action,
|
||||
triggers = triggers,
|
||||
doc = doc
|
||||
doc = doc,
|
||||
command = command
|
||||
}
|
||||
|
@ -19,10 +19,12 @@ if not hs_dat then
|
||||
|
||||
end
|
||||
|
||||
local doc = [[
|
||||
/hearthstone <query>
|
||||
Returns Hearthstone card info.
|
||||
]]
|
||||
local command = 'hearthstone <query>'
|
||||
local doc = [[```
|
||||
/hearthstone <query>
|
||||
Returns Hearthstone card info.
|
||||
Alias: /hn
|
||||
```]]
|
||||
|
||||
local triggers = {
|
||||
'^/hearthstone[@'..bot.username..']*',
|
||||
@ -65,7 +67,7 @@ local format_card = function(card)
|
||||
if card.text then
|
||||
info = card.text:gsub('</?.->',''):gsub('%$','')
|
||||
if card.flavor then
|
||||
info = info .. '\n' .. card.flavor
|
||||
info = info .. '\n_' .. card.flavor .. '_'
|
||||
end
|
||||
elseif card.flavor then
|
||||
info = card.flavor
|
||||
@ -73,7 +75,7 @@ local format_card = function(card)
|
||||
info = nil
|
||||
end
|
||||
|
||||
local s = card.name .. '\n' .. ctype
|
||||
local s = '*' .. card.name .. '*\n' .. ctype
|
||||
if stats then
|
||||
s = s .. '\n' .. stats
|
||||
end
|
||||
@ -89,7 +91,7 @@ local action = function(msg)
|
||||
|
||||
local input = msg.text_lower:input()
|
||||
if not input then
|
||||
sendReply(msg, doc)
|
||||
sendMessage(msg.chat.id, doc, true, msg.message_id, true)
|
||||
return
|
||||
end
|
||||
|
||||
@ -106,12 +108,13 @@ local action = function(msg)
|
||||
return
|
||||
end
|
||||
|
||||
sendReply(msg, output)
|
||||
sendMessage(msg.chat.id, output, true, msg.message_id, true)
|
||||
|
||||
end
|
||||
|
||||
return {
|
||||
action = action,
|
||||
triggers = triggers,
|
||||
doc = doc
|
||||
doc = doc,
|
||||
command = command
|
||||
}
|
||||
|
@ -1,16 +1,18 @@
|
||||
-- This plugin should go at the end of your plugin list in
|
||||
-- config.lua, but not after greetings.lua.
|
||||
|
||||
local help_text = 'Available commands:\n'
|
||||
local help_text = '*Available commands:*'
|
||||
|
||||
for i,v in ipairs(plugins) do
|
||||
if v.doc then
|
||||
local a = string.sub(v.doc, 1, string.find(v.doc, '\n')-1)
|
||||
help_text = help_text .. a .. '\n'
|
||||
if v.command then
|
||||
help_text = help_text .. '\n /' .. v.command:gsub('%[', '\\[')
|
||||
end
|
||||
end
|
||||
|
||||
local help_text = help_text .. 'Arguments: <required> [optional]'
|
||||
help_text = help_text .. [[\n
|
||||
/help <command>
|
||||
Arguments: <required> \[optional]
|
||||
]]
|
||||
|
||||
local triggers = {
|
||||
'^/help[@'..bot.username..']*',
|
||||
@ -20,16 +22,30 @@ local triggers = {
|
||||
|
||||
local action = function(msg)
|
||||
|
||||
if msg.from.id ~= msg.chat.id then
|
||||
if sendMessage(msg.from.id, help_text) then
|
||||
local input = msg.text_lower:input()
|
||||
|
||||
-- Attempts to send the help message via PM.
|
||||
-- If msg is from a group, it tells the group whether the PM was successful.
|
||||
if not input then
|
||||
local res = sendMessage(msg.from.id, help_text, true, nil, true)
|
||||
if not res then
|
||||
sendReply(msg, 'Please message me privately for a list of commands.')
|
||||
elseif msg.chat.type ~= 'private' then
|
||||
sendReply(msg, 'I have sent you the requested information in a private message.')
|
||||
else
|
||||
sendReply(msg, help_text)
|
||||
end
|
||||
else
|
||||
sendReply(msg, help_text)
|
||||
return
|
||||
end
|
||||
|
||||
for i,v in ipairs(plugins) do
|
||||
if v.command and get_word(v.command, 1) == input and v.doc then
|
||||
local output = '*Help for* _' .. get_word(v.command, 1) .. '_ *:*\n' .. v.doc
|
||||
sendMessage(msg.chat.id, output, true, nil, true)
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
sendReply(msg, 'Sorry, there is no help for that command.')
|
||||
|
||||
end
|
||||
|
||||
return {
|
||||
|
@ -1,7 +1,8 @@
|
||||
local doc = [[
|
||||
/imdb <query>
|
||||
Returns an IMDb entry.
|
||||
]]
|
||||
local command = 'imdb <query>'
|
||||
local doc = [[```
|
||||
/imdb <query>
|
||||
Returns an IMDb entry.
|
||||
```]]
|
||||
|
||||
local triggers = {
|
||||
'^/imdb[@'..bot.username..']*'
|
||||
@ -14,7 +15,7 @@ local action = function(msg)
|
||||
if msg.reply_to_message and msg.reply_to_message.text then
|
||||
input = msg.reply_to_message.text
|
||||
else
|
||||
sendReply(msg, doc)
|
||||
sendMessage(msg.chat.id, doc, true, msg.message_id, true)
|
||||
return
|
||||
end
|
||||
end
|
||||
@ -34,17 +35,18 @@ local action = function(msg)
|
||||
return
|
||||
end
|
||||
|
||||
local message = jdat.Title ..' ('.. jdat.Year ..')\n'
|
||||
message = message .. jdat.imdbRating ..' | '.. jdat.Runtime ..' | '.. jdat.Genre ..'\n'
|
||||
message = message .. jdat.Plot .. '\n'
|
||||
message = message .. 'http://imdb.com/title/' .. jdat.imdbID
|
||||
local output = '[' .. jdat.Title .. '](http://imdb.com/title/'
|
||||
output = output .. jdat.imdbID .. ') ('.. jdat.Year ..')\n'
|
||||
output = output .. jdat.imdbRating ..'/10 | '.. jdat.Runtime ..' | '.. jdat.Genre ..'\n'
|
||||
output = output .. jdat.Plot
|
||||
|
||||
sendReply(msg, message)
|
||||
sendMessage(msg.chat.id, output, true, nil, true)
|
||||
|
||||
end
|
||||
|
||||
return {
|
||||
action = action,
|
||||
triggers = triggers,
|
||||
doc = doc
|
||||
doc = doc,
|
||||
command = command
|
||||
}
|
||||
|
@ -4,13 +4,14 @@ if not config.lastfm_api_key then
|
||||
return
|
||||
end
|
||||
|
||||
local doc = [[
|
||||
/lastfm
|
||||
/np [username]
|
||||
Returns what you are or were last listening to. If you specify a username, info will be returned for that username.
|
||||
/fmset <username>
|
||||
Sets your last.fm username. Otherwise, /np will use your Telegram username. Use "/fmset -" to delete it.
|
||||
]]
|
||||
local command = 'lastfm'
|
||||
local doc = [[```
|
||||
/np [username]
|
||||
Returns what you are or were last listening to. If you specify a username, info will be returned for that username.
|
||||
|
||||
/fmset <username>
|
||||
Sets your last.fm username. Otherwise, /np will use your Telegram username. Use "/fmset -" to delete it.
|
||||
```]]
|
||||
|
||||
local triggers = {
|
||||
'^/lastfm[@'..bot.username..']*',
|
||||
@ -28,7 +29,7 @@ local action = function(msg)
|
||||
return
|
||||
elseif string.match(msg.text, '^/fmset') then
|
||||
if not input then
|
||||
sendReply(msg, doc)
|
||||
sendMessage(msg.chat.id, doc, true, msg.message_id, true)
|
||||
elseif input == '-' then
|
||||
lastfm[msg.from.id_str] = nil
|
||||
sendReply(msg, 'Your last.fm username has been forgotten.')
|
||||
@ -101,5 +102,6 @@ end
|
||||
return {
|
||||
action = action,
|
||||
triggers = triggers,
|
||||
doc = doc
|
||||
doc = doc,
|
||||
command = command
|
||||
}
|
||||
|
@ -1,7 +1,8 @@
|
||||
local doc = [[
|
||||
/nick <nickname>
|
||||
Set your nickname. Use "/whoami" to check your nickname and "/nick -" to delete it.
|
||||
]]
|
||||
local command = 'nick <nickname>'
|
||||
local doc = [[```
|
||||
/nick <nickname>
|
||||
Set your nickname. Use "/whoami" to check your nickname and "/nick -" to delete it.
|
||||
```]]
|
||||
|
||||
local triggers = {
|
||||
'^/nick[@'..bot.username..']*'
|
||||
@ -11,7 +12,7 @@ local action = function(msg)
|
||||
|
||||
local input = msg.text:input()
|
||||
if not input then
|
||||
sendReply(msg, doc)
|
||||
sendMessage(msg.chat.id, doc, true, msg.message_id, true)
|
||||
return true
|
||||
end
|
||||
|
||||
@ -38,5 +39,6 @@ end
|
||||
return {
|
||||
action = action,
|
||||
triggers = triggers,
|
||||
doc = doc
|
||||
doc = doc,
|
||||
command = command
|
||||
}
|
||||
|
@ -1,7 +1,9 @@
|
||||
local doc = [[
|
||||
/pokedex <query>
|
||||
Returns a Pokedex entry from pokeapi.co.
|
||||
]]
|
||||
local command = 'pokedex <query>'
|
||||
local doc = [[```
|
||||
/pokedex <query>
|
||||
Returns a Pokedex entry from pokeapi.co.
|
||||
Alias: /dex
|
||||
```]]
|
||||
|
||||
local triggers = {
|
||||
'^/pokedex[@'..bot.username..']*',
|
||||
@ -15,7 +17,7 @@ local action = function(msg)
|
||||
if msg.reply_to_message and msg.reply_to_message.text then
|
||||
input = msg.reply_to_message.text
|
||||
else
|
||||
sendReply(msg, doc)
|
||||
sendMessage(msg.chat.id, doc, true, msg.message_id, true)
|
||||
return
|
||||
end
|
||||
end
|
||||
@ -51,14 +53,16 @@ local action = function(msg)
|
||||
end
|
||||
poke_type = poke_type .. ' type'
|
||||
|
||||
local message = dex_jdat.name .. ' #' .. dex_jdat.national_id .. '\n' .. poke_type .. '\nHeight: ' .. dex_jdat.height/10 .. 'm, Weight: ' .. dex_jdat.weight/10 .. 'kg\n' .. desc_jdat.description:gsub('POKMON', 'POKeMON')
|
||||
local output = '*' .. dex_jdat.name .. '*\n#' .. dex_jdat.national_id .. ' | ' .. poke_type .. '\n_' .. desc_jdat.description:gsub('POKMON', 'Pokémon'):gsub('Pokmon', 'Pokémon') .. '_'
|
||||
|
||||
sendReply(msg, message)
|
||||
|
||||
sendMessage(msg.chat.id, output, true, nil, true)
|
||||
|
||||
end
|
||||
|
||||
return {
|
||||
action = action,
|
||||
triggers = triggers,
|
||||
doc = doc
|
||||
doc = doc,
|
||||
command = command
|
||||
}
|
||||
|
@ -1,7 +1,5 @@
|
||||
local doc = [[
|
||||
/pun
|
||||
Returns a pun.
|
||||
]]
|
||||
local command = 'pun'
|
||||
local doc = '`Returns a pun.`'
|
||||
|
||||
local triggers = {
|
||||
'^/pun[@'..bot.username..']*'
|
||||
@ -140,5 +138,6 @@ end
|
||||
return {
|
||||
action = action,
|
||||
triggers = triggers,
|
||||
doc = doc
|
||||
doc = doc,
|
||||
command = command
|
||||
}
|
||||
|
@ -1,7 +1,5 @@
|
||||
local doc = [[
|
||||
/reactions
|
||||
Returns a list of "reaction" emoticon commands.
|
||||
]]
|
||||
local command = 'reactions'
|
||||
local doc = '`Returns a list of "reaction" emoticon commands.`'
|
||||
|
||||
local triggers = {
|
||||
['¯\\_(ツ)_/¯'] = '/shrug$',
|
||||
@ -33,5 +31,6 @@ end
|
||||
return {
|
||||
action = action,
|
||||
triggers = triggers,
|
||||
doc = doc
|
||||
doc = doc,
|
||||
command = command
|
||||
}
|
||||
|
@ -1,7 +1,9 @@
|
||||
local doc = [[
|
||||
/reddit [r/subreddit | query]
|
||||
Returns the four (if group) or eight (if private message) top posts for the given subreddit or query, or from the frontpage.
|
||||
]]
|
||||
local command = 'reddit [r/subreddit | query]'
|
||||
local doc = [[```
|
||||
/reddit [r/subreddit | query]
|
||||
Returns the four (if group) or eight (if private message) top posts for the given subreddit or query, or from the frontpage.
|
||||
Aliases: /r, /r/[subreddit]
|
||||
```]]
|
||||
|
||||
local triggers = {
|
||||
'^/reddit[@'..bot.username..']*',
|
||||
@ -21,14 +23,18 @@ local action = function(msg)
|
||||
limit = 8
|
||||
end
|
||||
|
||||
local source
|
||||
if input then
|
||||
if input:match('^r/') then
|
||||
if input:match('^r/.') then
|
||||
url = 'http://www.reddit.com/' .. input .. '/.json?limit=' .. limit
|
||||
source = '*/r/' .. input:match('^r/(.+)') .. '*\n'
|
||||
else
|
||||
url = 'http://www.reddit.com/search.json?q=' .. input .. '&limit=' .. limit
|
||||
source = '*reddit: Results for* _' .. input .. '_ *:*\n'
|
||||
end
|
||||
else
|
||||
url = 'http://www.reddit.com/.json?limit=' .. limit
|
||||
source = '*/r/all*\n'
|
||||
end
|
||||
|
||||
local jstr, res = HTTP.request(url)
|
||||
@ -43,25 +49,31 @@ local action = function(msg)
|
||||
return
|
||||
end
|
||||
|
||||
local message = ''
|
||||
local output = ''
|
||||
for i,v in ipairs(jdat.data.children) do
|
||||
local title = v.data.title:gsub('%[.+%]', ''):gsub('&', '&')
|
||||
if title:len() > 48 then
|
||||
title = title:sub(1,45) .. '...'
|
||||
end
|
||||
if v.data.over_18 then
|
||||
message = message .. '[NSFW] '
|
||||
v.data.is_self = true
|
||||
end
|
||||
local long_url = '\n'
|
||||
local short_url = 'redd.it/' .. v.data.id
|
||||
output = output .. '• [' .. title .. '](' .. short_url .. ')\n'
|
||||
if not v.data.is_self then
|
||||
long_url = '\n' .. v.data.url .. '\n'
|
||||
output = output .. v.data.url:gsub('_', '\\_') .. '\n'
|
||||
end
|
||||
local short_url = '[redd.it/' .. v.data.id .. '] '
|
||||
message = message .. short_url .. v.data.title .. long_url
|
||||
end
|
||||
|
||||
sendReply(msg, message)
|
||||
output = source .. output
|
||||
|
||||
sendMessage(msg.chat.id, output, true, nil, true)
|
||||
|
||||
end
|
||||
|
||||
return {
|
||||
action = action,
|
||||
triggers = triggers,
|
||||
doc = doc
|
||||
doc = doc,
|
||||
command = command
|
||||
}
|
||||
|
@ -1,7 +1,8 @@
|
||||
local doc = [[
|
||||
/shout <term>
|
||||
Shout something!
|
||||
]]
|
||||
local command = 'shout <text>'
|
||||
local doc = [[```
|
||||
/shout <text>
|
||||
Shouts something.
|
||||
```]]
|
||||
|
||||
local triggers = {
|
||||
'^/shout[@'..bot.username..']*'
|
||||
@ -12,7 +13,7 @@ local action = function(msg)
|
||||
local input = msg.text:input()
|
||||
|
||||
if not input then
|
||||
sendReply(msg, doc)
|
||||
sendMessage(msg.chat.id, doc, true, msg.message_id, true)
|
||||
return
|
||||
end
|
||||
input = input:trim()
|
||||
@ -44,5 +45,6 @@ end
|
||||
return {
|
||||
action = action,
|
||||
triggers = triggers,
|
||||
doc = doc
|
||||
doc = doc,
|
||||
command = command
|
||||
}
|
||||
|
@ -1,7 +1,8 @@
|
||||
local doc = [[
|
||||
/slap [target]
|
||||
Give someone a good slap (or worse) through reply or specification of a target.
|
||||
]]
|
||||
local command = 'slap [target]'
|
||||
local doc = [[```
|
||||
/slap [target]
|
||||
Slap somebody.
|
||||
```]]
|
||||
|
||||
local triggers = {
|
||||
'^/slap[@'..bot.username..']*'
|
||||
@ -125,5 +126,6 @@ end
|
||||
return {
|
||||
action = action,
|
||||
triggers = triggers,
|
||||
doc = doc
|
||||
doc = doc,
|
||||
command = command
|
||||
}
|
||||
|
@ -1,7 +1,8 @@
|
||||
local doc = [[
|
||||
/time <location>
|
||||
Returns the time, date, and timezone for the given location.
|
||||
]]
|
||||
local command = 'time <location>'
|
||||
local doc = [[```
|
||||
/time <location>
|
||||
Returns the time, date, and timezone for the given location.
|
||||
```]]
|
||||
|
||||
local triggers = {
|
||||
'^/time[@'..bot.username..']*'
|
||||
@ -14,7 +15,7 @@ local action = function(msg)
|
||||
if msg.reply_to_message and msg.reply_to_message.text then
|
||||
input = msg.reply_to_message.text
|
||||
else
|
||||
sendReply(msg, doc)
|
||||
sendMessage(msg.chat.id, doc, true, msg.message_id, true)
|
||||
return
|
||||
end
|
||||
end
|
||||
@ -49,5 +50,6 @@ end
|
||||
return {
|
||||
action = action,
|
||||
triggers = triggers,
|
||||
doc = doc
|
||||
doc = doc,
|
||||
command = command
|
||||
}
|
||||
|
@ -1,7 +1,8 @@
|
||||
local doc = [[
|
||||
/translate [text]
|
||||
Translates input or the replied-to message into the bot's language.
|
||||
]]
|
||||
local command = 'translate [text]'
|
||||
local doc = [[```
|
||||
/translate [text]
|
||||
Translates input or the replied-to message into the bot's language.
|
||||
```]]
|
||||
|
||||
local triggers = {
|
||||
'^/translate[@'..bot.username..']*'
|
||||
@ -14,7 +15,7 @@ local action = function(msg)
|
||||
if msg.reply_to_message and msg.reply_to_message.text then
|
||||
input = msg.reply_to_message.text
|
||||
else
|
||||
sendReply(msg, doc)
|
||||
sendMessage(msg.chat.id, doc, true, msg.message_id, true)
|
||||
return
|
||||
end
|
||||
end
|
||||
@ -36,5 +37,6 @@ end
|
||||
return {
|
||||
action = action,
|
||||
triggers = triggers,
|
||||
doc = doc
|
||||
doc = doc,
|
||||
command = command
|
||||
}
|
||||
|
@ -1,7 +1,9 @@
|
||||
local doc = [[
|
||||
/urbandictionary <query>
|
||||
Returns a definition from Urban Dictionary.
|
||||
]]
|
||||
local command = 'urbandictionary <query>'
|
||||
local doc = [[```
|
||||
/urbandictionary <query>
|
||||
Returns a definition from Urban Dictionary.
|
||||
Aliases: /ud, /urban
|
||||
```]]
|
||||
|
||||
local triggers = {
|
||||
'^/urbandictionary[@'..bot.username..']*',
|
||||
@ -17,7 +19,7 @@ local action = function(msg)
|
||||
if msg.reply_to_message and msg.reply_to_message.text then
|
||||
input = msg.reply_to_message.text
|
||||
else
|
||||
sendReply(msg, doc)
|
||||
sendMessage(msg.chat.id, doc, true, msg.message_id, true)
|
||||
return
|
||||
end
|
||||
end
|
||||
@ -36,17 +38,20 @@ local action = function(msg)
|
||||
return
|
||||
end
|
||||
|
||||
local message = '"' .. jdat.list[1].word .. '"\n' .. jdat.list[1].definition:trim()
|
||||
local output = '*' .. jdat.list[1].word .. '*\n\n' .. jdat.list[1].definition:trim()
|
||||
if string.len(jdat.list[1].example) > 0 then
|
||||
message = message .. '\n\nExample:\n' .. jdat.list[1].example:trim()
|
||||
output = output .. '_\n\n' .. jdat.list[1].example:trim() .. '_'
|
||||
end
|
||||
|
||||
sendReply(msg, message)
|
||||
output = output:gsub('%[', ''):gsub('%]', '')
|
||||
|
||||
sendMessage(msg.chat.id, output, true, nil, true)
|
||||
|
||||
end
|
||||
|
||||
return {
|
||||
action = action,
|
||||
triggers = triggers,
|
||||
doc = doc
|
||||
doc = doc,
|
||||
command = command
|
||||
}
|
||||
|
@ -4,10 +4,11 @@ if not config.owm_api_key then
|
||||
return
|
||||
end
|
||||
|
||||
local doc = [[
|
||||
/weather <location>
|
||||
Returns the current weather conditions for a given location.
|
||||
]]
|
||||
local command = 'weather <location>'
|
||||
local doc = [[```
|
||||
/weather <location>
|
||||
Returns the current weather conditions for a given location.
|
||||
```]]
|
||||
|
||||
local triggers = {
|
||||
'^/weather[@'..bot.username..']*'
|
||||
@ -20,7 +21,7 @@ local action = function(msg)
|
||||
if msg.reply_to_message and msg.reply_to_message.text then
|
||||
input = msg.reply_to_message.text
|
||||
else
|
||||
sendReply(msg, doc)
|
||||
sendMessage(msg.chat.id, doc, true, msg.message_id, true)
|
||||
return
|
||||
end
|
||||
end
|
||||
@ -52,5 +53,6 @@ end
|
||||
return {
|
||||
action = action,
|
||||
triggers = triggers,
|
||||
doc = doc
|
||||
doc = doc,
|
||||
command = command
|
||||
}
|
||||
|
@ -1,3 +1,9 @@
|
||||
local command = 'whoami'
|
||||
local doc = [[```
|
||||
Returns user and chat info for you or the replied-to message.
|
||||
Alias: /who
|
||||
```]]
|
||||
|
||||
local triggers = {
|
||||
'^/who[ami]*[@'..bot.username..']*$'
|
||||
}
|
||||
@ -37,5 +43,7 @@ end
|
||||
|
||||
return {
|
||||
action = action,
|
||||
triggers = triggers
|
||||
triggers = triggers,
|
||||
doc = doc,
|
||||
command = command
|
||||
}
|
||||
|
@ -1,7 +1,9 @@
|
||||
local doc = [[
|
||||
/wikipedia <query>
|
||||
Returns an article from Wikipedia.
|
||||
]]
|
||||
local command = 'wikipedia <query>'
|
||||
local doc = [[```
|
||||
/wikipedia <query>
|
||||
Returns an article from Wikipedia.
|
||||
Aliases: /w, /wiki
|
||||
```]]
|
||||
|
||||
local triggers = {
|
||||
'^/wikipedia[@'..bot.username..']*',
|
||||
@ -17,7 +19,7 @@ local action = function(msg)
|
||||
if msg.reply_to_message and msg.reply_to_message.text then
|
||||
input = msg.reply_to_message.text
|
||||
else
|
||||
sendReply(msg, doc)
|
||||
sendMessage(msg.chat.id, doc, true, msg.message_id, true)
|
||||
return
|
||||
end
|
||||
end
|
||||
@ -32,6 +34,10 @@ local action = function(msg)
|
||||
end
|
||||
|
||||
local jdat = JSON.decode(jstr)
|
||||
if not jdat.responseData then
|
||||
sendReply(msg, config.errors.connection)
|
||||
return
|
||||
end
|
||||
if not jdat.responseData.results[1] then
|
||||
sendReply(msg, config.errors.results)
|
||||
return
|
||||
@ -61,14 +67,24 @@ local action = function(msg)
|
||||
if l then
|
||||
text = text:sub(1, l-1)
|
||||
end
|
||||
text = text .. '\n' .. url
|
||||
|
||||
sendReply(msg, text)
|
||||
title = title:gsub('%(.+%)', '')
|
||||
--local output = '[' .. title .. '](' .. url .. ')\n' .. text:gsub('%[.+]%','')
|
||||
--local output = '*' .. title .. '*\n' .. text:gsub('%[.+]%','') .. '\n[Read more.](' .. url .. ')'
|
||||
local output = text:gsub('%[.+%]',''):gsub(title, '*'..title..'*') .. '\n'
|
||||
if url:find('%(') then
|
||||
output = output .. url:gsub('_', '\\_')
|
||||
else
|
||||
output = output .. '[Read more.](' .. url .. ')'
|
||||
end
|
||||
|
||||
sendMessage(msg.chat.id, output, true, nil, true)
|
||||
|
||||
end
|
||||
|
||||
return {
|
||||
action = action,
|
||||
triggers = triggers,
|
||||
doc = doc
|
||||
doc = doc,
|
||||
command = command
|
||||
}
|
||||
|
@ -1,7 +1,8 @@
|
||||
local doc = [[
|
||||
/xkcd [query]
|
||||
Returns an xkcd strip and its alt text. If there is no query, it will be randomized.
|
||||
]]
|
||||
local command = 'xkcd [query]'
|
||||
local doc = [[```
|
||||
/xkcd [query]
|
||||
Returns an xkcd strip and its alt text. If there is no query, it will be randomized.
|
||||
```]]
|
||||
|
||||
local triggers = {
|
||||
'^/xkcd[@'..bot.username..']*'
|
||||
@ -44,13 +45,15 @@ local action = function(msg)
|
||||
end
|
||||
local jdat = JSON.decode(jstr)
|
||||
|
||||
local message = '[' .. jdat.num .. '] ' .. jdat.alt .. '\n' .. jdat.img
|
||||
sendMessage(msg.chat.id, message, false, msg.message_id)
|
||||
local output = '[' .. jdat.num .. '](' .. jdat.img .. ')\n' .. jdat.alt
|
||||
|
||||
sendMessage(msg.chat.id, output, false, nil, true)
|
||||
|
||||
end
|
||||
|
||||
return {
|
||||
action = action,
|
||||
triggers = triggers,
|
||||
doc = doc
|
||||
doc = doc,
|
||||
command = command
|
||||
}
|
||||
|
@ -1,9 +1,11 @@
|
||||
-- Thanks to @TiagoDanin for writing the original plugin.
|
||||
|
||||
local doc = [[
|
||||
/youtube <query>
|
||||
Returns the top result from YouTube.
|
||||
]]
|
||||
local command = 'youtube <query>'
|
||||
local doc = [[```
|
||||
/youtube <query>
|
||||
Returns the top result from YouTube.
|
||||
Alias: /yt
|
||||
```]]
|
||||
|
||||
local triggers = {
|
||||
'^/youtube[@'..bot.username..']*',
|
||||
@ -18,7 +20,7 @@ local action = function(msg)
|
||||
if msg.reply_to_message and msg.reply_to_message.text then
|
||||
input = msg.reply_to_message.text
|
||||
else
|
||||
sendReply(msg, doc)
|
||||
sendMessage(msg.chat.id, doc, true, msg.message_id, true)
|
||||
return
|
||||
end
|
||||
end
|
||||
@ -42,5 +44,6 @@ end
|
||||
return {
|
||||
action = action,
|
||||
triggers = triggers,
|
||||
doc = doc
|
||||
doc = doc,
|
||||
command = command
|
||||
}
|
||||
|
@ -3,6 +3,9 @@
|
||||
|
||||
function get_word(s, i) -- get the indexed word in a string
|
||||
|
||||
s = s or ''
|
||||
i = i or 1
|
||||
|
||||
local t = {}
|
||||
for w in s:gmatch('%g+') do
|
||||
table.insert(t, w)
|
||||
|
Reference in New Issue
Block a user