Guest User

test.lua

a guest
Jan 30th, 2016
161
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. --Damit der "Gelesen Haken" erscheint
  80. if msg.text then
  81. mark_read (msg.from.print_name, ok_cb, false)
  82. end
  83.  
  84. --Ggf. nur eine Rufnummer zulassen:
  85. if msg.from.print_name ~= 'Jonas Lieske' then
  86. os.execute("/home/pi/tg/send_script ".. msg.from.print_name .." 'Ung├╝ltige Nr.'")
  87. return
  88. end
  89. if (string.lower(msg.text) == 'uptime') then
  90. local handle = io.popen("sudo python /home/pi/tg/tg_actions.py uptime")
  91. local res = handle:read("*a")
  92. handle:close()
  93. os.execute("/home/pi/tg/send_script ".. msg.from.print_name .." '"..res.."' ")
  94. --Alternativ:
  95. --send_msg (msg.from.print_name, res)
  96. return
  97. elseif (string.lower(msg.text) == 'shutdown') then
  98. local handle = io.popen("sudo python /home/pi/tg/tg_actions.py shutdown")
  99. local res = handle:read("*a")
  100. os.execute("/home/pi/tg/send_script "..msg.from.print_name.." '"..res.."' ")
  101. handle:close()
  102. return
  103. elseif (string.lower(msg.text) == 'reboot') then
  104. local handle = io.popen("sudo python /home/pi/tg/tg_actions.py reboot")
  105. local res = handle:read("*a")
  106. handle:close()
  107. os.execute("/home/pi/tg/send_script ".. msg.from.print_name .." '"..res.."' ")
  108. return
  109. else
  110. os.execute("/home/pi/tg/send_script ".. msg.from.print_name .." 'Fehler' ")
  111. end
  112.  
  113. end
  114. end
  115.  
  116. function on_our_id (id)
  117. our_id = id
  118. end
  119.  
  120. function on_user_update (user, what)
  121. --vardump (user)
  122. end
  123.  
  124. function on_chat_update (chat, what)
  125. --vardump (chat)
  126. end
  127.  
  128. function on_secret_chat_update (schat, what)
  129. --vardump (schat)
  130. end
  131.  
  132. function on_get_difference_end ()
  133. end
  134.  
  135. function cron()
  136. -- do something
  137. postpone (cron, false, 1.0)
  138. end
  139.  
  140. function on_binlog_replay_end ()
  141. started = 1
  142. postpone (cron, false, 1.0)
  143. end
RAW Paste Data