mtproto 0.0.30 → 0.0.32

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 573ffb4ecced33cf4a62f7d2faab6ad88d9903246732dc521f3193c8bba3a0dd
4
- data.tar.gz: 68f6fb65b7121568e5a1ca7c46daf287430214de1204a7de718d4046d596d4de
3
+ metadata.gz: 6f20076eea4c2e79508740e13b6f8405437f47ce5ea04f7bffcb55eef0134026
4
+ data.tar.gz: 3e0ad205973f1f54e8ba60b1b97c4cac1c4a67ea5e59d2b7c797950f943953e0
5
5
  SHA512:
6
- metadata.gz: a9e3cd7660f5d50be09e4ec3e68f5d1d84c96e8cfb8a056036b1d41eb1dd4e23fdcc6fb7399d7ea922987f6a18de2be8496c8cabc94bfcd1f1ff020daa5578da
7
- data.tar.gz: e1fb03e7f7b214788fbc12fdfa859873b809f1483e5e2e008bc07d68e4d751c78b7b4c8a441489f178a809d109efc9ba8273b231ce4450eed2fde6daac85a531
6
+ metadata.gz: 815dbe344577826f6ef0e6d4fac25c0a56eb58f8372f5612c3c77c8f71b9b2684624f3152b3ba4c7f62046dcb239b1bff6ee95b0af98ab249f79a30928abb6cb
7
+ data.tar.gz: daaf36af66d6cff257881b8ebb3b19ab6c7b6c4bdaa8d7b9ef9f277a7da53539525039380714555948f80112fd46815985c324cbbd6c3075bef8738cf1ef8296
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../../tl/objects/export_bot_token'
4
+ require_relative '../../tl/objects/exported_bot_token'
5
+
6
+ module MTProto
7
+ class Client
8
+ class API
9
+ def export_bot_token(bot:, revoke: false)
10
+ rpc_call(TL::ExportBotToken.new(bot: bot, revoke: revoke), TL::ExportedBotToken).body.token
11
+ end
12
+ end
13
+ end
14
+ end
@@ -17,12 +17,13 @@ module MTProto
17
17
  # A `reply_to` (with optional `quote_text`/`quote_offset`) replies to a message,
18
18
  # optionally pinning the quoted fragment.
19
19
  def send_message(peer:, message: '', random_id: nil, reply_to: nil, entities: nil,
20
- parse_mode: nil, rich_markdown: nil, quote_text: nil, quote_offset: nil, no_webpage: false)
20
+ parse_mode: nil, rich_markdown: nil, quote_text: nil, quote_offset: nil, no_webpage: false,
21
+ reply_markup: nil)
21
22
  message, entities = Markdown.parse(message) if parse_mode && entities.nil? && rich_markdown.nil?
22
23
  rpc_call(
23
24
  TL::SendMessage.new(peer: peer, message: message, random_id: random_id, reply_to: reply_to,
24
25
  entities: entities, rich_markdown: rich_markdown, quote_text: quote_text, quote_offset: quote_offset,
25
- no_webpage: no_webpage),
26
+ no_webpage: no_webpage, reply_markup: reply_markup),
26
27
  TL::UpdateShortSentMessage
27
28
  ).body
28
29
  end
@@ -18,6 +18,7 @@ require_relative 'api/get_bot_callback_answer'
18
18
  require_relative 'api/send_message'
19
19
  require_relative 'api/set_typing'
20
20
  require_relative 'api/get_contacts'
21
+ require_relative 'api/export_bot_token'
21
22
  require_relative 'api/pin_message'
22
23
  require_relative 'api/unpin_all_messages'
23
24
  require_relative 'api/get_pinned_messages'
@@ -8,12 +8,12 @@ require_relative 'updates'
8
8
  module MTProto
9
9
  module TL
10
10
  class UpdatesDifference
11
- attr_reader :type, :date, :seq, :new_messages, :pts, :state, :chats, :users, :guest_queries
11
+ attr_reader :type, :date, :seq, :new_messages, :pts, :state, :chats, :users, :guest_queries, :managed_bots
12
12
 
13
13
  SCHEMA_PATH = File.expand_path('../../../../data/tl-schema.json', __dir__)
14
14
 
15
15
  def initialize(type:, date: nil, seq: nil, new_messages: [], pts: nil, state: nil, chats: [], users: [],
16
- guest_queries: [])
16
+ guest_queries: [], managed_bots: [])
17
17
  @type = type
18
18
  @date = date
19
19
  @seq = seq
@@ -23,6 +23,7 @@ module MTProto
23
23
  @chats = chats
24
24
  @users = users
25
25
  @guest_queries = guest_queries
26
+ @managed_bots = managed_bots
26
27
  end
27
28
 
28
29
  def self.schema
@@ -47,6 +48,7 @@ module MTProto
47
48
 
48
49
  UPDATE_NEW_MESSAGE = 0x1f2b0afd
49
50
  UPDATE_NEW_CHANNEL_MESSAGE = 0x62ba04d9
51
+ UPDATE_MANAGED_BOT = 0x4880ed9a
50
52
 
51
53
  class << self
52
54
  private
@@ -68,7 +70,7 @@ module MTProto
68
70
 
69
71
  messages, offset = parse_messages_vector(data, offset)
70
72
  offset = schema.skip_vector(data, offset) # new_encrypted_messages
71
- other_messages, guest_queries, offset = parse_other_updates(data, offset)
73
+ other_messages, guest_queries, managed_bots, offset = parse_other_updates(data, offset)
72
74
  chats, offset = Dialogs.chats_at(data, offset)
73
75
  users, offset = Dialogs.users_at(data, offset)
74
76
  state = UpdatesState.deserialize(data[offset..])
@@ -77,6 +79,7 @@ module MTProto
77
79
  type: constructor == Constructors::UPDATES_DIFFERENCE ? :difference : :slice,
78
80
  new_messages: messages + other_messages,
79
81
  guest_queries: guest_queries,
82
+ managed_bots: managed_bots,
80
83
  chats: chats, users: users, state: state
81
84
  )
82
85
  end
@@ -91,6 +94,7 @@ module MTProto
91
94
 
92
95
  messages = []
93
96
  guest_queries = []
97
+ managed_bots = []
94
98
  count.times do
95
99
  ctor = data[offset, 4].unpack1('L<')
96
100
  if [UPDATE_NEW_MESSAGE, UPDATE_NEW_CHANNEL_MESSAGE].include?(ctor)
@@ -99,10 +103,12 @@ module MTProto
99
103
  messages << msg.to_h if msg
100
104
  elsif ctor == Updates::UPDATE_BOT_GUEST_CHAT_QUERY
101
105
  guest_queries << Updates.extract_guest_query(data, offset)
106
+ elsif ctor == UPDATE_MANAGED_BOT
107
+ managed_bots << { user_id: data[offset + 4, 8].unpack1('Q<'), bot_id: data[offset + 12, 8].unpack1('Q<') }
102
108
  end
103
109
  offset = schema.skip(data, offset)
104
110
  end
105
- [messages, guest_queries, offset]
111
+ [messages, guest_queries, managed_bots, offset]
106
112
  end
107
113
 
108
114
  def parse_messages_vector(data, offset)
@@ -12,6 +12,7 @@ module MTProto
12
12
  # :delete deleted_ids
13
13
  # :callback query_id, user_id, data, msg_id
14
14
  # :guest_query query_id, message, qts
15
+ # :managed_bot user_id, bot_id
15
16
  # `pts`/`pts_count`/`channel` drive ordering and gap detection; they are nil for
16
17
  # updates outside the pts sequence (e.g. getDifference's common new_messages,
17
18
  # which the protocol delivers without a per-message pts). `users`/`chats` are the
@@ -21,7 +22,7 @@ module MTProto
21
22
  :kind, :channel, :pts, :pts_count,
22
23
  :peer_type, :peer_id, :msg_id,
23
24
  :message, :joined_user_id, :left_user_id, :deleted_ids, :reactors,
24
- :query_id, :user_id, :data, :qts,
25
+ :query_id, :user_id, :bot_id, :data, :qts,
25
26
  :users, :chats,
26
27
  keyword_init: true
27
28
  )
@@ -25,6 +25,7 @@ module MTProto
25
25
  UPDATE_BOT_CALLBACK_QUERY = 0xb9cfc48d
26
26
  UPDATE_CHANNEL_PARTICIPANT = 0x985d3abb
27
27
  UPDATE_BOT_GUEST_CHAT_QUERY = 0xcdd4093d
28
+ UPDATE_MANAGED_BOT = 0x4880ed9a
28
29
 
29
30
  MESSAGE_SERVICE = 0x7a800e0a
30
31
  ACTION_CHAT_ADD_USER = 0x15cefd00
@@ -61,9 +62,20 @@ module MTProto
61
62
  participant_event(data, offset)
62
63
  when UPDATE_BOT_GUEST_CHAT_QUERY
63
64
  guest_query_event(data, offset)
65
+ when UPDATE_MANAGED_BOT
66
+ managed_bot_event(data, offset)
64
67
  end
65
68
  end
66
69
 
70
+ # updateManagedBot#4880ed9a user_id:long bot_id:long — a bot the user just minted
71
+ # through this bot acting as its manager. Carries the owner (user_id) and the new
72
+ # bot (bot_id); the bot's access_hash rides in the batch users the parser attaches.
73
+ def managed_bot_event(data, offset)
74
+ Event.new(kind: :managed_bot,
75
+ user_id: data[offset + 4, 8].unpack1('Q<'),
76
+ bot_id: data[offset + 12, 8].unpack1('Q<'))
77
+ end
78
+
67
79
  # A Vector<Message> entry (a difference's new_messages) → a :message / :join /
68
80
  # :leave Event WITHOUT pts (the protocol omits per-message pts there), or nil.
69
81
  # `channel` is the envelope's kind (true for a channelDifference), since the
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module MTProto
4
- VERSION = '0.0.30'
4
+ VERSION = '0.0.32'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mtproto
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.30
4
+ version: 0.0.32
5
5
  platform: ruby
6
6
  authors:
7
7
  - Artem Levenkov
@@ -65,6 +65,7 @@ files:
65
65
  - lib/mtproto/client/api.rb
66
66
  - lib/mtproto/client/api/check_password.rb
67
67
  - lib/mtproto/client/api/export_authorization.rb
68
+ - lib/mtproto/client/api/export_bot_token.rb
68
69
  - lib/mtproto/client/api/export_login_token.rb
69
70
  - lib/mtproto/client/api/get_bot_callback_answer.rb
70
71
  - lib/mtproto/client/api/get_channel_difference.rb