98 lines
3.3 KiB
Lua
98 lines
3.3 KiB
Lua
local shell = {}
|
|
|
|
function shell:init(config)
|
|
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
|
|
|
|
function shell:transeng(ger)
|
|
local ger = string.gsub(ger, 'week,', 'Woche,')
|
|
local ger = string.gsub(ger, 'weeks,', 'Wochen,')
|
|
local ger = string.gsub(ger, 'day,', 'Tag,')
|
|
local ger = string.gsub(ger, 'days,', 'Tage,')
|
|
local ger = string.gsub(ger, 'hour,', 'Stunde und')
|
|
local ger = string.gsub(ger, 'hours,', 'Stunden und')
|
|
local ger = string.gsub(ger, 'minute$', 'Minute.')
|
|
local ger = string.gsub(ger, 'minutes', 'Minuten.')
|
|
local ger = string.gsub(ger, "Monday", "Montag")
|
|
local ger = string.gsub(ger, "Tuesday", "Dienstag")
|
|
local ger = string.gsub(ger, "Wednesday", "Mittwoch")
|
|
local ger = string.gsub(ger, "Thursday", "Donnerstag")
|
|
local ger = string.gsub(ger, "Friday", "Freitag")
|
|
local ger = string.gsub(ger, "Saturday", "Samstag")
|
|
local ger = string.gsub(ger, "Sunday", "Sonntag")
|
|
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
|
|
utilities.send_reply(self, msg, config.errors.sudo)
|
|
return
|
|
end
|
|
|
|
local input = matches[1]
|
|
|
|
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 <b>'..makeOurDate(string.match(cmd, '(%d+-%d+-%d+)'))..'</b> an.'
|
|
local text2 = shell:transeng('Das sind <b>'..string.match(cmd, 'up (.*)')..'</b>')
|
|
utilities.send_reply(self, msg, text1..'\n'..text2, 'HTML')
|
|
return
|
|
end
|
|
|
|
-- Requires scrot (sudo apt-get install scrot)
|
|
if msg.text:match('^/[Ss][Cc][Rr][Ee][Ee][Nn]$') then
|
|
local taken_time = os.date("%A, %d. %B %Y um %H:%M:%S Uhr")
|
|
run_command("scrot 'scrot.png' -e 'mv $f /tmp/'")
|
|
local text = '#Screenshot vom '..shell:transeng(taken_time)
|
|
utilities.send_photo(self, msg.chat.id, '/tmp/scrot.png', text, msg.message_id)
|
|
return
|
|
end
|
|
|
|
-- Requires fswebcam (sudo apt-get install fswebcam)
|
|
if msg.text:match('^/[Ww][Ee][Bb][Cc][Aa][Mm]$') then
|
|
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 <b>'..string.match(cmd, '(%d+) aktualisiert')..'</b> Updates'
|
|
utilities.send_reply(self, msg, text, 'HTML')
|
|
return
|
|
end
|
|
|
|
-- Requires vnstat & vnstati (sudo apt-get install vnstat vnstati)
|
|
if msg.text:match('^/[Tt][Rr][Aa][Ff][Ff][Ii][Cc]$') then
|
|
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('—', '--')
|
|
|
|
local output = run_command(input)
|
|
if output:len() == 0 then
|
|
output = 'Ausgeführt.'
|
|
else
|
|
output = '<pre>\n' .. output .. '\n</pre>'
|
|
end
|
|
output = output:gsub('<pre>%\n', '<pre>')
|
|
output = output:gsub('%\n%\n</pre>', '</pre>')
|
|
utilities.send_message(self, msg.chat.id, output, true, msg.message_id, 'HTML')
|
|
end
|
|
|
|
return shell |