59 lines
1.6 KiB
Lua
59 lines
1.6 KiB
Lua
local control = {}
|
|
|
|
local bot = require('miku.bot')
|
|
local utilities = require('miku.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
|
|
|
|
function control:action(msg, config)
|
|
|
|
if msg.from.id ~= config.admin then
|
|
return
|
|
end
|
|
|
|
if msg.date < os.time() - 2 then return end
|
|
|
|
if msg.text_lower:match('^'..cmd_pat..'restart') then
|
|
for pac, _ in pairs(package.loaded) do
|
|
if pac:match('^miku%.plugins%.') then
|
|
package.loaded[pac] = nil
|
|
end
|
|
end
|
|
package.loaded['miku.bindings'] = nil
|
|
package.loaded['miku.utilities'] = nil
|
|
package.loaded['config'] = nil
|
|
if not msg.text_lower:match('%-config') then
|
|
for k, v in pairs(require('config')) do
|
|
config[k] = v
|
|
end
|
|
end
|
|
bot.init(self, config)
|
|
utilities.send_reply(self, msg, 'Bot neu gestartet!')
|
|
elseif msg.text_lower:match('^'..cmd_pat..'halt') then
|
|
self.is_started = false
|
|
utilities.send_reply(self, msg, 'Stoppe 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
|
|
|