2015-04-14 20:21:23 +02:00
|
|
|
function run(msg, matches)
|
|
|
|
local receiver = get_receiver(msg)
|
2015-08-17 18:58:11 +02:00
|
|
|
|
|
|
|
if string.match(msg.text, '^/[Ss][Hh]') then
|
2015-04-14 20:21:23 +02:00
|
|
|
text = run_sh(msg)
|
|
|
|
send_msg(receiver, text, ok_cb, false)
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2015-08-17 18:58:11 +02:00
|
|
|
if string.match(msg.text, '^/[Uu][Pp][Tt][Ii][Mm][Ee]$') then
|
2015-04-14 20:21:23 +02:00
|
|
|
text = run_bash('uptime')
|
|
|
|
send_msg(receiver, text, ok_cb, false)
|
|
|
|
return
|
|
|
|
end
|
2015-06-10 15:06:52 +02:00
|
|
|
|
2015-08-17 18:58:11 +02:00
|
|
|
-- Requires scrot (sudo apt-get install scrot)
|
|
|
|
if string.match(msg.text, '^/[Ss][Cc][Rr][Ee][Ee][Nn]$') then
|
2015-06-10 15:06:52 +02:00
|
|
|
text = run_bash("scrot 'scrot.png' -e 'mv $f ~/Mikubot/tmp/'")
|
|
|
|
send_photo(get_receiver(msg), "tmp/scrot.png", ok_cb, false)
|
|
|
|
return 'Screenshot wird gesendet!'
|
|
|
|
end
|
|
|
|
|
2016-06-02 16:10:03 +02:00
|
|
|
-- Requires fswebcam (sudo apt-get install fswebcam)
|
2016-06-01 20:46:40 +02:00
|
|
|
if string.match(msg.text, '^/[Ww][Ee][Bb][Cc][Aa][Mm]$') then
|
2016-06-02 16:10:03 +02:00
|
|
|
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)
|
2016-06-01 20:46:40 +02:00
|
|
|
end
|
|
|
|
|
2015-08-17 18:58:11 +02:00
|
|
|
-- You need to disable sudo password
|
|
|
|
if string.match(msg.text, '^/[Uu][Pp][Dd][Aa][Tt][Ee]$') then
|
2015-06-10 15:06:52 +02:00
|
|
|
text = run_bash("sudo apt-get update")
|
|
|
|
print(text)
|
|
|
|
return 'Update durchgeführt!'
|
|
|
|
end
|
|
|
|
|
2015-08-17 18:58:11 +02:00
|
|
|
if string.match(msg.text, '^/[Uu][Pp][Gg][Rr][Aa][Dd][Ee]$') then
|
2015-06-10 15:06:52 +02:00
|
|
|
text = run_bash("sudo apt-get upgrade -y")
|
|
|
|
print(text)
|
|
|
|
return 'Upgrade durchgeführt!'
|
|
|
|
end
|
2016-02-28 15:09:04 +01:00
|
|
|
|
|
|
|
if string.match(msg.text, '^/[Cc][Hh][Ee][Cc][Kk]$') then
|
|
|
|
cmd = run_bash("sudo apt-get --just-print upgrade")
|
|
|
|
text = 'Es gibt '..string.match(cmd, '(%d+) aktualisiert')..' Updates'
|
|
|
|
return text
|
|
|
|
end
|
2015-06-10 14:28:44 +02:00
|
|
|
|
2015-08-17 18:58:11 +02:00
|
|
|
-- vcgencmd works only on Raspberry Pi
|
|
|
|
if string.match(msg.text, '^/[Tt][Ee][Mm][Pp]$') then
|
|
|
|
text = run_bash('vcgencmd measure_temp')
|
|
|
|
text = string.gsub(text, "temp=", " ")
|
|
|
|
return "Die CPU Temperatur beträgt" ..text
|
|
|
|
end
|
|
|
|
|
|
|
|
if string.match(msg.text, '^/[Vv][Oo][Ll][Tt]$') then
|
|
|
|
text = run_bash('vcgencmd measure_volts')
|
|
|
|
send_msg(receiver, text, ok_cb, false)
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
if string.match(msg.text, '^/[Tt][Aa][Kk][Tt]$') then
|
|
|
|
text = run_bash('vcgencmd measure_clock arm')
|
|
|
|
send_msg(receiver, text, ok_cb, false)
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2015-04-14 20:21:23 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
return {
|
|
|
|
description = "Führt Befehle in der Konsole aus",
|
2015-08-17 18:58:11 +02:00
|
|
|
usage = {"/sh [Befehl]","/uptime","/temp","/volt","/takt","/screen","/update","/upgrade"},
|
|
|
|
patterns = {"^/[Ss][Hh] (.*)$",
|
|
|
|
"^/[Uu][Pp][Tt][Ii][Mm][Ee]$",
|
|
|
|
"^/[Ss][Cc][Rr][Ee][Ee][Nn]$",
|
|
|
|
"^/[Uu][Pp][Dd][Aa][Tt][Ee]$",
|
|
|
|
"^/[Uu][Pp][Gg][Rr][Aa][Dd][Ee]$",
|
|
|
|
"^/[Tt][Ee][Mm][Pp]$",
|
|
|
|
"^/[Vv][Oo][Ll][Tt]$",
|
2016-02-28 15:09:04 +01:00
|
|
|
"^/[Tt][Aa][Kk][Tt]$",
|
2016-06-01 20:46:40 +02:00
|
|
|
"^/[Cc][Hh][Ee][Cc][Kk]$",
|
|
|
|
"^/[Ww][Ee][Bb][Cc][Aa][Mm]$"
|
2015-08-17 18:58:11 +02:00
|
|
|
},
|
2015-04-14 20:21:23 +02:00
|
|
|
run = run,
|
|
|
|
privileged = true
|
2015-04-15 18:45:45 +02:00
|
|
|
}
|