Fully use utilities.CMD_PAT (née INVOCATION_PATTERN).

This commit is contained in:
Brayden Banks 2016-05-26 17:59:45 -07:00
parent 6a13d523fb
commit ed6b536a46
42 changed files with 109 additions and 109 deletions

View File

@ -61,8 +61,8 @@ function bot:on_msg_receive(msg, config) -- The fn run whenever a message is rec
msg = utilities.enrich_message(msg)
if msg.text:match('^/start .+') then
msg.text = '/' .. utilities.input(msg.text)
if msg.text:match('^'..utilities.CMD_PAT..'start .+') then
msg.text = utilities.CMD_PAT .. utilities.input(msg.text)
msg.text_lower = msg.text:lower()
end

View File

@ -19,9 +19,9 @@ function about:action(msg, config)
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)
or msg.text_lower:match('^/about')
or msg.text_lower:match('^/about@'..self.info.username:lower())
or msg.text_lower:match('^/start') then
or msg.text_lower:match('^'..utilities.CMD_PAT..'about')
or msg.text_lower:match('^'..utilities.CMD_PAT..'about@'..self.info.username:lower())
or msg.text_lower:match('^'..utilities.CMD_PAT..'start') then
utilities.send_message(self, msg.chat.id, output, true)
return
end

View File

@ -75,8 +75,8 @@ administration.flags = {
name = 'unlisted',
desc = 'Removes this group from the group listing.',
short = 'This group is unlisted.',
enabled = 'This group is no longer listed in /groups.',
disabled = 'This group is now listed in /groups.'
enabled = 'This group is no longer listed in '..utilities.CMD_PAT..'groups.',
disabled = 'This group is now listed in '..utilities.CMD_PAT..'groups.'
},
[2] = {
name = 'antisquig',
@ -105,7 +105,7 @@ administration.flags = {
name = 'antiflood',
desc = 'Prevents flooding by rate-limiting messages per user.',
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.',
kicked = 'You were automatically kicked from GROUPNAME for flooding.'
},
@ -237,7 +237,7 @@ function administration:get_desc(chat_id)
if modstring ~= '' then
table.insert(t, '*Moderators:*\n' .. utilities.trim(modstring))
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')
end
@ -250,7 +250,7 @@ function administration:update_desc(chat)
local gov = self.database.users[tostring(group.governor)]
desc = desc .. '\nGovernor: ' .. utilities.build_name(gov.first_name, gov.last_name) .. ' [' .. gov.id .. ']\n'
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
drua.channel_set_about(chat, desc)
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 input = utilities.get_word(msg.text_lower, 2)
if input then
input = input:gsub('^/', '')
input = input:gsub('^'..utilities.CMD_PAT..'', '')
local doc
for _,action in ipairs(administration.commands) do
if action.keyword == input then
doc = '/' .. action.command:gsub('\\','') .. '\n' .. action.doc
doc = ''..utilities.CMD_PAT..'' .. action.command:gsub('\\','') .. '\n' .. action.doc
break
end
end
@ -533,14 +533,14 @@ function administration.init_command(self_, config)
local output = '*Help for* _' .. input .. '_ :\n```\n' .. doc .. '\n```'
utilities.send_message(self, msg.chat.id, output, true, nil, true)
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)
end
else
local output = '*Commands for ' .. administration.ranks[rank] .. ':*\n'
for i = 1, rank do
for _, val in ipairs(self.admin_temp.help[i]) do
output = output .. '/' .. val .. '\n'
output = output .. '' .. utilities.CMD_PAT .. val .. '\n'
end
end
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.',
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
group.rules = {}
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)
local input = utilities.input(msg.text)
local output = 'usage: `/changerule <i> <newrule>`'
local output = 'usage: `'..utilities.CMD_PAT..'changerule <i> <newrule>`'
if input then
local rule_num = tonumber(input:match('^%d+'))
local new_rule = utilities.input(input)
@ -944,7 +944,7 @@ function administration.init_command(self_, config)
action = function(self, msg, group, config)
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
if not group.antiflood then
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.'
end
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
output = output .. '*'..k..':* `'..v..'`\n'
end
@ -1389,6 +1389,6 @@ function administration:cron()
end
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

View File

@ -9,12 +9,12 @@ local utilities = require('utilities')
apod.command = 'apod [date]'
apod.doc = [[```
/apod [query]
]]..utilities.CMD_PAT..[[apod [query]
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.
/apodhd [query]
]]..utilities.CMD_PAT..[[apodhd [query]
Returns the image in HD, if available.
/apodtext [query]
]]..utilities.CMD_PAT..[[apodtext [query]
Returns the explanation of the APOD.
Source: nasa.gov
```]]
@ -65,13 +65,13 @@ function apod:action(msg, config)
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
end
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
disable_page_preview = true
end

View File

@ -5,7 +5,7 @@ local utilities = require('utilities')
bandersnatch.command = 'bandersnatch'
bandersnatch.doc = [[```
Shun the frumious Bandersnatch.
Alias: /bc
Alias: ]]..utilities.CMD_PAT..[[bc
```]]
function bandersnatch:init()

View File

@ -16,9 +16,9 @@ end
bible.command = 'bible <reference>'
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.
Alias: /b
Alias: ]]..utilities.CMD_PAT..[[b
```]]
function bible:action(msg, config)

View File

@ -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.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
local target = utilities.user_from_message(self, msg)

View File

@ -6,7 +6,7 @@ local utilities = require('utilities')
calc.command = 'calc <expression>'
calc.doc = [[```
/calc <expression>
]]..utilities.CMD_PAT..[[calc <expression>
Returns solutions to mathematical expressions and conversions between common units. Results provided by mathjs.org.
```]]

View File

@ -34,7 +34,7 @@ function chatter:action(msg, config)
--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.text:match('^/')
or msg.text:match('^'..utilities.CMD_PAT)
or msg.text == ''
) then
return true

View File

@ -5,7 +5,7 @@ local utilities = require('utilities')
function control:init()
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
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.text:match('^'..utilities.INVOCATION_PATTERN..'reload') then
if msg.text:match('^'..utilities.CMD_PAT..'reload') then
for pac, _ in pairs(package.loaded) do
if pac:match('^plugins%.') then
package.loaded[pac] = nil
@ -30,13 +30,13 @@ function control:action(msg, config)
end
bot.init(self, config)
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
utilities.send_reply(self, msg, 'Stopping bot!')
elseif msg.text:match('^'..utilities.INVOCATION_PATTERN..'script') then
local input = msg.text:match('^'..utilities.INVOCATION_PATTERN..'script\n(.+)')
elseif msg.text:match('^'..utilities.CMD_PAT..'script') then
local input = msg.text:match('^'..utilities.CMD_PAT..'script\n(.+)')
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
end
input = input .. '\n'

View File

@ -5,8 +5,8 @@ local utilities = require('utilities')
currency.command = 'cash [amount] <from> to <to>'
currency.doc = [[```
/cash [amount] <from> to <to>
Example: /cash 5 USD to EUR
]]..utilities.CMD_PAT..[[cash [amount] <from> to <to>
Example: ]]..utilities.CMD_PAT..[[cash 5 USD to EUR
Returns exchange rates for various currencies.
Source: Google Finance.
```]]

View File

@ -4,7 +4,7 @@ local utilities = require('utilities')
dice.command = 'roll <nDr>'
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.
```]]

View File

@ -7,7 +7,7 @@ local utilities = require('utilities')
dilbert.command = 'dilbert [date]'
dilbert.doc = [[```
/dilbert [YYYY-MM-DD]
]]..utilities.CMD_PAT..[[dilbert [YYYY-MM-DD]
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.
Source: dilbert.com

View File

@ -4,7 +4,7 @@ local utilities = require('utilities')
echo.command = 'echo <text>'
echo.doc = [[```
/echo <text>
]]..utilities.CMD_PAT..[[echo <text>
Repeats a string of text.
```]]

View File

@ -24,9 +24,9 @@ end
gImages.command = 'image <query>'
gImages.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
]]..utilities.CMD_PAT..[[image <query>
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: ]]..utilities.CMD_PAT..[[i
```]]
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
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'
end

View File

@ -5,9 +5,9 @@ local utilities = require('utilities')
gMaps.command = 'location <query>'
gMaps.doc = [[```
/location <query>
]]..utilities.CMD_PAT..[[location <query>
Returns a location from Google Maps.
Alias: /loc
Alias: ]]..utilities.CMD_PAT..[[loc
```]]
function gMaps:init()
@ -26,7 +26,7 @@ function gMaps:action(msg, config)
end
end
local coords = utilities.get_coords(self, input, config)
local coords = utilities.get_coords(input, config)
if type(coords) == 'string' then
utilities.send_reply(self, msg, coords)
return

View File

@ -7,9 +7,9 @@ local utilities = require('utilities')
gSearch.command = 'google <query>'
gSearch.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
]]..utilities.CMD_PAT..[[google <query>
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: ]]..utilities.CMD_PAT..[[g
```]]
function gSearch:init()
@ -36,7 +36,7 @@ function gSearch:action(msg, config)
url = url .. '&rsz=4'
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'
end

View File

@ -8,7 +8,7 @@ local utilities = require('utilities')
hackernews.command = 'hackernews'
hackernews.doc = [[```
Returns four (if group) or eight (if private message) top stories from Hacker News.
Alias: /hn
Alias: ]]..utilities.CMD_PAT..[[hn
```]]
function hackernews:init()

View File

@ -41,9 +41,9 @@ end
hearthstone.command = 'hearthstone <query>'
hearthstone.doc = [[```
/hearthstone <query>
]]..utilities.CMD_PAT..[[hearthstone <query>
Returns Hearthstone card info.
Alias: /hs
Alias: ]]..utilities.CMD_PAT..[[hs
```]]
local function format_card(card)

View File

@ -10,19 +10,19 @@ local help_text
function help:init()
local commandlist = {}
help_text = '*Available commands:*\n/'
help_text = '*Available commands:*\n'..utilities.CMD_PAT
for _,plugin in ipairs(self.plugins) do
if plugin.command then
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
table.insert(commandlist, 'help [command]')
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('%[', '\\[')

View File

@ -7,7 +7,7 @@ local utilities = require('utilities')
imdb.command = 'imdb <query>'
imdb.doc = [[```
/imdb <query>
]]..utilities.CMD_PAT..[[imdb <query>
Returns an IMDb entry.
```]]

View File

@ -20,21 +20,21 @@ end
lastfm.command = 'lastfm'
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.
/fmset <username>
Sets your last.fm username. Otherwise, /np will use your Telegram username. Use "/fmset --" to delete it.
]]..utilities.CMD_PAT..[[fmset <username>
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)
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)
return
elseif string.match(msg.text, '^/fmset') then
elseif string.match(msg.text, '^'..utilities.CMD_PAT..'fmset') then
if not input then
utilities.send_message(self, msg.chat.id, lastfm.doc, true, msg.message_id, true)
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
elseif msg.from.username then
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
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
end
@ -78,7 +78,7 @@ function lastfm:action(msg, config)
local jdat = JSON.decode(jstr)
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
end

View File

@ -20,7 +20,7 @@ function luarun:action(msg, config)
return
end
if msg.text_lower:match('^/return') then
if msg.text_lower:match('^'..utilities.CMD_PAT..'return') then
input = 'return ' .. input
end

View File

@ -4,8 +4,8 @@ local utilities = require('utilities')
nick.command = 'nick <nickname>'
nick.doc = [[```
/nick <nickname>
Set your nickname. Use "/nick --" to delete it.
]]..utilities.CMD_PAT..[[nick <nickname>
Set your nickname. Use "]]..utilities.CMD_PAT..[[nick --" to delete it.
```]]
function nick:init()

View File

@ -9,7 +9,7 @@ function ping:init()
end
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)
end

View File

@ -7,9 +7,9 @@ local utilities = require('utilities')
pokedex.command = 'pokedex <query>'
pokedex.doc = [[```
/pokedex <query>
]]..utilities.CMD_PAT..[[pokedex <query>
Returns a Pokedex entry from pokeapi.co.
Alias: /dex
Alias: ]]..utilities.CMD_PAT..[[dex
```]]
function pokedex:init()

View File

@ -5,7 +5,7 @@ local utilities = require('utilities')
preview.command = 'preview <link>'
preview.doc = [[```
/preview <link>
]]..utilities.CMD_PAT..[[preview <link>
Returns a full-message, "unlinked" preview.
```]]

View File

@ -30,19 +30,19 @@ function reactions:init()
help = 'Reactions:\n'
reactions.triggers = utilities.triggers(self.info.username):t('reactions').table
for trigger,reaction in pairs(mapping) do
help = help .. '' .. utilities.INVOCATION_PATTERN .. trigger:gsub('.%?', '') .. ': ' .. reaction .. '\n'
table.insert(reactions.triggers, utilities.INVOCATION_PATTERN..trigger)
table.insert(reactions.triggers, utilities.INVOCATION_PATTERN..trigger..'@'..self.info.username:lower())
help = help .. '' .. utilities.CMD_PAT .. trigger:gsub('.%?', '') .. ': ' .. reaction .. '\n'
table.insert(reactions.triggers, utilities.CMD_PAT..trigger)
table.insert(reactions.triggers, utilities.CMD_PAT..trigger..'@'..self.info.username:lower())
end
end
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)
return
end
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)
return
end

View File

@ -7,9 +7,9 @@ local utilities = require('utilities')
reddit.command = 'reddit [r/subreddit | query]'
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.
Aliases: /r, /r/subreddit
Aliases: ]]..utilities.CMD_PAT..[[r, /r/subreddit
```]]
function reddit:init()
@ -48,7 +48,7 @@ function reddit:action(msg, config)
local text = msg.text_lower
if text:match('^/r/.') then
-- 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
local input = utilities.input(text)
local source, url

View File

@ -4,7 +4,7 @@ local utilities = require('utilities')
remind.command = 'remind <duration> <message>'
remind.doc = [[```
/remind <duration> <message>
]]..utilities.CMD_PAT..[[remind <duration> <message>
Repeats a message after a duration of time, in minutes.
```]]

View File

@ -9,9 +9,9 @@ end
setandget.command = 'set <name> <value>'
setandget.doc = [[```
/set <name> <value>
Stores a value with the given name. Use "/set <name> --" to delete the stored value.
/get [name]
]]..utilities.CMD_PAT..[[set <name> <value>
Stores a value with the given name. Use "]]..utilities.CMD_PAT..[[set <name> --" to delete the stored value.
]]..utilities.CMD_PAT..[[get [name]
Returns the stored value or a list of stored values.
```]]
@ -21,7 +21,7 @@ function setandget:action(msg)
local input = utilities.input(msg.text)
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
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)
end
elseif msg.text_lower:match('^/get') then
elseif msg.text_lower:match('^'..utilities.CMD_PAT..'get') then
if not input then
local output

View File

@ -4,7 +4,7 @@ local utilities = require('utilities')
shout.command = 'shout <text>'
shout.doc = [[```
/shout <text>
]]..utilities.CMD_PAT..[[shout <text>
Shouts something. Input may be the replied-to message.
```]]

View File

@ -4,7 +4,7 @@ local utilities = require('utilities')
slap.command = 'slap [target]'
slap.doc = [[```
/slap [target]
]]..utilities.CMD_PAT..[[slap [target]
Slap somebody.
```]]

View File

@ -6,7 +6,7 @@ local utilities = require('utilities')
time.command = 'time <location>'
time.doc = [[```
/time <location>
]]..utilities.CMD_PAT..[[time <location>
Returns the time, date, and timezone for the given location.
```]]
@ -26,7 +26,7 @@ function time:action(msg, config)
end
end
local coords = utilities.get_coords(self, input, config)
local coords = utilities.get_coords(input, config)
if type(coords) == 'string' then
utilities.send_reply(self, msg, coords)
return

View File

@ -7,7 +7,7 @@ local utilities = require('utilities')
translate.command = 'translate [text]'
translate.doc = [[```
/translate [text]
]]..utilities.CMD_PAT..[[translate [text]
Translates input or the replied-to message into the bot's language.
```]]

View File

@ -7,9 +7,9 @@ local utilities = require('utilities')
urbandictionary.command = 'urbandictionary <query>'
urbandictionary.doc = [[```
/urbandictionary <query>
]]..utilities.CMD_PAT..[[urbandictionary <query>
Returns a definition from Urban Dictionary.
Aliases: /ud, /urban
Aliases: ]]..utilities.CMD_PAT..[[ud, ]]..utilities.CMD_PAT..[[urban
```]]
function urbandictionary:init()

View File

@ -16,7 +16,7 @@ end
weather.command = 'weather <location>'
weather.doc = [[```
/weather <location>
]]..utilities.CMD_PAT..[[weather <location>
Returns the current weather conditions for a given location.
```]]
@ -32,7 +32,7 @@ function weather:action(msg, config)
end
end
local coords = utilities.get_coords(self, input, config)
local coords = utilities.get_coords(input, config)
if type(coords) == 'string' then
utilities.send_reply(self, msg, coords)
return

View File

@ -5,7 +5,7 @@ local utilities = require('utilities')
whoami.command = 'whoami'
whoami.doc = [[```
Returns user and chat info for you or the replied-to message.
Alias: /who
Alias: ]]..utilities.CMD_PAT..[[who
```]]
function whoami:init()

View File

@ -7,9 +7,9 @@ local utilities = require('utilities')
wikipedia.command = 'wikipedia <query>'
wikipedia.doc = [[```
/wikipedia <query>
]]..utilities.CMD_PAT..[[wikipedia <query>
Returns an article from Wikipedia.
Aliases: /w, /wiki
Aliases: ]]..utilities.CMD_PAT..[[w, ]]..utilities.CMD_PAT..[[wiki
```]]
function wikipedia:init()

View File

@ -6,7 +6,7 @@ local utilities = require('utilities')
xkcd.command = 'xkcd [i]'
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.
```]]

View File

@ -19,9 +19,9 @@ end
youtube.command = 'youtube <query>'
youtube.doc = [[```
/youtube <query>
]]..utilities.CMD_PAT..[[youtube <query>
Returns the top result from YouTube.
Alias: /yt
Alias: ]]..utilities.CMD_PAT..[[yt
```]]
function youtube:action(msg, config)

View File

@ -137,7 +137,7 @@ function utilities.save_data(filename, data)
end
-- 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)
@ -281,17 +281,17 @@ end
utilities.md_escape = utilities.markdown_escape
utilities.INVOCATION_PATTERN = '/'
utilities.CMD_PAT = '/'
utilities.triggers_meta = {}
utilities.triggers_meta.__index = utilities.triggers_meta
function utilities.triggers_meta:t(pattern, has_args)
local username = self.username:lower()
table.insert(self.table, '^'..utilities.INVOCATION_PATTERN..pattern..'$')
table.insert(self.table, '^'..utilities.INVOCATION_PATTERN..pattern..'@'..username..'$')
table.insert(self.table, '^'..utilities.CMD_PAT..pattern..'$')
table.insert(self.table, '^'..utilities.CMD_PAT..pattern..'@'..username..'$')
if has_args then
table.insert(self.table, '^'..utilities.INVOCATION_PATTERN..pattern..'%s+[^%s]*')
table.insert(self.table, '^'..utilities.INVOCATION_PATTERN..pattern..'@'..username..'%s+[^%s]*')
table.insert(self.table, '^'..utilities.CMD_PAT..pattern..'%s+[^%s]*')
table.insert(self.table, '^'..utilities.CMD_PAT..pattern..'@'..username..'%s+[^%s]*')
end
return self
end