2016-04-10 21:04:47 -07:00
|
|
|
local control = {}
|
2015-12-13 09:25:49 -05:00
|
|
|
|
2016-06-07 00:31:34 -04:00
|
|
|
local bot = require('otouto.bot')
|
|
|
|
local utilities = require('otouto.utilities')
|
2015-12-13 09:25:49 -05:00
|
|
|
|
2016-05-26 20:28:44 -07: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,
|
2016-06-18 12:51:13 +02:00
|
|
|
{'^'..cmd_pat..'script'}):t('restart', true):t('halt').table
|
2016-04-10 21:04:47 -07:00
|
|
|
end
|
|
|
|
|
2016-05-26 17:26:30 -07:00
|
|
|
function control:action(msg, config)
|
2016-04-10 21:04:47 -07:00
|
|
|
|
2016-05-26 17:26:30 -07:00
|
|
|
if msg.from.id ~= config.admin then
|
2015-12-13 09:25:49 -05:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2016-04-17 23:28:55 -04:00
|
|
|
if msg.date < os.time() - 1 then return end
|
2016-02-22 15:53:17 -05:00
|
|
|
|
2016-06-18 12:51:13 +02:00
|
|
|
if msg.text_lower:match('^'..cmd_pat..'restart') then
|
2016-04-28 21:36:35 -07:00
|
|
|
for pac, _ in pairs(package.loaded) do
|
2016-06-07 03:02:05 -04:00
|
|
|
if pac:match('^otouto%.plugins%.') then
|
2016-04-28 21:36:35 -07:00
|
|
|
package.loaded[pac] = nil
|
|
|
|
end
|
|
|
|
end
|
2016-06-07 03:13:54 -04:00
|
|
|
package.loaded['otouto.bindings'] = nil
|
|
|
|
package.loaded['otouto.utilities'] = nil
|
2016-05-26 17:26:30 -07:00
|
|
|
package.loaded['config'] = nil
|
2016-05-26 20:28:44 -07:00
|
|
|
if msg.text_lower:match('%+config') then for k, v in pairs(require('config')) do
|
2016-05-26 17:26:30 -07:00
|
|
|
config[k] = v
|
2016-05-26 20:28:44 -07:00
|
|
|
end end
|
2016-05-26 17:26:30 -07:00
|
|
|
bot.init(self, config)
|
2016-05-29 13:08:39 -04:00
|
|
|
utilities.send_reply(self, msg, 'Bot reloaded!')
|
2016-05-26 20:28:44 -07:00
|
|
|
elseif msg.text_lower:match('^'..cmd_pat..'halt') then
|
2016-04-10 21:04:47 -07:00
|
|
|
self.is_started = false
|
2016-05-29 13:08:39 -04:00
|
|
|
utilities.send_reply(self, msg, 'Stopping bot!')
|
2016-05-26 20:28:44 -07:00
|
|
|
elseif msg.text_lower:match('^'..cmd_pat..'script') then
|
|
|
|
local input = msg.text_lower:match('^'..cmd_pat..'script\n(.+)')
|
2016-05-20 20:47:13 -04:00
|
|
|
if not input then
|
2016-05-26 20:28:44 -07:00
|
|
|
utilities.send_reply(self, msg, 'usage: ```\n'..cmd_pat..'script\n'..cmd_pat..'command <arg>\n...\n```', true)
|
2016-05-20 20:47:13 -04:00
|
|
|
return
|
|
|
|
end
|
|
|
|
input = input .. '\n'
|
|
|
|
for command in input:gmatch('(.-)\n') do
|
|
|
|
command = utilities.trim(command)
|
|
|
|
msg.text = command
|
2016-06-17 01:13:05 -04:00
|
|
|
bot.on_msg_receive(self, msg, config)
|
2016-05-20 20:47:13 -04:00
|
|
|
end
|
2015-12-13 09:25:49 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
2016-04-10 21:04:47 -07:00
|
|
|
return control
|
2015-12-13 09:25:49 -05:00
|
|
|
|