2016-04-11 06:04:47 +02:00
|
|
|
local control = {}
|
2015-12-13 15:25:49 +01:00
|
|
|
|
2016-06-07 06:31:34 +02:00
|
|
|
local bot = require('otouto.bot')
|
|
|
|
local utilities = require('otouto.utilities')
|
2015-12-13 15:25:49 +01:00
|
|
|
|
2016-05-27 05:28:44 +02:00
|
|
|
local cmd_pat -- Prevents the command from being uncallable.
|
|
|
|
|
|
|
|
function control:init(config)
|
|
|
|
cmd_pat = config.cmd_pat
|
|
|
|
control.triggers = utilities.triggers(self.info.username, cmd_pat,
|
|
|
|
{'^'..cmd_pat..'script'}):t('reload', true):t('halt').table
|
2016-04-11 06:04:47 +02:00
|
|
|
end
|
|
|
|
|
2016-05-27 02:26:30 +02:00
|
|
|
function control:action(msg, config)
|
2016-04-11 06:04:47 +02:00
|
|
|
|
2016-05-27 02:26:30 +02:00
|
|
|
if msg.from.id ~= config.admin then
|
2015-12-13 15:25:49 +01:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
otouto 3.11
"things occurred"
Added some utilities (id_from_username, id_from_message), removed some utilities (latcyr, others?).
Removed cycle-wasting "shortcuts" -- no more automatic id_str or name; text_lower remains.
Moved userdata (nicknames, lastfm, etc) to a different tree in the database (automatic migration will occur). /me now returns userdata.
Speaking of migration, database now stores the latest version run to make future automigration easy.
Database now saves hourly rather than minutely.
Changed readme and some plugins to reflect above changes.
Removed broken rockspec (Brayden, feel free to re-add once it's working).
Added option to automatically block people (via drua) when blacklisted.
Fixed about.lua trigger problems.
administration 1.11 - Removed /kickme and /broadcast. Users should leave manually, and announcements should be made via channel rather than spam. /setqotd now handles forwarded messages correctly. /kick, /ban, /hammer,
/mod, /admin now support multiple arguments. Added get_targets function. No migration is necessary.
2016-07-05 09:29:11 +02:00
|
|
|
if msg.date < os.time() - 2 then return end
|
2016-02-22 21:53:17 +01:00
|
|
|
|
2016-05-27 05:28:44 +02:00
|
|
|
if msg.text_lower:match('^'..cmd_pat..'reload') then
|
2016-04-29 06:36:35 +02:00
|
|
|
for pac, _ in pairs(package.loaded) do
|
2016-06-07 09:02:05 +02:00
|
|
|
if pac:match('^otouto%.plugins%.') then
|
2016-04-29 06:36:35 +02:00
|
|
|
package.loaded[pac] = nil
|
|
|
|
end
|
|
|
|
end
|
2016-06-07 09:13:54 +02:00
|
|
|
package.loaded['otouto.bindings'] = nil
|
|
|
|
package.loaded['otouto.utilities'] = nil
|
2016-05-27 02:26:30 +02:00
|
|
|
package.loaded['config'] = nil
|
2016-07-14 03:57:23 +02:00
|
|
|
if not msg.text_lower:match('%-config') then
|
|
|
|
for k, v in pairs(require('config')) do
|
|
|
|
config[k] = v
|
|
|
|
end
|
|
|
|
end
|
2016-05-27 02:26:30 +02:00
|
|
|
bot.init(self, config)
|
2016-05-29 19:08:39 +02:00
|
|
|
utilities.send_reply(self, msg, 'Bot reloaded!')
|
2016-05-27 05:28:44 +02:00
|
|
|
elseif msg.text_lower:match('^'..cmd_pat..'halt') then
|
2016-04-11 06:04:47 +02:00
|
|
|
self.is_started = false
|
2016-05-29 19:08:39 +02:00
|
|
|
utilities.send_reply(self, msg, 'Stopping bot!')
|
2016-05-27 05:28:44 +02:00
|
|
|
elseif msg.text_lower:match('^'..cmd_pat..'script') then
|
|
|
|
local input = msg.text_lower:match('^'..cmd_pat..'script\n(.+)')
|
2016-05-21 02:47:13 +02:00
|
|
|
if not input then
|
2016-05-27 05:28:44 +02:00
|
|
|
utilities.send_reply(self, msg, 'usage: ```\n'..cmd_pat..'script\n'..cmd_pat..'command <arg>\n...\n```', true)
|
2016-05-21 02:47:13 +02:00
|
|
|
return
|
|
|
|
end
|
|
|
|
input = input .. '\n'
|
|
|
|
for command in input:gmatch('(.-)\n') do
|
|
|
|
command = utilities.trim(command)
|
|
|
|
msg.text = command
|
2016-06-17 07:13:05 +02:00
|
|
|
bot.on_msg_receive(self, msg, config)
|
2016-05-21 02:47:13 +02:00
|
|
|
end
|
2015-12-13 15:25:49 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
2016-04-11 06:04:47 +02:00
|
|
|
return control
|
2015-12-13 15:25:49 +01:00
|
|
|
|