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/plugins/admin.lua

76 lines
1.2 KiB
Lua
Raw Normal View History

local triggers = {
'^/admin[@'..bot.username..']*'
2015-07-03 00:15:52 +02:00
}
local commands = {
['run'] = function(cmd)
local cmd = cmd:input()
if not cmd then
return 'Please enter a command to run.'
end
return io.popen(cmd):read('*all')
end,
2015-07-03 00:15:52 +02:00
['lua'] = function(cmd)
local cmd = cmd:input()
if not cmd then
return 'Please enter a command to run.'
end
local a = loadstring(cmd)()
if a then
return a
else
return 'Done!'
end
end,
2015-07-03 00:15:52 +02:00
['reload'] = function(cmd)
bot_init()
return 'Bot reloaded!'
end,
2015-07-08 04:24:12 +02:00
['halt'] = function(cmd)
is_started = false
return 'Stopping bot!'
end,
2015-07-03 00:15:52 +02:00
['error'] = function(cmd)
error('Intentional test error.')
end
2015-07-03 00:15:52 +02:00
}
2015-07-03 00:15:52 +02:00
local action = function(msg)
2015-07-03 00:15:52 +02:00
if msg.from.id ~= config.admin then
return
end
2015-07-03 00:15:52 +02:00
local input = msg.text:input()
if not input then
local list = 'Specify a command: '
for k,v in pairs(commands) do
list = list .. k .. ', '
end
list = list:gsub(', $', '.')
sendReply(msg, list)
return
end
2015-07-03 00:15:52 +02:00
for k,v in pairs(commands) do
if string.match(get_word(input, 1), k) then
sendReply(msg, v(input))
return
end
2015-07-03 00:15:52 +02:00
end
sendReply(msg, 'Specify a command: run, reload, halt.')
2015-07-03 00:15:52 +02:00
end
return {
action = action,
triggers = triggers
}