Advertisement
Guest User

test.lua

a guest
May 16th, 2015
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.06 KB | None | 0 0
  1. started = 0
  2. our_id = 0
  3.  
  4. function vardump(value, depth, key)
  5.   local linePrefix = ""
  6.   local spaces = ""
  7.  
  8.   if key ~= nil then
  9.     linePrefix = "["..key.."] = "
  10.   end
  11.  
  12.   if depth == nil then
  13.     depth = 0
  14.   else
  15.     depth = depth + 1
  16.     for i=1, depth do spaces = spaces .. "  " end
  17.   end
  18.  
  19.   if type(value) == 'table' then
  20.     mTable = getmetatable(value)
  21.     if mTable == nil then
  22.       print(spaces ..linePrefix.."(table) ")
  23.     else
  24.       print(spaces .."(metatable) ")
  25.         value = mTable
  26.     end    
  27.     for tableKey, tableValue in pairs(value) do
  28.       vardump(tableValue, depth, tableKey)
  29.     end
  30.   elseif type(value)    == 'function' or
  31.       type(value)   == 'thread' or
  32.       type(value)   == 'userdata' or
  33.       value     == nil
  34.   then
  35.     print(spaces..tostring(value))
  36.   else
  37.     print(spaces..linePrefix.."("..type(value)..") "..tostring(value))
  38.   end
  39. end
  40.  
  41. print ("HI, this is lua script")
  42.  
  43. function ok_cb(extra, success, result)
  44. end
  45.  
  46. function on_msg_receive (msg)
  47.   if started == 0 then
  48.     return
  49.   end
  50.   if msg.out then
  51.     return
  52.   end
  53.   --Damit der "Gelesen Haken" erscheint
  54.   if msg.text then
  55.     mark_read (msg.from.print_name, ok_cb, false)
  56.   end
  57.  
  58.   --Ggf. nur eine Rufnummer zulassen:
  59.   if msg.from.print_name ~= 'Stefan' then
  60.     os.execute("/home/pi/tg/send_script ".. msg.from.print_name .." 'Ungültige Nr.'")
  61.     return
  62.   end
  63.   if (string.lower(msg.text) == 'uptime') then
  64.     local handle = io.popen("python /home/pi/tg/tg_actions.py uptime")
  65.     local res = handle:read("*a")
  66.     handle:close()
  67.     os.execute("/home/pi/tg/send_script ".. msg.from.print_name .." '"..res.."'")
  68.     --Alternativ:
  69.     --send_msg (msg.from.print_name, res)
  70.     return
  71.   elseif (string.lower(msg.text) == 'shutdown') then
  72.     local handle = io.popen("sudo python /home/pi/tg/tg_actions.py shutdown")
  73.     local res = handle:read("*a")
  74.     handle:close()
  75.     os.execute("/home/pi/tg/send_script "..msg.from.print_name.." '"..res.."'")
  76.     return
  77.   elseif (string.lower(msg.text) == 'reboot') then
  78.     local handle = io.popen("sudo python /home/pi/tg/tg_actions.py reboot")
  79.     local res = handle:read("*a")
  80.     handle:close()
  81.     os.execute("/home/pi/tg/send_script ".. msg.from.print_name .." '"..res.."'")
  82.     return
  83.   elseif (string.lower(msg.text) == 't1h') then
  84.     local handle = io.popen("sudo python /home/pi/tg/tg_actions.py t1h")
  85.     local res = handle:read("*a")
  86.     handle:close()
  87.     os.execute("/home/pi/tg/send_script ".. msg.from.print_name .." '"..res.."'")
  88.     return
  89.     else
  90.     os.execute("/home/pi/tg/send_script ".. msg.from.print_name .." 'Fehler' ")
  91.   end
  92.  
  93. end
  94.  
  95. function on_our_id (id)
  96.   our_id = id
  97. end
  98.  
  99. function on_user_update (user, what)
  100.   --vardump (user)
  101. end
  102.  
  103. function on_chat_update (chat, what)
  104.   --vardump (chat)
  105. end
  106.  
  107. function on_secret_chat_update (schat, what)
  108.   --vardump (schat)
  109. end
  110.  
  111. function on_get_difference_end ()
  112. end
  113.  
  114. function cron()
  115.   -- do something
  116.   postpone (cron, false, 1.0)
  117. end
  118.  
  119. function on_binlog_replay_end ()
  120.   started = 1
  121.   postpone (cron, false, 1.0)
  122. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement