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/shell.lua

36 lines
795 B
Lua
Raw Normal View History

local shell = {}
2016-06-07 06:31:34 +02:00
local utilities = require('otouto.utilities')
function shell:init(config)
2016-08-14 04:46:18 +02:00
shell.triggers = utilities.triggers(self.info.username, config.cmd_pat):t('run', true).table
end
2016-05-27 02:26:30 +02:00
function shell:action(msg, config)
2016-08-14 04:46:18 +02:00
if msg.from.id ~= config.admin then
return
end
local input = utilities.input(msg.text)
input = input:gsub('', '--')
if not input then
utilities.send_reply(self, msg, 'Please specify a command to run.')
return
end
local f = io.popen(input)
local output = f:read('*all')
f:close()
if output:len() == 0 then
output = 'Done!'
else
output = '```\n' .. output .. '\n```'
end
utilities.send_message(self, msg.chat.id, output, true, msg.message_id, true)
end
return shell