Shell: Portiere weitere Kommandos
This commit is contained in:
parent
d52f30be0d
commit
8d134a4000
@ -1,20 +1,78 @@
|
|||||||
local shell = {}
|
local shell = {}
|
||||||
|
|
||||||
function shell:init(config)
|
function shell:init(config)
|
||||||
shell.triggers = utilities.triggers(self.info.username, config.cmd_pat):t('sh', true).table
|
shell.triggers = {
|
||||||
|
"^/[Cc][Mm][Dd] (.+)$",
|
||||||
|
"^/[Uu][Pp][Tt][Ii][Mm][Ee]$",
|
||||||
|
"^/[Ss][Cc][Rr][Ee][Ee][Nn]$",
|
||||||
|
"^/[Cc][Hh][Ee][Cc][Kk]$",
|
||||||
|
"^/[Ww][Ee][Bb][Cc][Aa][Mm]$",
|
||||||
|
"^/[Tt][Rr][Aa][Ff][Ff][Ii][Cc]$"
|
||||||
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
function shell:action(msg, config)
|
function shell:transeng(ger)
|
||||||
|
ger = string.gsub(ger, 'week,', 'Woche,')
|
||||||
|
ger = string.gsub(ger, 'weeks,', 'Wochen,')
|
||||||
|
ger = string.gsub(ger, 'day,', 'Tag,')
|
||||||
|
ger = string.gsub(ger, 'days,', 'Tage,')
|
||||||
|
ger = string.gsub(ger, 'hour,', 'Stunde und')
|
||||||
|
ger = string.gsub(ger, 'hours,', 'Stunden und')
|
||||||
|
ger = string.gsub(ger, 'minute$', 'Minute.')
|
||||||
|
ger = string.gsub(ger, 'minutes', 'Minuten.')
|
||||||
|
return ger
|
||||||
|
end
|
||||||
|
|
||||||
|
local makeOurDate = function(dateString)
|
||||||
|
local pattern = "(%d+)%-(%d+)%-(%d+)"
|
||||||
|
local year, month, day = dateString:match(pattern)
|
||||||
|
return day..'.'..month..'.'..year
|
||||||
|
end
|
||||||
|
|
||||||
|
function shell:action(msg, config, matches)
|
||||||
if not is_sudo(msg, config) then
|
if not is_sudo(msg, config) then
|
||||||
utilities.send_reply(self, msg, config.errors.sudo)
|
utilities.send_reply(self, msg, config.errors.sudo)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local input = utilities.input(msg.text)
|
local input = matches[1]
|
||||||
if not input then
|
|
||||||
utilities.send_reply(self, msg, 'Bitte gib ein Kommando ein.')
|
if msg.text:match('^/[Uu][Pp][Tt][Ii][Mm][Ee]$') then
|
||||||
|
local cmd = run_command('uptime -s && uptime -p')
|
||||||
|
local text1 = 'Der PC ist seit dem '..makeOurDate(string.match(cmd, '(%d+-%d+-%d+)'))..' an.'
|
||||||
|
local text2 = shell:transeng('Das sind '..string.match(cmd, 'up (.*)'))
|
||||||
|
utilities.send_reply(self, msg, text1..'\n'..text2)
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Requires scrot (sudo apt-get install scrot)
|
||||||
|
if msg.text:match('^/[Ss][Cc][Rr][Ee][Ee][Nn]$') then
|
||||||
|
local text = run_command("scrot 'scrot.png' -e 'mv $f /tmp/'")
|
||||||
|
utilities.send_photo(self, msg.chat.id, '/tmp/scrot.png', nil, msg.message_id)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Requires fswebcam (sudo apt-get install fswebcam)
|
||||||
|
if msg.text:match('^/[Ww][Ee][Bb][Cc][Aa][Mm]$') then
|
||||||
|
local text = run_command("fswebcam -r 640x480 --png 9 -D 1 /tmp/webcam.png")
|
||||||
|
utilities.send_photo(self, msg.chat.id, '/tmp/webcam.png', nil, msg.message_id)
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
if msg.text:match('^/[Cc][Hh][Ee][Cc][Kk]$') then
|
||||||
|
local cmd = run_command("apt --just-print upgrade")
|
||||||
|
local text = 'Es gibt '..string.match(cmd, '(%d+) aktualisiert')..' Updates'
|
||||||
|
utilities.send_reply(self, msg, text)
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Requires vnstat & vnstati (sudo apt-get install vnstat vnstati)
|
||||||
|
if msg.text:match('^/[Tt][Rr][Aa][Ff][Ff][Ii][Cc]$') then
|
||||||
|
local text = run_command("vnstati -m -vs -i enp2s0 -o /tmp/vnstat.png")
|
||||||
|
utilities.send_photo(self, msg.chat.id, '/tmp/vnstat.png', nil, msg.message_id)
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
input = input:gsub('—', '--')
|
input = input:gsub('—', '--')
|
||||||
|
|
||||||
local output = run_command(input)
|
local output = run_command(input)
|
||||||
|
Reference in New Issue
Block a user