Module: MTProto::TL::BotCommandScope
- Extended by:
- Binary
- Defined in:
- lib/mtproto/tl/objects/bot_command_scope.rb
Overview
Serializes a BotCommandScope — the ‘scope:` field shared by bots.setBotCommands / bots.resetBotCommands / bots.getBotCommands.
scope is a hash:
{ type: :default }
{ type: :users }
{ type: :chats }
{ type: :chat_admins }
{ type: :peer, peer: <input_peer> }
{ type: :peer_admins, peer: <input_peer> }
{ type: :peer_user, peer: <input_peer>, user: <input_user> }
input_peer is the same shape used elsewhere (e.g. SendMessage):
{ type: :self | :user | :chat | :channel, id:, access_hash: }
input_user:
{ type: :self } or { id:, access_hash: }
Constant Summary collapse
- DEFAULT =
0x2f6cb2ab- USERS =
0x3c4f04d8- CHATS =
0x6fe1a881- CHAT_ADMINS =
0xb9aa606a- PEER =
0xdb9d897d- PEER_ADMINS =
0x3fd863d1- PEER_USER =
0x0a1321f3- INPUT_USER =
0xf21158c6- INPUT_USER_SELF =
0xf7c1b13f
Class Method Summary collapse
- .serialize(scope) ⇒ Object
- .serialize_input_peer(peer) ⇒ Object
- .serialize_input_user(user) ⇒ Object
Methods included from Binary
Class Method Details
.serialize(scope) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/mtproto/tl/objects/bot_command_scope.rb', line 37 def serialize(scope) scope ||= { type: :default } case scope[:type] when :default then u32_b(DEFAULT) when :users then u32_b(USERS) when :chats then u32_b(CHATS) when :chat_admins then u32_b(CHAT_ADMINS) when :peer then u32_b(PEER) + serialize_input_peer(scope[:peer]) when :peer_admins then u32_b(PEER_ADMINS) + serialize_input_peer(scope[:peer]) when :peer_user u32_b(PEER_USER) + serialize_input_peer(scope[:peer]) + serialize_input_user(scope[:user]) else raise ArgumentError, "Unknown bot command scope: #{scope[:type].inspect}" end end |
.serialize_input_peer(peer) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/mtproto/tl/objects/bot_command_scope.rb', line 53 def serialize_input_peer(peer) raise ArgumentError, 'scope requires peer:' if peer.nil? case peer[:type] when :self u32_b(Constructors::INPUT_PEER_SELF) when :user u32_b(Constructors::INPUT_PEER_USER) + u64_b(peer[:id]) + u64_b(peer[:access_hash] || 0) when :chat u32_b(Constructors::INPUT_PEER_CHAT) + u64_b(peer[:id]) when :channel u32_b(Constructors::INPUT_PEER_CHANNEL) + u64_b(peer[:id]) + u64_b(peer[:access_hash] || 0) else raise ArgumentError, "Unknown peer type: #{peer[:type].inspect}" end end |
.serialize_input_user(user) ⇒ Object
70 71 72 73 74 75 76 77 78 |
# File 'lib/mtproto/tl/objects/bot_command_scope.rb', line 70 def serialize_input_user(user) raise ArgumentError, 'peer_user scope requires user:' if user.nil? if user[:type] == :self u32_b(INPUT_USER_SELF) else u32_b(INPUT_USER) + u64_b(user[:id]) + u64_b(user[:access_hash] || 0) end end |