Fully use utilities.CMD_PAT (née INVOCATION_PATTERN).
This commit is contained in:
parent
6a13d523fb
commit
ed6b536a46
4
bot.lua
4
bot.lua
@ -61,8 +61,8 @@ function bot:on_msg_receive(msg, config) -- The fn run whenever a message is rec
|
|||||||
|
|
||||||
msg = utilities.enrich_message(msg)
|
msg = utilities.enrich_message(msg)
|
||||||
|
|
||||||
if msg.text:match('^/start .+') then
|
if msg.text:match('^'..utilities.CMD_PAT..'start .+') then
|
||||||
msg.text = '/' .. utilities.input(msg.text)
|
msg.text = utilities.CMD_PAT .. utilities.input(msg.text)
|
||||||
msg.text_lower = msg.text:lower()
|
msg.text_lower = msg.text:lower()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -19,9 +19,9 @@ function about:action(msg, config)
|
|||||||
local output = config.about_text .. '\nBased on otouto v'..bot.version..' by topkecleon.'
|
local output = config.about_text .. '\nBased on otouto v'..bot.version..' by topkecleon.'
|
||||||
|
|
||||||
if (msg.new_chat_participant and msg.new_chat_participant.id == self.info.id)
|
if (msg.new_chat_participant and msg.new_chat_participant.id == self.info.id)
|
||||||
or msg.text_lower:match('^/about')
|
or msg.text_lower:match('^'..utilities.CMD_PAT..'about')
|
||||||
or msg.text_lower:match('^/about@'..self.info.username:lower())
|
or msg.text_lower:match('^'..utilities.CMD_PAT..'about@'..self.info.username:lower())
|
||||||
or msg.text_lower:match('^/start') then
|
or msg.text_lower:match('^'..utilities.CMD_PAT..'start') then
|
||||||
utilities.send_message(self, msg.chat.id, output, true)
|
utilities.send_message(self, msg.chat.id, output, true)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
@ -75,8 +75,8 @@ administration.flags = {
|
|||||||
name = 'unlisted',
|
name = 'unlisted',
|
||||||
desc = 'Removes this group from the group listing.',
|
desc = 'Removes this group from the group listing.',
|
||||||
short = 'This group is unlisted.',
|
short = 'This group is unlisted.',
|
||||||
enabled = 'This group is no longer listed in /groups.',
|
enabled = 'This group is no longer listed in '..utilities.CMD_PAT..'groups.',
|
||||||
disabled = 'This group is now listed in /groups.'
|
disabled = 'This group is now listed in '..utilities.CMD_PAT..'groups.'
|
||||||
},
|
},
|
||||||
[2] = {
|
[2] = {
|
||||||
name = 'antisquig',
|
name = 'antisquig',
|
||||||
@ -105,7 +105,7 @@ administration.flags = {
|
|||||||
name = 'antiflood',
|
name = 'antiflood',
|
||||||
desc = 'Prevents flooding by rate-limiting messages per user.',
|
desc = 'Prevents flooding by rate-limiting messages per user.',
|
||||||
short = 'This group automatically removes users who flood.',
|
short = 'This group automatically removes users who flood.',
|
||||||
enabled = 'Users will now be removed automatically for excessive messages. Use /antiflood to configure limits.',
|
enabled = 'Users will now be removed automatically for excessive messages. Use '..utilities.CMD_PAT..'antiflood to configure limits.',
|
||||||
disabled = 'Users will no longer be removed automatically for excessive messages.',
|
disabled = 'Users will no longer be removed automatically for excessive messages.',
|
||||||
kicked = 'You were automatically kicked from GROUPNAME for flooding.'
|
kicked = 'You were automatically kicked from GROUPNAME for flooding.'
|
||||||
},
|
},
|
||||||
@ -237,7 +237,7 @@ function administration:get_desc(chat_id)
|
|||||||
if modstring ~= '' then
|
if modstring ~= '' then
|
||||||
table.insert(t, '*Moderators:*\n' .. utilities.trim(modstring))
|
table.insert(t, '*Moderators:*\n' .. utilities.trim(modstring))
|
||||||
end
|
end
|
||||||
table.insert(t, 'Run /ahelp@' .. self.info.username .. ' for a list of commands.')
|
table.insert(t, 'Run '..utilities.CMD_PAT..'ahelp@' .. self.info.username .. ' for a list of commands.')
|
||||||
return table.concat(t, '\n\n')
|
return table.concat(t, '\n\n')
|
||||||
|
|
||||||
end
|
end
|
||||||
@ -250,7 +250,7 @@ function administration:update_desc(chat)
|
|||||||
local gov = self.database.users[tostring(group.governor)]
|
local gov = self.database.users[tostring(group.governor)]
|
||||||
desc = desc .. '\nGovernor: ' .. utilities.build_name(gov.first_name, gov.last_name) .. ' [' .. gov.id .. ']\n'
|
desc = desc .. '\nGovernor: ' .. utilities.build_name(gov.first_name, gov.last_name) .. ' [' .. gov.id .. ']\n'
|
||||||
end
|
end
|
||||||
local s = '\n/desc@' .. self.info.username .. ' for more information.'
|
local s = '\n'..utilities.CMD_PAT..'desc@' .. self.info.username .. ' for more information.'
|
||||||
desc = desc:sub(1, 250-s:len()) .. s
|
desc = desc:sub(1, 250-s:len()) .. s
|
||||||
drua.channel_set_about(chat, desc)
|
drua.channel_set_about(chat, desc)
|
||||||
end
|
end
|
||||||
@ -521,11 +521,11 @@ function administration.init_command(self_, config)
|
|||||||
local rank = administration.get_rank(self, msg.from.id, msg.chat.id, config)
|
local rank = administration.get_rank(self, msg.from.id, msg.chat.id, config)
|
||||||
local input = utilities.get_word(msg.text_lower, 2)
|
local input = utilities.get_word(msg.text_lower, 2)
|
||||||
if input then
|
if input then
|
||||||
input = input:gsub('^/', '')
|
input = input:gsub('^'..utilities.CMD_PAT..'', '')
|
||||||
local doc
|
local doc
|
||||||
for _,action in ipairs(administration.commands) do
|
for _,action in ipairs(administration.commands) do
|
||||||
if action.keyword == input then
|
if action.keyword == input then
|
||||||
doc = '/' .. action.command:gsub('\\','') .. '\n' .. action.doc
|
doc = ''..utilities.CMD_PAT..'' .. action.command:gsub('\\','') .. '\n' .. action.doc
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -533,14 +533,14 @@ function administration.init_command(self_, config)
|
|||||||
local output = '*Help for* _' .. input .. '_ :\n```\n' .. doc .. '\n```'
|
local output = '*Help for* _' .. input .. '_ :\n```\n' .. doc .. '\n```'
|
||||||
utilities.send_message(self, msg.chat.id, output, true, nil, true)
|
utilities.send_message(self, msg.chat.id, output, true, nil, true)
|
||||||
else
|
else
|
||||||
local output = 'Sorry, there is no help for that command.\n/ahelp@'..self.info.username
|
local output = 'Sorry, there is no help for that command.\n'..utilities.CMD_PAT..'ahelp@'..self.info.username
|
||||||
utilities.send_reply(self, msg, output)
|
utilities.send_reply(self, msg, output)
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
local output = '*Commands for ' .. administration.ranks[rank] .. ':*\n'
|
local output = '*Commands for ' .. administration.ranks[rank] .. ':*\n'
|
||||||
for i = 1, rank do
|
for i = 1, rank do
|
||||||
for _, val in ipairs(self.admin_temp.help[i]) do
|
for _, val in ipairs(self.admin_temp.help[i]) do
|
||||||
output = output .. '• /' .. val .. '\n'
|
output = output .. '• ' .. utilities.CMD_PAT .. val .. '\n'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
output = output .. 'Arguments: <required> \\[optional]'
|
output = output .. 'Arguments: <required> \\[optional]'
|
||||||
@ -771,7 +771,7 @@ function administration.init_command(self_, config)
|
|||||||
doc = 'Sets the group\'s rules. Rules will be automatically numbered. Separate rules with a new line. Markdown is supported. Pass "--" to delete the rules.',
|
doc = 'Sets the group\'s rules. Rules will be automatically numbered. Separate rules with a new line. Markdown is supported. Pass "--" to delete the rules.',
|
||||||
|
|
||||||
action = function(self, msg, group, config)
|
action = function(self, msg, group, config)
|
||||||
local input = msg.text:match('^/setrules[@'..self.info.username..']*(.+)')
|
local input = msg.text:match('^'..utilities.CMD_PAT..'setrules[@'..self.info.username..']*(.+)')
|
||||||
if input == ' --' or input == ' ' .. utilities.char.em_dash then
|
if input == ' --' or input == ' ' .. utilities.char.em_dash then
|
||||||
group.rules = {}
|
group.rules = {}
|
||||||
utilities.send_reply(self, msg, 'The rules have been cleared.')
|
utilities.send_reply(self, msg, 'The rules have been cleared.')
|
||||||
@ -802,7 +802,7 @@ function administration.init_command(self_, config)
|
|||||||
|
|
||||||
action = function(self, msg, group, config)
|
action = function(self, msg, group, config)
|
||||||
local input = utilities.input(msg.text)
|
local input = utilities.input(msg.text)
|
||||||
local output = 'usage: `/changerule <i> <newrule>`'
|
local output = 'usage: `'..utilities.CMD_PAT..'changerule <i> <newrule>`'
|
||||||
if input then
|
if input then
|
||||||
local rule_num = tonumber(input:match('^%d+'))
|
local rule_num = tonumber(input:match('^%d+'))
|
||||||
local new_rule = utilities.input(input)
|
local new_rule = utilities.input(input)
|
||||||
@ -944,7 +944,7 @@ function administration.init_command(self_, config)
|
|||||||
|
|
||||||
action = function(self, msg, group, config)
|
action = function(self, msg, group, config)
|
||||||
if not group.flags[5] then
|
if not group.flags[5] then
|
||||||
utilities.send_message(self, msg.chat.id, 'antiflood is not enabled. Use `/flag 5` to enable it.', true, nil, true)
|
utilities.send_message(self, msg.chat.id, 'antiflood is not enabled. Use `'..utilities.CMD_PAT..'flag 5` to enable it.', true, nil, true)
|
||||||
else
|
else
|
||||||
if not group.antiflood then
|
if not group.antiflood then
|
||||||
group.antiflood = JSON.decode(JSON.encode(administration.antiflood))
|
group.antiflood = JSON.decode(JSON.encode(administration.antiflood))
|
||||||
@ -963,7 +963,7 @@ function administration.init_command(self_, config)
|
|||||||
output = '*' .. key:gsub('^%l', string.upper) .. '* messages are now worth *' .. val .. '* points.'
|
output = '*' .. key:gsub('^%l', string.upper) .. '* messages are now worth *' .. val .. '* points.'
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
output = 'usage: `/antiflood <type> <i>`\nexample: `/antiflood text 5`\nUse this command to configure the point values for each message type. When a user reaches 100 points, he is kicked. The points are reset each minute. The current values are:\n'
|
output = 'usage: `'..utilities.CMD_PAT..'antiflood <type> <i>`\nexample: `'..utilities.CMD_PAT..'antiflood text 5`\nUse this command to configure the point values for each message type. When a user reaches 100 points, he is kicked. The points are reset each minute. The current values are:\n'
|
||||||
for k,v in pairs(group.antiflood) do
|
for k,v in pairs(group.antiflood) do
|
||||||
output = output .. '*'..k..':* `'..v..'`\n'
|
output = output .. '*'..k..':* `'..v..'`\n'
|
||||||
end
|
end
|
||||||
@ -1389,6 +1389,6 @@ function administration:cron()
|
|||||||
end
|
end
|
||||||
|
|
||||||
administration.command = 'groups'
|
administration.command = 'groups'
|
||||||
administration.doc = '`Returns a list of administrated groups.\nUse /ahelp for more administrative commands.`'
|
administration.doc = '`Returns a list of administrated groups.\nUse '..utilities.CMD_PAT..'ahelp for more administrative commands.`'
|
||||||
|
|
||||||
return administration
|
return administration
|
||||||
|
@ -9,12 +9,12 @@ local utilities = require('utilities')
|
|||||||
|
|
||||||
apod.command = 'apod [date]'
|
apod.command = 'apod [date]'
|
||||||
apod.doc = [[```
|
apod.doc = [[```
|
||||||
/apod [query]
|
]]..utilities.CMD_PAT..[[apod [query]
|
||||||
Returns the Astronomy Picture of the Day.
|
Returns the Astronomy Picture of the Day.
|
||||||
If the query is a date, in the format YYYY-MM-DD, the APOD of that day is returned.
|
If the query is a date, in the format YYYY-MM-DD, the APOD of that day is returned.
|
||||||
/apodhd [query]
|
]]..utilities.CMD_PAT..[[apodhd [query]
|
||||||
Returns the image in HD, if available.
|
Returns the image in HD, if available.
|
||||||
/apodtext [query]
|
]]..utilities.CMD_PAT..[[apodtext [query]
|
||||||
Returns the explanation of the APOD.
|
Returns the explanation of the APOD.
|
||||||
Source: nasa.gov
|
Source: nasa.gov
|
||||||
```]]
|
```]]
|
||||||
@ -65,13 +65,13 @@ function apod:action(msg, config)
|
|||||||
|
|
||||||
local img_url = jdat.url
|
local img_url = jdat.url
|
||||||
|
|
||||||
if string.match(msg.text, '^/apodhd*') then
|
if string.match(msg.text, '^'..utilities.CMD_PAT..'apodhd*') then
|
||||||
img_url = jdat.hdurl or jdat.url
|
img_url = jdat.hdurl or jdat.url
|
||||||
end
|
end
|
||||||
|
|
||||||
local output = date .. '[' .. jdat.title .. '](' .. img_url .. ')'
|
local output = date .. '[' .. jdat.title .. '](' .. img_url .. ')'
|
||||||
|
|
||||||
if string.match(msg.text, '^/apodtext*') then
|
if string.match(msg.text, '^'..utilities.CMD_PAT..'apodtext*') then
|
||||||
output = output .. '\n' .. jdat.explanation
|
output = output .. '\n' .. jdat.explanation
|
||||||
disable_page_preview = true
|
disable_page_preview = true
|
||||||
end
|
end
|
||||||
|
@ -5,7 +5,7 @@ local utilities = require('utilities')
|
|||||||
bandersnatch.command = 'bandersnatch'
|
bandersnatch.command = 'bandersnatch'
|
||||||
bandersnatch.doc = [[```
|
bandersnatch.doc = [[```
|
||||||
Shun the frumious Bandersnatch.
|
Shun the frumious Bandersnatch.
|
||||||
Alias: /bc
|
Alias: ]]..utilities.CMD_PAT..[[bc
|
||||||
```]]
|
```]]
|
||||||
|
|
||||||
function bandersnatch:init()
|
function bandersnatch:init()
|
||||||
|
@ -16,9 +16,9 @@ end
|
|||||||
|
|
||||||
bible.command = 'bible <reference>'
|
bible.command = 'bible <reference>'
|
||||||
bible.doc = [[```
|
bible.doc = [[```
|
||||||
/bible <reference>
|
]]..utilities.CMD_PAT..[[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.
|
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
|
Alias: ]]..utilities.CMD_PAT..[[b
|
||||||
```]]
|
```]]
|
||||||
|
|
||||||
function bible:action(msg, config)
|
function bible:action(msg, config)
|
||||||
|
@ -19,7 +19,7 @@ function blacklist:action(msg, config)
|
|||||||
|
|
||||||
if self.database.blacklist[msg.from.id_str] then return end
|
if self.database.blacklist[msg.from.id_str] then return end
|
||||||
if self.database.blacklist[msg.chat.id_str] then return end
|
if self.database.blacklist[msg.chat.id_str] then return end
|
||||||
if not msg.text:match('^/blacklist') then return true end
|
if not msg.text:match('^'..utilities.CMD_PAT..'blacklist') then return true end
|
||||||
if msg.from.id ~= config.admin then return end
|
if msg.from.id ~= config.admin then return end
|
||||||
|
|
||||||
local target = utilities.user_from_message(self, msg)
|
local target = utilities.user_from_message(self, msg)
|
||||||
|
@ -6,7 +6,7 @@ local utilities = require('utilities')
|
|||||||
|
|
||||||
calc.command = 'calc <expression>'
|
calc.command = 'calc <expression>'
|
||||||
calc.doc = [[```
|
calc.doc = [[```
|
||||||
/calc <expression>
|
]]..utilities.CMD_PAT..[[calc <expression>
|
||||||
Returns solutions to mathematical expressions and conversions between common units. Results provided by mathjs.org.
|
Returns solutions to mathematical expressions and conversions between common units. Results provided by mathjs.org.
|
||||||
```]]
|
```]]
|
||||||
|
|
||||||
|
@ -34,7 +34,7 @@ function chatter:action(msg, config)
|
|||||||
--Uncomment the following line for Al Gore-like conversation.
|
--Uncomment the following line for Al Gore-like conversation.
|
||||||
--or (msg.reply_to_message and msg.reply_to_message.from.id == self.info.id)
|
--or (msg.reply_to_message and msg.reply_to_message.from.id == self.info.id)
|
||||||
)
|
)
|
||||||
or msg.text:match('^/')
|
or msg.text:match('^'..utilities.CMD_PAT)
|
||||||
or msg.text == ''
|
or msg.text == ''
|
||||||
) then
|
) then
|
||||||
return true
|
return true
|
||||||
|
@ -5,7 +5,7 @@ local utilities = require('utilities')
|
|||||||
|
|
||||||
function control:init()
|
function control:init()
|
||||||
control.triggers = utilities.triggers(self.info.username):t('reload'):t('halt').table
|
control.triggers = utilities.triggers(self.info.username):t('reload'):t('halt').table
|
||||||
table.insert(control.triggers, '^/script')
|
table.insert(control.triggers, '^'..utilities.CMD_PAT..'script')
|
||||||
end
|
end
|
||||||
|
|
||||||
function control:action(msg, config)
|
function control:action(msg, config)
|
||||||
@ -16,7 +16,7 @@ function control:action(msg, config)
|
|||||||
|
|
||||||
if msg.date < os.time() - 1 then return end
|
if msg.date < os.time() - 1 then return end
|
||||||
|
|
||||||
if msg.text:match('^'..utilities.INVOCATION_PATTERN..'reload') then
|
if msg.text:match('^'..utilities.CMD_PAT..'reload') then
|
||||||
for pac, _ in pairs(package.loaded) do
|
for pac, _ in pairs(package.loaded) do
|
||||||
if pac:match('^plugins%.') then
|
if pac:match('^plugins%.') then
|
||||||
package.loaded[pac] = nil
|
package.loaded[pac] = nil
|
||||||
@ -30,13 +30,13 @@ function control:action(msg, config)
|
|||||||
end
|
end
|
||||||
bot.init(self, config)
|
bot.init(self, config)
|
||||||
utilities.send_reply(self, msg, 'Bot reloaded!')
|
utilities.send_reply(self, msg, 'Bot reloaded!')
|
||||||
elseif msg.text:match('^'..utilities.INVOCATION_PATTERN..'halt') then
|
elseif msg.text:match('^'..utilities.CMD_PAT..'halt') then
|
||||||
self.is_started = false
|
self.is_started = false
|
||||||
utilities.send_reply(self, msg, 'Stopping bot!')
|
utilities.send_reply(self, msg, 'Stopping bot!')
|
||||||
elseif msg.text:match('^'..utilities.INVOCATION_PATTERN..'script') then
|
elseif msg.text:match('^'..utilities.CMD_PAT..'script') then
|
||||||
local input = msg.text:match('^'..utilities.INVOCATION_PATTERN..'script\n(.+)')
|
local input = msg.text:match('^'..utilities.CMD_PAT..'script\n(.+)')
|
||||||
if not input then
|
if not input then
|
||||||
utilities.send_reply(self, msg, 'usage: ```\n/script\n/command <arg>\n...\n```', true)
|
utilities.send_reply(self, msg, 'usage: ```\n'..utilities.CMD_PAT..'script\n'..utilities.CMD_PAT..'command <arg>\n...\n```', true)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
input = input .. '\n'
|
input = input .. '\n'
|
||||||
|
@ -5,8 +5,8 @@ local utilities = require('utilities')
|
|||||||
|
|
||||||
currency.command = 'cash [amount] <from> to <to>'
|
currency.command = 'cash [amount] <from> to <to>'
|
||||||
currency.doc = [[```
|
currency.doc = [[```
|
||||||
/cash [amount] <from> to <to>
|
]]..utilities.CMD_PAT..[[cash [amount] <from> to <to>
|
||||||
Example: /cash 5 USD to EUR
|
Example: ]]..utilities.CMD_PAT..[[cash 5 USD to EUR
|
||||||
Returns exchange rates for various currencies.
|
Returns exchange rates for various currencies.
|
||||||
Source: Google Finance.
|
Source: Google Finance.
|
||||||
```]]
|
```]]
|
||||||
|
@ -4,7 +4,7 @@ local utilities = require('utilities')
|
|||||||
|
|
||||||
dice.command = 'roll <nDr>'
|
dice.command = 'roll <nDr>'
|
||||||
dice.doc = [[```
|
dice.doc = [[```
|
||||||
/roll <nDr>
|
]]..utilities.CMD_PAT..[[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.
|
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.
|
||||||
```]]
|
```]]
|
||||||
|
|
||||||
|
@ -7,7 +7,7 @@ local utilities = require('utilities')
|
|||||||
|
|
||||||
dilbert.command = 'dilbert [date]'
|
dilbert.command = 'dilbert [date]'
|
||||||
dilbert.doc = [[```
|
dilbert.doc = [[```
|
||||||
/dilbert [YYYY-MM-DD]
|
]]..utilities.CMD_PAT..[[dilbert [YYYY-MM-DD]
|
||||||
Returns the latest Dilbert strip or that of the provided date.
|
Returns the latest Dilbert strip or that of the provided date.
|
||||||
Dates before the first strip will return the first strip. Dates after the last trip will return the last strip.
|
Dates before the first strip will return the first strip. Dates after the last trip will return the last strip.
|
||||||
Source: dilbert.com
|
Source: dilbert.com
|
||||||
|
@ -4,7 +4,7 @@ local utilities = require('utilities')
|
|||||||
|
|
||||||
echo.command = 'echo <text>'
|
echo.command = 'echo <text>'
|
||||||
echo.doc = [[```
|
echo.doc = [[```
|
||||||
/echo <text>
|
]]..utilities.CMD_PAT..[[echo <text>
|
||||||
Repeats a string of text.
|
Repeats a string of text.
|
||||||
```]]
|
```]]
|
||||||
|
|
||||||
|
@ -24,9 +24,9 @@ end
|
|||||||
|
|
||||||
gImages.command = 'image <query>'
|
gImages.command = 'image <query>'
|
||||||
gImages.doc = [[```
|
gImages.doc = [[```
|
||||||
/image <query>
|
]]..utilities.CMD_PAT..[[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.
|
Returns a randomized top result from Google Images. Safe search is enabled by default; use "]]..utilities.CMD_PAT..[[insfw" to disable it. NSFW results will not display an image preview.
|
||||||
Alias: /i
|
Alias: ]]..utilities.CMD_PAT..[[i
|
||||||
```]]
|
```]]
|
||||||
|
|
||||||
function gImages:action(msg, config)
|
function gImages:action(msg, config)
|
||||||
@ -43,7 +43,7 @@ function gImages:action(msg, config)
|
|||||||
|
|
||||||
local url = 'https://www.googleapis.com/customsearch/v1?&searchType=image&imgSize=xlarge&alt=json&num=8&start=1&key=' .. config.google_api_key .. '&cx=' .. config.google_cse_key
|
local url = 'https://www.googleapis.com/customsearch/v1?&searchType=image&imgSize=xlarge&alt=json&num=8&start=1&key=' .. config.google_api_key .. '&cx=' .. config.google_cse_key
|
||||||
|
|
||||||
if not string.match(msg.text, '^/i[mage]*nsfw') then
|
if not string.match(msg.text, '^'..utilities.CMD_PAT..'i[mage]*nsfw') then
|
||||||
url = url .. '&safe=high'
|
url = url .. '&safe=high'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -5,9 +5,9 @@ local utilities = require('utilities')
|
|||||||
|
|
||||||
gMaps.command = 'location <query>'
|
gMaps.command = 'location <query>'
|
||||||
gMaps.doc = [[```
|
gMaps.doc = [[```
|
||||||
/location <query>
|
]]..utilities.CMD_PAT..[[location <query>
|
||||||
Returns a location from Google Maps.
|
Returns a location from Google Maps.
|
||||||
Alias: /loc
|
Alias: ]]..utilities.CMD_PAT..[[loc
|
||||||
```]]
|
```]]
|
||||||
|
|
||||||
function gMaps:init()
|
function gMaps:init()
|
||||||
@ -26,7 +26,7 @@ function gMaps:action(msg, config)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local coords = utilities.get_coords(self, input, config)
|
local coords = utilities.get_coords(input, config)
|
||||||
if type(coords) == 'string' then
|
if type(coords) == 'string' then
|
||||||
utilities.send_reply(self, msg, coords)
|
utilities.send_reply(self, msg, coords)
|
||||||
return
|
return
|
||||||
|
@ -7,9 +7,9 @@ local utilities = require('utilities')
|
|||||||
|
|
||||||
gSearch.command = 'google <query>'
|
gSearch.command = 'google <query>'
|
||||||
gSearch.doc = [[```
|
gSearch.doc = [[```
|
||||||
/google <query>
|
]]..utilities.CMD_PAT..[[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.
|
Returns four (if group) or eight (if private message) results from Google. Safe search is enabled by default, use "]]..utilities.CMD_PAT..[[gnsfw" to disable it.
|
||||||
Alias: /g
|
Alias: ]]..utilities.CMD_PAT..[[g
|
||||||
```]]
|
```]]
|
||||||
|
|
||||||
function gSearch:init()
|
function gSearch:init()
|
||||||
@ -36,7 +36,7 @@ function gSearch:action(msg, config)
|
|||||||
url = url .. '&rsz=4'
|
url = url .. '&rsz=4'
|
||||||
end
|
end
|
||||||
|
|
||||||
if not string.match(msg.text, '^/g[oogle]*nsfw') then
|
if not string.match(msg.text, '^'..utilities.CMD_PAT..'g[oogle]*nsfw') then
|
||||||
url = url .. '&safe=active'
|
url = url .. '&safe=active'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -8,7 +8,7 @@ local utilities = require('utilities')
|
|||||||
hackernews.command = 'hackernews'
|
hackernews.command = 'hackernews'
|
||||||
hackernews.doc = [[```
|
hackernews.doc = [[```
|
||||||
Returns four (if group) or eight (if private message) top stories from Hacker News.
|
Returns four (if group) or eight (if private message) top stories from Hacker News.
|
||||||
Alias: /hn
|
Alias: ]]..utilities.CMD_PAT..[[hn
|
||||||
```]]
|
```]]
|
||||||
|
|
||||||
function hackernews:init()
|
function hackernews:init()
|
||||||
|
@ -41,9 +41,9 @@ end
|
|||||||
|
|
||||||
hearthstone.command = 'hearthstone <query>'
|
hearthstone.command = 'hearthstone <query>'
|
||||||
hearthstone.doc = [[```
|
hearthstone.doc = [[```
|
||||||
/hearthstone <query>
|
]]..utilities.CMD_PAT..[[hearthstone <query>
|
||||||
Returns Hearthstone card info.
|
Returns Hearthstone card info.
|
||||||
Alias: /hs
|
Alias: ]]..utilities.CMD_PAT..[[hs
|
||||||
```]]
|
```]]
|
||||||
|
|
||||||
local function format_card(card)
|
local function format_card(card)
|
||||||
|
@ -10,19 +10,19 @@ local help_text
|
|||||||
function help:init()
|
function help:init()
|
||||||
|
|
||||||
local commandlist = {}
|
local commandlist = {}
|
||||||
help_text = '*Available commands:*\n• /'
|
help_text = '*Available commands:*\n• '..utilities.CMD_PAT
|
||||||
|
|
||||||
for _,plugin in ipairs(self.plugins) do
|
for _,plugin in ipairs(self.plugins) do
|
||||||
if plugin.command then
|
if plugin.command then
|
||||||
table.insert(commandlist, plugin.command)
|
table.insert(commandlist, plugin.command)
|
||||||
--help_text = help_text .. '\n• /' .. plugin.command:gsub('%[', '\\[')
|
--help_text = help_text .. '\n• '..utilities.CMD_PAT .. plugin.command:gsub('%[', '\\[')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
table.insert(commandlist, 'help [command]')
|
table.insert(commandlist, 'help [command]')
|
||||||
table.sort(commandlist)
|
table.sort(commandlist)
|
||||||
|
|
||||||
help_text = help_text .. table.concat(commandlist, '\n• /') .. '\nArguments: <required> [optional]'
|
help_text = help_text .. table.concat(commandlist, '\n• '..utilities.CMD_PAT) .. '\nArguments: <required> [optional]'
|
||||||
|
|
||||||
help_text = help_text:gsub('%[', '\\[')
|
help_text = help_text:gsub('%[', '\\[')
|
||||||
|
|
||||||
|
@ -7,7 +7,7 @@ local utilities = require('utilities')
|
|||||||
|
|
||||||
imdb.command = 'imdb <query>'
|
imdb.command = 'imdb <query>'
|
||||||
imdb.doc = [[```
|
imdb.doc = [[```
|
||||||
/imdb <query>
|
]]..utilities.CMD_PAT..[[imdb <query>
|
||||||
Returns an IMDb entry.
|
Returns an IMDb entry.
|
||||||
```]]
|
```]]
|
||||||
|
|
||||||
|
@ -20,21 +20,21 @@ end
|
|||||||
|
|
||||||
lastfm.command = 'lastfm'
|
lastfm.command = 'lastfm'
|
||||||
lastfm.doc = [[```
|
lastfm.doc = [[```
|
||||||
/np [username]
|
]]..utilities.CMD_PAT..[[np [username]
|
||||||
Returns what you are or were last listening to. If you specify a username, info will be returned for that username.
|
Returns what you are or were last listening to. If you specify a username, info will be returned for that username.
|
||||||
|
|
||||||
/fmset <username>
|
]]..utilities.CMD_PAT..[[fmset <username>
|
||||||
Sets your last.fm username. Otherwise, /np will use your Telegram username. Use "/fmset --" to delete it.
|
Sets your last.fm username. Otherwise, ]]..utilities.CMD_PAT..[[np will use your Telegram username. Use "]]..utilities.CMD_PAT..[[fmset --" to delete it.
|
||||||
```]]
|
```]]
|
||||||
|
|
||||||
function lastfm:action(msg, config)
|
function lastfm:action(msg, config)
|
||||||
|
|
||||||
local input = utilities.input(msg.text)
|
local input = utilities.input(msg.text)
|
||||||
|
|
||||||
if string.match(msg.text, '^/lastfm') then
|
if string.match(msg.text, '^'..utilities.CMD_PAT..'lastfm') then
|
||||||
utilities.send_message(self, msg.chat.id, lastfm.doc, true, msg.message_id, true)
|
utilities.send_message(self, msg.chat.id, lastfm.doc, true, msg.message_id, true)
|
||||||
return
|
return
|
||||||
elseif string.match(msg.text, '^/fmset') then
|
elseif string.match(msg.text, '^'..utilities.CMD_PAT..'fmset') then
|
||||||
if not input then
|
if not input then
|
||||||
utilities.send_message(self, msg.chat.id, lastfm.doc, true, msg.message_id, true)
|
utilities.send_message(self, msg.chat.id, lastfm.doc, true, msg.message_id, true)
|
||||||
elseif input == '--' or input == utilities.char.em_dash then
|
elseif input == '--' or input == utilities.char.em_dash then
|
||||||
@ -57,10 +57,10 @@ function lastfm:action(msg, config)
|
|||||||
username = self.database.users[msg.from.id_str].lastfm
|
username = self.database.users[msg.from.id_str].lastfm
|
||||||
elseif msg.from.username then
|
elseif msg.from.username then
|
||||||
username = msg.from.username
|
username = msg.from.username
|
||||||
alert = '\n\nYour username has been set to ' .. username .. '.\nTo change it, use /fmset <username>.'
|
alert = '\n\nYour username has been set to ' .. username .. '.\nTo change it, use '..utilities.CMD_PAT..'fmset <username>.'
|
||||||
self.database.users[msg.from.id_str].lastfm = username
|
self.database.users[msg.from.id_str].lastfm = username
|
||||||
else
|
else
|
||||||
utilities.send_reply(self, msg, 'Please specify your last.fm username or set it with /fmset.')
|
utilities.send_reply(self, msg, 'Please specify your last.fm username or set it with '..utilities.CMD_PAT..'fmset.')
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -78,7 +78,7 @@ function lastfm:action(msg, config)
|
|||||||
|
|
||||||
local jdat = JSON.decode(jstr)
|
local jdat = JSON.decode(jstr)
|
||||||
if jdat.error then
|
if jdat.error then
|
||||||
utilities.send_reply(self, msg, 'Please specify your last.fm username or set it with /fmset.')
|
utilities.send_reply(self, msg, 'Please specify your last.fm username or set it with '..utilities.CMD_PAT..'fmset.')
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -20,7 +20,7 @@ function luarun:action(msg, config)
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
if msg.text_lower:match('^/return') then
|
if msg.text_lower:match('^'..utilities.CMD_PAT..'return') then
|
||||||
input = 'return ' .. input
|
input = 'return ' .. input
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -4,8 +4,8 @@ local utilities = require('utilities')
|
|||||||
|
|
||||||
nick.command = 'nick <nickname>'
|
nick.command = 'nick <nickname>'
|
||||||
nick.doc = [[```
|
nick.doc = [[```
|
||||||
/nick <nickname>
|
]]..utilities.CMD_PAT..[[nick <nickname>
|
||||||
Set your nickname. Use "/nick --" to delete it.
|
Set your nickname. Use "]]..utilities.CMD_PAT..[[nick --" to delete it.
|
||||||
```]]
|
```]]
|
||||||
|
|
||||||
function nick:init()
|
function nick:init()
|
||||||
|
@ -9,7 +9,7 @@ function ping:init()
|
|||||||
end
|
end
|
||||||
|
|
||||||
function ping:action(msg)
|
function ping:action(msg)
|
||||||
local output = msg.text_lower:match('^/ping') and 'Pong!' or 'Annyong.'
|
local output = msg.text_lower:match('^'..utilities.CMD_PAT..'ping') and 'Pong!' or 'Annyong.'
|
||||||
utilities.send_message(self, msg.chat.id, output)
|
utilities.send_message(self, msg.chat.id, output)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -7,9 +7,9 @@ local utilities = require('utilities')
|
|||||||
|
|
||||||
pokedex.command = 'pokedex <query>'
|
pokedex.command = 'pokedex <query>'
|
||||||
pokedex.doc = [[```
|
pokedex.doc = [[```
|
||||||
/pokedex <query>
|
]]..utilities.CMD_PAT..[[pokedex <query>
|
||||||
Returns a Pokedex entry from pokeapi.co.
|
Returns a Pokedex entry from pokeapi.co.
|
||||||
Alias: /dex
|
Alias: ]]..utilities.CMD_PAT..[[dex
|
||||||
```]]
|
```]]
|
||||||
|
|
||||||
function pokedex:init()
|
function pokedex:init()
|
||||||
|
@ -5,7 +5,7 @@ local utilities = require('utilities')
|
|||||||
|
|
||||||
preview.command = 'preview <link>'
|
preview.command = 'preview <link>'
|
||||||
preview.doc = [[```
|
preview.doc = [[```
|
||||||
/preview <link>
|
]]..utilities.CMD_PAT..[[preview <link>
|
||||||
Returns a full-message, "unlinked" preview.
|
Returns a full-message, "unlinked" preview.
|
||||||
```]]
|
```]]
|
||||||
|
|
||||||
|
@ -30,19 +30,19 @@ function reactions:init()
|
|||||||
help = 'Reactions:\n'
|
help = 'Reactions:\n'
|
||||||
reactions.triggers = utilities.triggers(self.info.username):t('reactions').table
|
reactions.triggers = utilities.triggers(self.info.username):t('reactions').table
|
||||||
for trigger,reaction in pairs(mapping) do
|
for trigger,reaction in pairs(mapping) do
|
||||||
help = help .. '• ' .. utilities.INVOCATION_PATTERN .. trigger:gsub('.%?', '') .. ': ' .. reaction .. '\n'
|
help = help .. '• ' .. utilities.CMD_PAT .. trigger:gsub('.%?', '') .. ': ' .. reaction .. '\n'
|
||||||
table.insert(reactions.triggers, utilities.INVOCATION_PATTERN..trigger)
|
table.insert(reactions.triggers, utilities.CMD_PAT..trigger)
|
||||||
table.insert(reactions.triggers, utilities.INVOCATION_PATTERN..trigger..'@'..self.info.username:lower())
|
table.insert(reactions.triggers, utilities.CMD_PAT..trigger..'@'..self.info.username:lower())
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function reactions:action(msg)
|
function reactions:action(msg)
|
||||||
if string.match(msg.text_lower, utilities.INVOCATION_PATTERN..'reactions') then
|
if string.match(msg.text_lower, utilities.CMD_PAT..'reactions') then
|
||||||
utilities.send_message(self, msg.chat.id, help)
|
utilities.send_message(self, msg.chat.id, help)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
for trigger,reaction in pairs(mapping) do
|
for trigger,reaction in pairs(mapping) do
|
||||||
if string.match(msg.text_lower, utilities.INVOCATION_PATTERN..trigger) then
|
if string.match(msg.text_lower, utilities.CMD_PAT..trigger) then
|
||||||
utilities.send_message(self, msg.chat.id, reaction)
|
utilities.send_message(self, msg.chat.id, reaction)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
@ -7,9 +7,9 @@ local utilities = require('utilities')
|
|||||||
|
|
||||||
reddit.command = 'reddit [r/subreddit | query]'
|
reddit.command = 'reddit [r/subreddit | query]'
|
||||||
reddit.doc = [[```
|
reddit.doc = [[```
|
||||||
/reddit [r/subreddit | query]
|
]]..utilities.CMD_PAT..[[reddit [r/subreddit | query]
|
||||||
Returns the top posts or results for a given subreddit or query. If no argument is given, returns the top posts from r/all. Querying specific subreddits is not supported.
|
Returns the top posts or results for a given subreddit or query. If no argument is given, returns the top posts from r/all. Querying specific subreddits is not supported.
|
||||||
Aliases: /r, /r/subreddit
|
Aliases: ]]..utilities.CMD_PAT..[[r, /r/subreddit
|
||||||
```]]
|
```]]
|
||||||
|
|
||||||
function reddit:init()
|
function reddit:init()
|
||||||
@ -48,7 +48,7 @@ function reddit:action(msg, config)
|
|||||||
local text = msg.text_lower
|
local text = msg.text_lower
|
||||||
if text:match('^/r/.') then
|
if text:match('^/r/.') then
|
||||||
-- Normalize input so this hack works easily.
|
-- Normalize input so this hack works easily.
|
||||||
text = msg.text_lower:gsub('^/r/', '/r r/')
|
text = msg.text_lower:gsub('^/r/', utilities.CMD_PAT..'r r/')
|
||||||
end
|
end
|
||||||
local input = utilities.input(text)
|
local input = utilities.input(text)
|
||||||
local source, url
|
local source, url
|
||||||
|
@ -4,7 +4,7 @@ local utilities = require('utilities')
|
|||||||
|
|
||||||
remind.command = 'remind <duration> <message>'
|
remind.command = 'remind <duration> <message>'
|
||||||
remind.doc = [[```
|
remind.doc = [[```
|
||||||
/remind <duration> <message>
|
]]..utilities.CMD_PAT..[[remind <duration> <message>
|
||||||
Repeats a message after a duration of time, in minutes.
|
Repeats a message after a duration of time, in minutes.
|
||||||
```]]
|
```]]
|
||||||
|
|
||||||
|
@ -9,9 +9,9 @@ end
|
|||||||
|
|
||||||
setandget.command = 'set <name> <value>'
|
setandget.command = 'set <name> <value>'
|
||||||
setandget.doc = [[```
|
setandget.doc = [[```
|
||||||
/set <name> <value>
|
]]..utilities.CMD_PAT..[[set <name> <value>
|
||||||
Stores a value with the given name. Use "/set <name> --" to delete the stored value.
|
Stores a value with the given name. Use "]]..utilities.CMD_PAT..[[set <name> --" to delete the stored value.
|
||||||
/get [name]
|
]]..utilities.CMD_PAT..[[get [name]
|
||||||
Returns the stored value or a list of stored values.
|
Returns the stored value or a list of stored values.
|
||||||
```]]
|
```]]
|
||||||
|
|
||||||
@ -21,7 +21,7 @@ function setandget:action(msg)
|
|||||||
local input = utilities.input(msg.text)
|
local input = utilities.input(msg.text)
|
||||||
self.database.setandget[msg.chat.id_str] = self.database.setandget[msg.chat.id_str] or {}
|
self.database.setandget[msg.chat.id_str] = self.database.setandget[msg.chat.id_str] or {}
|
||||||
|
|
||||||
if msg.text_lower:match('^/set') then
|
if msg.text_lower:match('^'..utilities.CMD_PAT..'set') then
|
||||||
|
|
||||||
if not input then
|
if not input then
|
||||||
utilities.send_message(self, msg.chat.id, setandget.doc, true, nil, true)
|
utilities.send_message(self, msg.chat.id, setandget.doc, true, nil, true)
|
||||||
@ -41,7 +41,7 @@ function setandget:action(msg)
|
|||||||
utilities.send_message(self, msg.chat.id, '"' .. name .. '" has been set to "' .. value .. '".', true)
|
utilities.send_message(self, msg.chat.id, '"' .. name .. '" has been set to "' .. value .. '".', true)
|
||||||
end
|
end
|
||||||
|
|
||||||
elseif msg.text_lower:match('^/get') then
|
elseif msg.text_lower:match('^'..utilities.CMD_PAT..'get') then
|
||||||
|
|
||||||
if not input then
|
if not input then
|
||||||
local output
|
local output
|
||||||
|
@ -4,7 +4,7 @@ local utilities = require('utilities')
|
|||||||
|
|
||||||
shout.command = 'shout <text>'
|
shout.command = 'shout <text>'
|
||||||
shout.doc = [[```
|
shout.doc = [[```
|
||||||
/shout <text>
|
]]..utilities.CMD_PAT..[[shout <text>
|
||||||
Shouts something. Input may be the replied-to message.
|
Shouts something. Input may be the replied-to message.
|
||||||
```]]
|
```]]
|
||||||
|
|
||||||
|
@ -4,7 +4,7 @@ local utilities = require('utilities')
|
|||||||
|
|
||||||
slap.command = 'slap [target]'
|
slap.command = 'slap [target]'
|
||||||
slap.doc = [[```
|
slap.doc = [[```
|
||||||
/slap [target]
|
]]..utilities.CMD_PAT..[[slap [target]
|
||||||
Slap somebody.
|
Slap somebody.
|
||||||
```]]
|
```]]
|
||||||
|
|
||||||
|
@ -6,7 +6,7 @@ local utilities = require('utilities')
|
|||||||
|
|
||||||
time.command = 'time <location>'
|
time.command = 'time <location>'
|
||||||
time.doc = [[```
|
time.doc = [[```
|
||||||
/time <location>
|
]]..utilities.CMD_PAT..[[time <location>
|
||||||
Returns the time, date, and timezone for the given location.
|
Returns the time, date, and timezone for the given location.
|
||||||
```]]
|
```]]
|
||||||
|
|
||||||
@ -26,7 +26,7 @@ function time:action(msg, config)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local coords = utilities.get_coords(self, input, config)
|
local coords = utilities.get_coords(input, config)
|
||||||
if type(coords) == 'string' then
|
if type(coords) == 'string' then
|
||||||
utilities.send_reply(self, msg, coords)
|
utilities.send_reply(self, msg, coords)
|
||||||
return
|
return
|
||||||
|
@ -7,7 +7,7 @@ local utilities = require('utilities')
|
|||||||
|
|
||||||
translate.command = 'translate [text]'
|
translate.command = 'translate [text]'
|
||||||
translate.doc = [[```
|
translate.doc = [[```
|
||||||
/translate [text]
|
]]..utilities.CMD_PAT..[[translate [text]
|
||||||
Translates input or the replied-to message into the bot's language.
|
Translates input or the replied-to message into the bot's language.
|
||||||
```]]
|
```]]
|
||||||
|
|
||||||
|
@ -7,9 +7,9 @@ local utilities = require('utilities')
|
|||||||
|
|
||||||
urbandictionary.command = 'urbandictionary <query>'
|
urbandictionary.command = 'urbandictionary <query>'
|
||||||
urbandictionary.doc = [[```
|
urbandictionary.doc = [[```
|
||||||
/urbandictionary <query>
|
]]..utilities.CMD_PAT..[[urbandictionary <query>
|
||||||
Returns a definition from Urban Dictionary.
|
Returns a definition from Urban Dictionary.
|
||||||
Aliases: /ud, /urban
|
Aliases: ]]..utilities.CMD_PAT..[[ud, ]]..utilities.CMD_PAT..[[urban
|
||||||
```]]
|
```]]
|
||||||
|
|
||||||
function urbandictionary:init()
|
function urbandictionary:init()
|
||||||
|
@ -16,7 +16,7 @@ end
|
|||||||
|
|
||||||
weather.command = 'weather <location>'
|
weather.command = 'weather <location>'
|
||||||
weather.doc = [[```
|
weather.doc = [[```
|
||||||
/weather <location>
|
]]..utilities.CMD_PAT..[[weather <location>
|
||||||
Returns the current weather conditions for a given location.
|
Returns the current weather conditions for a given location.
|
||||||
```]]
|
```]]
|
||||||
|
|
||||||
@ -32,7 +32,7 @@ function weather:action(msg, config)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local coords = utilities.get_coords(self, input, config)
|
local coords = utilities.get_coords(input, config)
|
||||||
if type(coords) == 'string' then
|
if type(coords) == 'string' then
|
||||||
utilities.send_reply(self, msg, coords)
|
utilities.send_reply(self, msg, coords)
|
||||||
return
|
return
|
||||||
|
@ -5,7 +5,7 @@ local utilities = require('utilities')
|
|||||||
whoami.command = 'whoami'
|
whoami.command = 'whoami'
|
||||||
whoami.doc = [[```
|
whoami.doc = [[```
|
||||||
Returns user and chat info for you or the replied-to message.
|
Returns user and chat info for you or the replied-to message.
|
||||||
Alias: /who
|
Alias: ]]..utilities.CMD_PAT..[[who
|
||||||
```]]
|
```]]
|
||||||
|
|
||||||
function whoami:init()
|
function whoami:init()
|
||||||
|
@ -7,9 +7,9 @@ local utilities = require('utilities')
|
|||||||
|
|
||||||
wikipedia.command = 'wikipedia <query>'
|
wikipedia.command = 'wikipedia <query>'
|
||||||
wikipedia.doc = [[```
|
wikipedia.doc = [[```
|
||||||
/wikipedia <query>
|
]]..utilities.CMD_PAT..[[wikipedia <query>
|
||||||
Returns an article from Wikipedia.
|
Returns an article from Wikipedia.
|
||||||
Aliases: /w, /wiki
|
Aliases: ]]..utilities.CMD_PAT..[[w, ]]..utilities.CMD_PAT..[[wiki
|
||||||
```]]
|
```]]
|
||||||
|
|
||||||
function wikipedia:init()
|
function wikipedia:init()
|
||||||
|
@ -6,7 +6,7 @@ local utilities = require('utilities')
|
|||||||
|
|
||||||
xkcd.command = 'xkcd [i]'
|
xkcd.command = 'xkcd [i]'
|
||||||
xkcd.doc = [[```
|
xkcd.doc = [[```
|
||||||
/xkcd [i]
|
]]..utilities.CMD_PAT..[[xkcd [i]
|
||||||
Returns the latest xkcd strip and its alt text. If a number is given, returns that number strip. If "r" is passed in place of a number, returns a random strip.
|
Returns the latest xkcd strip and its alt text. If a number is given, returns that number strip. If "r" is passed in place of a number, returns a random strip.
|
||||||
```]]
|
```]]
|
||||||
|
|
||||||
|
@ -19,9 +19,9 @@ end
|
|||||||
|
|
||||||
youtube.command = 'youtube <query>'
|
youtube.command = 'youtube <query>'
|
||||||
youtube.doc = [[```
|
youtube.doc = [[```
|
||||||
/youtube <query>
|
]]..utilities.CMD_PAT..[[youtube <query>
|
||||||
Returns the top result from YouTube.
|
Returns the top result from YouTube.
|
||||||
Alias: /yt
|
Alias: ]]..utilities.CMD_PAT..[[yt
|
||||||
```]]
|
```]]
|
||||||
|
|
||||||
function youtube:action(msg, config)
|
function youtube:action(msg, config)
|
||||||
|
@ -137,7 +137,7 @@ function utilities.save_data(filename, data)
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- Gets coordinates for a location. Used by gMaps.lua, time.lua, weather.lua.
|
-- Gets coordinates for a location. Used by gMaps.lua, time.lua, weather.lua.
|
||||||
function utilities:get_coords(input, config)
|
function utilities.get_coords(input, config)
|
||||||
|
|
||||||
local url = 'http://maps.googleapis.com/maps/api/geocode/json?address=' .. URL.escape(input)
|
local url = 'http://maps.googleapis.com/maps/api/geocode/json?address=' .. URL.escape(input)
|
||||||
|
|
||||||
@ -281,17 +281,17 @@ end
|
|||||||
|
|
||||||
utilities.md_escape = utilities.markdown_escape
|
utilities.md_escape = utilities.markdown_escape
|
||||||
|
|
||||||
utilities.INVOCATION_PATTERN = '/'
|
utilities.CMD_PAT = '/'
|
||||||
|
|
||||||
utilities.triggers_meta = {}
|
utilities.triggers_meta = {}
|
||||||
utilities.triggers_meta.__index = utilities.triggers_meta
|
utilities.triggers_meta.__index = utilities.triggers_meta
|
||||||
function utilities.triggers_meta:t(pattern, has_args)
|
function utilities.triggers_meta:t(pattern, has_args)
|
||||||
local username = self.username:lower()
|
local username = self.username:lower()
|
||||||
table.insert(self.table, '^'..utilities.INVOCATION_PATTERN..pattern..'$')
|
table.insert(self.table, '^'..utilities.CMD_PAT..pattern..'$')
|
||||||
table.insert(self.table, '^'..utilities.INVOCATION_PATTERN..pattern..'@'..username..'$')
|
table.insert(self.table, '^'..utilities.CMD_PAT..pattern..'@'..username..'$')
|
||||||
if has_args then
|
if has_args then
|
||||||
table.insert(self.table, '^'..utilities.INVOCATION_PATTERN..pattern..'%s+[^%s]*')
|
table.insert(self.table, '^'..utilities.CMD_PAT..pattern..'%s+[^%s]*')
|
||||||
table.insert(self.table, '^'..utilities.INVOCATION_PATTERN..pattern..'@'..username..'%s+[^%s]*')
|
table.insert(self.table, '^'..utilities.CMD_PAT..pattern..'@'..username..'%s+[^%s]*')
|
||||||
end
|
end
|
||||||
return self
|
return self
|
||||||
end
|
end
|
||||||
|
Reference in New Issue
Block a user