Guest User

Untitled

a guest
Mar 21st, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. require 'socket'
  2.  
  3. class Scratch
  4.  
  5. attr_reader :socket_json,
  6. :socket_plain
  7.  
  8. def initialize
  9. @socket_json = UNIXSocket.open('/home/dev/users/taras/stuff/tg/telega_cli_json')
  10. @socket_plain = UNIXSocket.open('/home/dev/users/taras/stuff/tg/telega_cli_plain')
  11. end
  12.  
  13.  
  14. def execute(cid)
  15. txt_channel_info = 'channel_info %s' % cid
  16. txt_channel_get_admins = 'channel_get_admins %' % cid
  17.  
  18. puts '# запрашиваем данные об админах'
  19. socket_json.puts(txt_channel_get_admins)
  20. _print_socket_response(socket_json)
  21. # {"result": "FAIL", "error_code": 71, "error": "RPC_CALL_FAIL 400: CHAT_ADMIN_REQUIRED"}
  22.  
  23. puts '# узнаём описание канала'
  24. socket_plain.puts(txt_channel_info)
  25. _print_socket_response(socket_plain)
  26.  
  27. puts '# узнаём другие метрики канала'
  28. socket_json.puts(txt_channel_info)
  29. _print_socket_response(socket_json)
  30.  
  31. socket_json.close
  32. socket_plain.close
  33. end
  34.  
  35. private
  36.  
  37. def _print_socket_response(socket)
  38. socket.each_char do |c|
  39. break if c == '>'
  40. print c
  41. end
  42. end
  43.  
  44. end
  45.  
  46. Scratch.new.execute('$05000000d042d440c1c2011001869c33')
Add Comment
Please, Sign In to add comment