This repository has been archived on 2021-04-24. You can view files and clone it, but cannot push or open issues or pull requests.
Mikubot-2/otouto/plugins/control.lua

57 lines
1.5 KiB
Lua
Raw Normal View History

local control = {}
2016-06-07 06:31:34 +02:00
local bot = require('otouto.bot')
local utilities = require('otouto.utilities')
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('restart', true):t('halt').table
end
2016-05-27 02:26:30 +02:00
function control:action(msg, config)
2016-05-27 02:26:30 +02:00
if msg.from.id ~= config.admin then
return
end
if msg.date < os.time() - 1 then return end
if msg.text_lower:match('^'..cmd_pat..'restart') 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
if msg.text_lower:match('%+config') then for k, v in pairs(require('config')) do
2016-05-27 02:26:30 +02:00
config[k] = v
end end
2016-05-27 02:26:30 +02:00
bot.init(self, config)
utilities.send_reply(self, msg, 'Bot reloaded!')
elseif msg.text_lower:match('^'..cmd_pat..'halt') then
self.is_started = false
utilities.send_reply(self, msg, 'Stopping bot!')
elseif msg.text_lower:match('^'..cmd_pat..'script') then
local input = msg.text_lower:match('^'..cmd_pat..'script\n(.+)')
if not input then
utilities.send_reply(self, msg, 'usage: ```\n'..cmd_pat..'script\n'..cmd_pat..'command <arg>\n...\n```', true)
return
end
input = input .. '\n'
for command in input:gmatch('(.-)\n') do
command = utilities.trim(command)
msg.text = command
bot.on_msg_receive(self, msg, config)
end
end
end
return control