Guest User

Untitled

a guest
Dec 25th, 2016
78
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. -- Notification code {{{
  47.  
  48. function get_title (P, Q)
  49. if (Q.type == 'user') then
  50. return P.first_name .. " " .. P.last_name
  51. elseif (Q.type == 'chat') then
  52. return Q.title
  53. elseif (Q.type == 'encr_chat') then
  54. return 'Secret chat with ' .. P.first_name .. ' ' .. P.last_name
  55. else
  56. return ''
  57. end
  58. end
  59.  
  60. local lgi = require ('lgi')
  61. local notify = lgi.require('Notify')
  62. notify.init ("Telegram updates")
  63. local icon = os.getenv("HOME") .. "/.telegram-cli/telegram-pics/telegram_64.png"
  64.  
  65. function do_notify (user, msg)
  66. local n = notify.Notification.new(user, msg, icon)
  67. n:show ()
  68. end
  69.  
  70. -- }}}
  71.  
  72. function on_msg_receive (msg)
  73. if started == 0 then
  74. return
  75. end
  76. if msg.out then
  77. return
  78. end
  79.  
  80. -- Damit der "gelesen hacken" erscheint...
  81. if msg.text then
  82. mark_read (msg.from.print_name, ok_cb, false)
  83. end
  84.  
  85. -- ggf. nur eine Rufnummer zulassen...
  86. if msg.from.print_name ~= 'Kontakt_name' then
  87. os.execute("/home/pi/tg/send_script ".. msg.from.print_name .." 'Ungueltige Berechtigung...'")
  88. return
  89. end
  90. if (string.lower(msg.text) == 'uptime') then
  91. local handle = io.popen("sudo python /home/pi/tg/tg_steuerung.py uptime")
  92. local res = handle:read("*a")
  93. handle:close()
  94. os.execute("/home/pi/tg/send_script ".. msg.from.print_name .." '"..res.."' ")
  95. --Alternativ:
  96. --send_msg (msg.from.print_name, res)
  97. return
  98. elseif (string.lower(msg.text) == 'shutdown') then
  99. local handle = io.popen("sudo python /home/pi/tg/tg_steuerung.py shutdown")
  100. local res = handle:read("*a")
  101. os.execute("/home/pi/tg/send_script "..msg.from.print_name.." '"..res.."' ")
  102. handle:close()
  103. return
  104. elseif (string.lower(msg.text) == 'reboot') then
  105. local handle = io.popen("sudo python /home/pi/tg/tg_steuerung.py reboot")
  106. local res = handle:read("*a")
  107. handle:close()
  108. os.execute("/home/pi/tg/send_script ".. msg.from.print_name .." '"..res.."' ")
  109. return
  110. else
  111. os.execute("/home/pi/tg/send_script ".. msg.from.print_name .." 'Fehler' ")
  112. end
  113. end
  114.  
  115. do_notify (get_title (msg.from, msg.to), msg.text)
  116.  
  117.  
  118. if (msg.text == 'ping') then
  119. if (msg.to.id == our_id) then
  120. send_msg (msg.from.print_name, 'pong', ok_cb, false)
  121. else
  122. send_msg (msg.to.print_name, 'pong', ok_cb, false)
  123. end
  124. return
  125. end
  126. if (msg.text == 'PING') then
  127. if (msg.to.id == our_id) then
  128. fwd_msg (msg.from.print_name, msg.id, ok_cb, false)
  129. else
  130. fwd_msg (msg.to.print_name, msg.id, ok_cb, false)
  131. end
  132. return
  133. end
  134. end
  135.  
  136. function on_our_id (id)
  137. our_id = id
  138. end
  139.  
  140. function on_user_update (user, what)
  141. --vardump (user)
  142. end
  143.  
  144. function on_chat_update (chat, what)
  145. --vardump (chat)
  146. end
  147.  
  148. function on_secret_chat_update (schat, what)
  149. --vardump (schat)
  150. end
  151.  
  152. function on_get_difference_end ()
  153. end
  154.  
  155. function cron()
  156. -- do something
  157. postpone (cron, false, 1.0)
  158. end
  159.  
  160. function on_binlog_replay_end ()
  161. started = 1
  162. postpone (cron, false, 1.0)
  163. end
RAW Paste Data