Advertisement
Guest User

Untitled

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