-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaction.lua
executable file
·56 lines (47 loc) · 1.19 KB
/
action.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
function on_msg_receive (msg)
if (msg.from.id == our_id) then
--Para ejecutar comandos en la terminal
t={}
str = msg.text
str:gsub(".",function(c) table.insert(t,c) end)
if (t[1] == '$') then
str = string.sub(str, 2)
foo = os.capture("cd ~; " .. str)
send_msg (msg.to.print_name, foo, ok_cb, false)
end
--[[en caso de querer ejecutar un comando sin recibir
la salida cambiar os.capture por os.execute
]]
if (msg.text == 'ip pubica' or msg.text == 'ip1') then
foo = os.capture('bash /home/pi/t_notifications/ip_pubica.sh')
send_msg (msg.to.print_name, foo, ok_cb, false)
end
if (msg.text == 'ip2') then
foo = os.capture('bash /home/pi/t_notifications/ip_pubica2.sh')
send_msg (msg.to.print_name, foo, ok_cb, false)
end
end
return
end
function os.capture(cmd, raw)
local f = assert(io.popen(cmd, 'r'))
local s = assert(f:read('*a'))
f:close()
if raw then return s end
s = string.gsub(s, '^%s+', '')
s = string.gsub(s, '%s+$', '')
return s
end
function on_our_id (id)
our_id = id
end
function on_secret_chat_created (peer)
end
function on_user_update (user)
end
function on_chat_update (user)
end
function on_get_difference_end ()
end
function on_binlog_replay_end ()
end