Advertisement
psycholyzern

Untitled

Nov 12th, 2016
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.30 KB | None | 0 0
  1.  
  2. function vardump(value, depth, key)
  3. local linePrefix = ""
  4. local spaces = ""
  5.  
  6. if key ~= nil then
  7. linePrefix = "["..key.."] = "
  8. end
  9.  
  10. if depth == nil then
  11. depth = 0
  12. else
  13. depth = depth + 1
  14. for i=1, depth do spaces = spaces .. " " end
  15. end
  16.  
  17. if type(value) == 'table' then
  18. mTable = getmetatable(value)
  19. if mTable == nil then
  20. print(spaces ..linePrefix.."(table) ")
  21. else
  22. print(spaces .."(metatable) ")
  23. value = mTable
  24. end
  25. for tableKey, tableValue in pairs(value) do
  26. vardump(tableValue, depth, tableKey)
  27. end
  28. elseif type(value) == 'function' or
  29. type(value) == 'thread' or
  30. type(value) == 'userdata' or
  31. value == nil
  32. then
  33. print(spaces..tostring(value))
  34. else
  35. print(spaces..linePrefix.."("..type(value)..") "..tostring(value))
  36. end
  37. end
  38.  
  39.  
  40. local lgi = require ('lgi')
  41. local notify = lgi.require('Notify')
  42. notify.init ("Telegram updates")
  43.  
  44. chats = {}
  45.  
  46. function do_notify (user, msg)
  47. --local n = notify.Notification.new("message", "<span font=\"Inconsolata 40\">" .. user .. "<br>".. msg .. "</span>")
  48. local n = notify.Notification.new(user, msg)
  49. n:show ()
  50. end
  51.  
  52. function dl_cb (arg, data)
  53. end
  54.  
  55. function tdcli_update_callback (data)
  56. if (data.ID == "UpdateNewMessage") then
  57. local msg = data.message_
  58. local d = data.disable_notification_
  59. local chat = chats[msg.chat_id_]
  60.  
  61. if ((not d) and chat) then
  62. if msg.content_.ID == "MessageText" then
  63. do_notify (chat.title_, msg.content_.text_)
  64. else
  65. do_notify (chat.title_, msg.content_.ID)
  66. end
  67. end
  68. if msg.content_.ID == "MessageText" and msg.content_.text_ == "ping" then
  69. tdcli_function ({ID="SendMessage", chat_id_=msg.chat_id_, reply_to_message_id_=msg.id_, disable_notification_=0, from_background_=1, reply_markup_=nil, input_message_content_={ID="InputMessageText", text_="pong", disable_web_page_preview_=1, clear_draft_=0, entities_={}}}, dl_cb, nil)
  70. end
  71. elseif (data.ID == "UpdateChat") then
  72. chat = data.chat_
  73. chats[chat.id_] = chat
  74. elseif (data.ID == "UpdateOption" and data.name_ == "my_id") then
  75. tdcli_function ({ID="GetChats", offset_order_="9223372036854775807", offset_chat_id_=0, limit_=20}, dl_cb, nil)
  76. end
  77. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement