From ed6b536a46f7fc3996fe5de71ab19a7f8c56d128 Mon Sep 17 00:00:00 2001 From: Brayden Banks Date: Thu, 26 May 2016 17:59:45 -0700 Subject: [PATCH] =?UTF-8?q?Fully=20use=20utilities.CMD=5FPAT=20(n=C3=A9e?= =?UTF-8?q?=20INVOCATION=5FPATTERN).?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bot.lua | 4 ++-- plugins/about.lua | 6 +++--- plugins/administration.lua | 28 ++++++++++++++-------------- plugins/apod.lua | 10 +++++----- plugins/bandersnatch.lua | 2 +- plugins/bible.lua | 4 ++-- plugins/blacklist.lua | 2 +- plugins/calc.lua | 2 +- plugins/chatter.lua | 2 +- plugins/control.lua | 12 ++++++------ plugins/currency.lua | 4 ++-- plugins/dice.lua | 2 +- plugins/dilbert.lua | 2 +- plugins/echo.lua | 2 +- plugins/gImages.lua | 8 ++++---- plugins/gMaps.lua | 6 +++--- plugins/gSearch.lua | 8 ++++---- plugins/hackernews.lua | 2 +- plugins/hearthstone.lua | 4 ++-- plugins/help.lua | 6 +++--- plugins/imdb.lua | 2 +- plugins/lastfm.lua | 16 ++++++++-------- plugins/luarun.lua | 2 +- plugins/nick.lua | 4 ++-- plugins/ping.lua | 2 +- plugins/pokedex.lua | 4 ++-- plugins/preview.lua | 2 +- plugins/reactions.lua | 10 +++++----- plugins/reddit.lua | 6 +++--- plugins/remind.lua | 2 +- plugins/setandget.lua | 10 +++++----- plugins/shout.lua | 2 +- plugins/slap.lua | 2 +- plugins/time.lua | 4 ++-- plugins/translate.lua | 2 +- plugins/urbandictionary.lua | 4 ++-- plugins/weather.lua | 4 ++-- plugins/whoami.lua | 2 +- plugins/wikipedia.lua | 4 ++-- plugins/xkcd.lua | 2 +- plugins/youtube.lua | 4 ++-- utilities.lua | 12 ++++++------ 42 files changed, 109 insertions(+), 109 deletions(-) diff --git a/bot.lua b/bot.lua index d2f2588..9f2d712 100755 --- a/bot.lua +++ b/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) - 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 diff --git a/plugins/about.lua b/plugins/about.lua index 6605dd1..331db36 100755 --- a/plugins/about.lua +++ b/plugins/about.lua @@ -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 diff --git a/plugins/administration.lua b/plugins/administration.lua index 339a38b..695f1b3 100644 --- a/plugins/administration.lua +++ b/plugins/administration.lua @@ -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: \\[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 `' + local output = 'usage: `'..utilities.CMD_PAT..'changerule `' 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 `\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 `\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 diff --git a/plugins/apod.lua b/plugins/apod.lua index 461e2f0..5bd664f 100755 --- a/plugins/apod.lua +++ b/plugins/apod.lua @@ -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 diff --git a/plugins/bandersnatch.lua b/plugins/bandersnatch.lua index a703d37..75af8f1 100755 --- a/plugins/bandersnatch.lua +++ b/plugins/bandersnatch.lua @@ -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() diff --git a/plugins/bible.lua b/plugins/bible.lua index b1251e1..523be77 100755 --- a/plugins/bible.lua +++ b/plugins/bible.lua @@ -16,9 +16,9 @@ end bible.command = 'bible ' bible.doc = [[``` -/bible +]]..utilities.CMD_PAT..[[bible 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) diff --git a/plugins/blacklist.lua b/plugins/blacklist.lua index ffb7c58..5632384 100755 --- a/plugins/blacklist.lua +++ b/plugins/blacklist.lua @@ -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) diff --git a/plugins/calc.lua b/plugins/calc.lua index c84066f..168b533 100755 --- a/plugins/calc.lua +++ b/plugins/calc.lua @@ -6,7 +6,7 @@ local utilities = require('utilities') calc.command = 'calc ' calc.doc = [[``` -/calc +]]..utilities.CMD_PAT..[[calc Returns solutions to mathematical expressions and conversions between common units. Results provided by mathjs.org. ```]] diff --git a/plugins/chatter.lua b/plugins/chatter.lua index fc909ee..07ad595 100755 --- a/plugins/chatter.lua +++ b/plugins/chatter.lua @@ -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 diff --git a/plugins/control.lua b/plugins/control.lua index 0edc72f..c9dada8 100644 --- a/plugins/control.lua +++ b/plugins/control.lua @@ -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 \n...\n```', true) + utilities.send_reply(self, msg, 'usage: ```\n'..utilities.CMD_PAT..'script\n'..utilities.CMD_PAT..'command \n...\n```', true) return end input = input .. '\n' diff --git a/plugins/currency.lua b/plugins/currency.lua index 6370138..bf51641 100755 --- a/plugins/currency.lua +++ b/plugins/currency.lua @@ -5,8 +5,8 @@ local utilities = require('utilities') currency.command = 'cash [amount] to ' currency.doc = [[``` -/cash [amount] to -Example: /cash 5 USD to EUR +]]..utilities.CMD_PAT..[[cash [amount] to +Example: ]]..utilities.CMD_PAT..[[cash 5 USD to EUR Returns exchange rates for various currencies. Source: Google Finance. ```]] diff --git a/plugins/dice.lua b/plugins/dice.lua index d12165d..5988002 100755 --- a/plugins/dice.lua +++ b/plugins/dice.lua @@ -4,7 +4,7 @@ local utilities = require('utilities') dice.command = 'roll ' dice.doc = [[``` -/roll +]]..utilities.CMD_PAT..[[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. ```]] diff --git a/plugins/dilbert.lua b/plugins/dilbert.lua index 857b7a1..aa384ed 100644 --- a/plugins/dilbert.lua +++ b/plugins/dilbert.lua @@ -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 diff --git a/plugins/echo.lua b/plugins/echo.lua index 8917209..be66afb 100755 --- a/plugins/echo.lua +++ b/plugins/echo.lua @@ -4,7 +4,7 @@ local utilities = require('utilities') echo.command = 'echo ' echo.doc = [[``` -/echo +]]..utilities.CMD_PAT..[[echo Repeats a string of text. ```]] diff --git a/plugins/gImages.lua b/plugins/gImages.lua index bfc4fbd..a6d2b03 100755 --- a/plugins/gImages.lua +++ b/plugins/gImages.lua @@ -24,9 +24,9 @@ end gImages.command = 'image ' gImages.doc = [[``` -/image -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 +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 diff --git a/plugins/gMaps.lua b/plugins/gMaps.lua index 53959a9..606dec9 100755 --- a/plugins/gMaps.lua +++ b/plugins/gMaps.lua @@ -5,9 +5,9 @@ local utilities = require('utilities') gMaps.command = 'location ' gMaps.doc = [[``` -/location +]]..utilities.CMD_PAT..[[location 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 diff --git a/plugins/gSearch.lua b/plugins/gSearch.lua index 3b00827..f102832 100755 --- a/plugins/gSearch.lua +++ b/plugins/gSearch.lua @@ -7,9 +7,9 @@ local utilities = require('utilities') gSearch.command = 'google ' gSearch.doc = [[``` -/google -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 +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 diff --git a/plugins/hackernews.lua b/plugins/hackernews.lua index a5b6446..1785dc5 100755 --- a/plugins/hackernews.lua +++ b/plugins/hackernews.lua @@ -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() diff --git a/plugins/hearthstone.lua b/plugins/hearthstone.lua index 98c632e..aab27fb 100755 --- a/plugins/hearthstone.lua +++ b/plugins/hearthstone.lua @@ -41,9 +41,9 @@ end hearthstone.command = 'hearthstone ' hearthstone.doc = [[``` -/hearthstone +]]..utilities.CMD_PAT..[[hearthstone Returns Hearthstone card info. -Alias: /hs +Alias: ]]..utilities.CMD_PAT..[[hs ```]] local function format_card(card) diff --git a/plugins/help.lua b/plugins/help.lua index c2f3b05..f78c476 100755 --- a/plugins/help.lua +++ b/plugins/help.lua @@ -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: [optional]' + help_text = help_text .. table.concat(commandlist, '\n• '..utilities.CMD_PAT) .. '\nArguments: [optional]' help_text = help_text:gsub('%[', '\\[') diff --git a/plugins/imdb.lua b/plugins/imdb.lua index 8d2ff29..ce8891a 100755 --- a/plugins/imdb.lua +++ b/plugins/imdb.lua @@ -7,7 +7,7 @@ local utilities = require('utilities') imdb.command = 'imdb ' imdb.doc = [[``` -/imdb +]]..utilities.CMD_PAT..[[imdb Returns an IMDb entry. ```]] diff --git a/plugins/lastfm.lua b/plugins/lastfm.lua index 3351b53..f3dc7bf 100755 --- a/plugins/lastfm.lua +++ b/plugins/lastfm.lua @@ -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 -Sets your last.fm username. Otherwise, /np will use your Telegram username. Use "/fmset --" to delete it. +]]..utilities.CMD_PAT..[[fmset +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 .' + alert = '\n\nYour username has been set to ' .. username .. '.\nTo change it, use '..utilities.CMD_PAT..'fmset .' 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 diff --git a/plugins/luarun.lua b/plugins/luarun.lua index bac9187..511d461 100644 --- a/plugins/luarun.lua +++ b/plugins/luarun.lua @@ -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 diff --git a/plugins/nick.lua b/plugins/nick.lua index 658291a..a1d183e 100755 --- a/plugins/nick.lua +++ b/plugins/nick.lua @@ -4,8 +4,8 @@ local utilities = require('utilities') nick.command = 'nick ' nick.doc = [[``` -/nick -Set your nickname. Use "/nick --" to delete it. +]]..utilities.CMD_PAT..[[nick +Set your nickname. Use "]]..utilities.CMD_PAT..[[nick --" to delete it. ```]] function nick:init() diff --git a/plugins/ping.lua b/plugins/ping.lua index a60a5d1..5877adb 100755 --- a/plugins/ping.lua +++ b/plugins/ping.lua @@ -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 diff --git a/plugins/pokedex.lua b/plugins/pokedex.lua index 31acdfa..145e58b 100755 --- a/plugins/pokedex.lua +++ b/plugins/pokedex.lua @@ -7,9 +7,9 @@ local utilities = require('utilities') pokedex.command = 'pokedex ' pokedex.doc = [[``` -/pokedex +]]..utilities.CMD_PAT..[[pokedex Returns a Pokedex entry from pokeapi.co. -Alias: /dex +Alias: ]]..utilities.CMD_PAT..[[dex ```]] function pokedex:init() diff --git a/plugins/preview.lua b/plugins/preview.lua index d959d97..4042634 100644 --- a/plugins/preview.lua +++ b/plugins/preview.lua @@ -5,7 +5,7 @@ local utilities = require('utilities') preview.command = 'preview ' preview.doc = [[``` -/preview +]]..utilities.CMD_PAT..[[preview Returns a full-message, "unlinked" preview. ```]] diff --git a/plugins/reactions.lua b/plugins/reactions.lua index 53e6659..5ce5a3c 100755 --- a/plugins/reactions.lua +++ b/plugins/reactions.lua @@ -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 diff --git a/plugins/reddit.lua b/plugins/reddit.lua index 00c30a9..1721ead 100755 --- a/plugins/reddit.lua +++ b/plugins/reddit.lua @@ -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 diff --git a/plugins/remind.lua b/plugins/remind.lua index 67a6975..ece2c56 100644 --- a/plugins/remind.lua +++ b/plugins/remind.lua @@ -4,7 +4,7 @@ local utilities = require('utilities') remind.command = 'remind ' remind.doc = [[``` - /remind + ]]..utilities.CMD_PAT..[[remind Repeats a message after a duration of time, in minutes. ```]] diff --git a/plugins/setandget.lua b/plugins/setandget.lua index 60e06e1..4cb3925 100644 --- a/plugins/setandget.lua +++ b/plugins/setandget.lua @@ -9,9 +9,9 @@ end setandget.command = 'set ' setandget.doc = [[``` -/set -Stores a value with the given name. Use "/set --" to delete the stored value. -/get [name] +]]..utilities.CMD_PAT..[[set +Stores a value with the given name. Use "]]..utilities.CMD_PAT..[[set --" 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 diff --git a/plugins/shout.lua b/plugins/shout.lua index 40581fc..c905083 100644 --- a/plugins/shout.lua +++ b/plugins/shout.lua @@ -4,7 +4,7 @@ local utilities = require('utilities') shout.command = 'shout ' shout.doc = [[``` -/shout +]]..utilities.CMD_PAT..[[shout Shouts something. Input may be the replied-to message. ```]] diff --git a/plugins/slap.lua b/plugins/slap.lua index 91c5f1e..a2abfac 100755 --- a/plugins/slap.lua +++ b/plugins/slap.lua @@ -4,7 +4,7 @@ local utilities = require('utilities') slap.command = 'slap [target]' slap.doc = [[``` -/slap [target] +]]..utilities.CMD_PAT..[[slap [target] Slap somebody. ```]] diff --git a/plugins/time.lua b/plugins/time.lua index 0f7af7f..8950432 100755 --- a/plugins/time.lua +++ b/plugins/time.lua @@ -6,7 +6,7 @@ local utilities = require('utilities') time.command = 'time ' time.doc = [[``` -/time +]]..utilities.CMD_PAT..[[time 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 diff --git a/plugins/translate.lua b/plugins/translate.lua index bb073b6..9c49d9c 100755 --- a/plugins/translate.lua +++ b/plugins/translate.lua @@ -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. ```]] diff --git a/plugins/urbandictionary.lua b/plugins/urbandictionary.lua index c376a8b..9fa1d3a 100755 --- a/plugins/urbandictionary.lua +++ b/plugins/urbandictionary.lua @@ -7,9 +7,9 @@ local utilities = require('utilities') urbandictionary.command = 'urbandictionary ' urbandictionary.doc = [[``` -/urbandictionary +]]..utilities.CMD_PAT..[[urbandictionary Returns a definition from Urban Dictionary. -Aliases: /ud, /urban +Aliases: ]]..utilities.CMD_PAT..[[ud, ]]..utilities.CMD_PAT..[[urban ```]] function urbandictionary:init() diff --git a/plugins/weather.lua b/plugins/weather.lua index f4c5444..977a139 100755 --- a/plugins/weather.lua +++ b/plugins/weather.lua @@ -16,7 +16,7 @@ end weather.command = 'weather ' weather.doc = [[``` -/weather +]]..utilities.CMD_PAT..[[weather 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 diff --git a/plugins/whoami.lua b/plugins/whoami.lua index a04b2a0..f0d453e 100755 --- a/plugins/whoami.lua +++ b/plugins/whoami.lua @@ -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() diff --git a/plugins/wikipedia.lua b/plugins/wikipedia.lua index e93fefa..0847c3c 100755 --- a/plugins/wikipedia.lua +++ b/plugins/wikipedia.lua @@ -7,9 +7,9 @@ local utilities = require('utilities') wikipedia.command = 'wikipedia ' wikipedia.doc = [[``` -/wikipedia +]]..utilities.CMD_PAT..[[wikipedia Returns an article from Wikipedia. -Aliases: /w, /wiki +Aliases: ]]..utilities.CMD_PAT..[[w, ]]..utilities.CMD_PAT..[[wiki ```]] function wikipedia:init() diff --git a/plugins/xkcd.lua b/plugins/xkcd.lua index c0e7fe8..6b3e705 100755 --- a/plugins/xkcd.lua +++ b/plugins/xkcd.lua @@ -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. ```]] diff --git a/plugins/youtube.lua b/plugins/youtube.lua index d988fa1..72599bc 100755 --- a/plugins/youtube.lua +++ b/plugins/youtube.lua @@ -19,9 +19,9 @@ end youtube.command = 'youtube ' youtube.doc = [[``` -/youtube +]]..utilities.CMD_PAT..[[youtube Returns the top result from YouTube. -Alias: /yt +Alias: ]]..utilities.CMD_PAT..[[yt ```]] function youtube:action(msg, config) diff --git a/utilities.lua b/utilities.lua index c290845..ffb44e4 100755 --- a/utilities.lua +++ b/utilities.lua @@ -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