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

115 lines
4.1 KiB
Lua
Raw Normal View History

local shell = {}
function shell:init(config)
2016-08-22 21:53:49 +02:00
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
2016-08-22 21:53:49 +02:00
function shell:transeng(ger)
2016-10-20 19:06:39 +02:00
--Days
2016-08-22 22:19:43 +02:00
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")
2016-10-20 19:06:39 +02:00
--Weeks
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.')
2016-10-20 19:06:39 +02:00
--Months
local ger = string.gsub(ger, "January", "Januar")
local ger = string.gsub(ger, "February", "Februar")
local ger = string.gsub(ger, "March", "März")
local ger = string.gsub(ger, "April", "April")
local ger = string.gsub(ger, "May", "Mai")
local ger = string.gsub(ger, "June", "Juni")
local ger = string.gsub(ger, "July", "Juli")
local ger = string.gsub(ger, "August", "August")
local ger = string.gsub(ger, "September", "September")
local ger = string.gsub(ger, "October", "Oktober")
local ger = string.gsub(ger, "November", "November")
local ger = string.gsub(ger, "December", "Dezember")
2016-08-22 21:53:49 +02:00
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(msg, config.errors.sudo, true)
return
end
2016-08-22 21:53:49 +02:00
local input = matches[1]
2017-08-14 23:39:44 +02:00
local taken_time = os.date("%A, %d. %B %Y um %H:%M:%S Uhr")
2016-08-22 21:53:49 +02:00
if msg.text:match('^/[Uu][Pp][Tt][Ii][Mm][Ee]$') then
local cmd = run_command('uptime -s && uptime -p')
2016-08-22 22:11:23 +02:00
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>')
2016-08-24 17:18:17 +02:00
utilities.send_reply(msg, text1..'\n'..text2, 'HTML')
2016-08-22 21:53:49 +02:00
return
end
-- Requires scrot (sudo apt-get install scrot)
if msg.text:match('^/[Ss][Cc][Rr][Ee][Ee][Nn]$') then
2017-08-14 23:39:44 +02:00
run_command("scrot '/tmp/scrot.png'")
local text = '#Screenshot vom '..shell:transeng(taken_time)
2016-08-24 17:18:17 +02:00
utilities.send_photo(msg.chat.id, '/tmp/scrot.png', text, msg.message_id)
2016-08-22 21:53:49 +02:00
return
end
-- Requires fswebcam (sudo apt-get install fswebcam)
if msg.text:match('^/[Ww][Ee][Bb][Cc][Aa][Mm]$') then
2016-10-28 23:15:08 +02:00
run_command("fswebcam -r 1280x1024 --png 9 -D 1 /tmp/webcam.png")
2017-08-14 23:39:44 +02:00
local text = '#Webcam vom '..shell:transeng(taken_time)
utilities.send_photo(msg.chat.id, '/tmp/webcam.png', text, msg.message_id)
2016-08-22 21:53:49 +02:00
return
end
if msg.text:match('^/[Cc][Hh][Ee][Cc][Kk]$') then
local cmd = run_command("apt --just-print upgrade")
2017-08-14 23:39:44 +02:00
local text = 'Es gibt <b>'..string.match(cmd, '(%d+) aktualisiert')..'</b> Updates.'
2016-08-24 17:18:17 +02:00
utilities.send_reply(msg, text, 'HTML')
2016-08-22 21:53:49 +02:00
return
end
-- Requires vnstat & vnstati (sudo apt-get install vnstat vnstati)
if msg.text:match('^/[Tt][Rr][Aa][Ff][Ff][Ii][Cc]$') then
2016-12-12 19:15:38 +01:00
local network = 'wlan0' -- You can see your network with "ifconfig" in an terminal
2016-09-07 20:13:27 +02:00
run_command("vnstati -m -vs -i "..network.." -o /tmp/vnstat.png")
2016-08-24 17:18:17 +02:00
utilities.send_photo(msg.chat.id, '/tmp/vnstat.png', nil, msg.message_id)
return
end
2016-08-22 21:53:49 +02:00
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>')
2016-08-24 17:18:17 +02:00
utilities.send_message(msg.chat.id, output, true, msg.message_id, 'HTML')
end
return shell