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

78 lines
2.5 KiB
Lua

do
local function 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
local function run(msg, matches)
local receiver = get_receiver(msg)
if string.match(msg.text, '^#[Ss][Hh]') then
text = run_sh(msg)
send_msg(receiver, text, ok_cb, false)
return
end
if string.match(msg.text, '^#[Uu][Pp][Tt][Ii][Mm][Ee]$') then
cmd = run_bash('uptime -s && uptime -p')
text1 = 'Der PC ist seit dem '..makeOurDate(string.match(cmd, '(%d+-%d+-%d+)'))..' an.'
text2 = transeng('Das sind '..string.match(cmd, 'up (.*)'))
return text1..'\n'..text2
end
-- Requires scrot (sudo apt-get install scrot)
if string.match(msg.text, '^#[Ss][Cc][Rr][Ee][Ee][Nn]$') then
text = run_bash("scrot 'scrot.png' -e 'mv $f ~/Mikubot/tmp/'")
send_photo(get_receiver(msg), "tmp/scrot.png", ok_cb, false)
end
-- Requires fswebcam (sudo apt-get install fswebcam)
if string.match(msg.text, '^#[Ww][Ee][Bb][Cc][Aa][Mm]$') then
text = run_bash("fswebcam -r 640x480 --png 9 -D 1 ~/Mikubot/tmp/webcam.png")
send_photo(get_receiver(msg), "tmp/webcam.png", ok_cb, false)
end
if string.match(msg.text, '^#[Cc][Hh][Ee][Cc][Kk]$') then
cmd = run_bash("apt --just-print upgrade")
text = 'Es gibt '..string.match(cmd, '(%d+) aktualisiert')..' Updates'
return text
end
-- Requires vnstat & vnstati (sudo apt-get install vnstat vnstati)
if string.match(msg.text, '^#[Tt][Rr][Aa][Ff][Ff][Ii][Cc]$') then
text = run_bash("vnstati -m -vs -i enp2s0 -o tmp/vnstat.png")
send_photo(get_receiver(msg), "tmp/vnstat.png", ok_cb, false)
end
end
return {
description = "Führt Befehle in der Konsole aus",
usage = {"#sh [Befehl]","#uptime","#screen","#check","#webcam"},
patterns = {"^#[Ss][Hh] (.*)$",
"^#[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]$"
},
run = run,
privileged = true
}
end