Skip to content
This repository has been archived by the owner on Nov 16, 2024. It is now read-only.

Commit

Permalink
Bot API 5.3 updates
Browse files Browse the repository at this point in the history
  • Loading branch information
watzon committed Jun 29, 2021
1 parent 4e28616 commit eaeacba
Show file tree
Hide file tree
Showing 12 changed files with 129 additions and 15 deletions.
23 changes: 20 additions & 3 deletions src/tourmaline/client/core_methods.cr
Original file line number Diff line number Diff line change
Expand Up @@ -1224,19 +1224,36 @@ module Tourmaline
# Use this method to change the list of the bot's commands.
# Returns `true` on success.
def set_my_commands(
commands : Array(BotCommand | NamedTuple(command: String, description: String))
commands : Array(BotCommand | NamedTuple(command: String, description: String)),
scope : BotCommandScope? = nil,
language_code : String? = nil,
)
# commands = commands.map(&.to_h.transform_keys(&.to_s))

request(Bool, "setMyCommands", {
commands: commands,
scope: scope,
language_code: language_code,
})
end

# Use this method to get the current list of the bot's commands. Requires no parameters.
# Returns Array of BotCommand on success.
def get_my_commands
request(Array(BotCommand), "getMyCommands")
def get_my_commands(scope : BotCommandScope? = nil, language_code : String? = nil)
request(Array(BotCommand), "getMyCommands", {
scope: scope,
language_code: language_code,
})
end

# Use this method to delete the list of the bot's commands for the given scope and user language.
# After deletion, higher level commands will be shown to affected users.
# Returns True on success.
def delete_my_commands(scope : BotCommandScope? = nil, language_code : String? = nil)
request(Bool, "deleteMyCommands", {
scope: scope,
language_code: language_code,
})
end

##########################
Expand Down
8 changes: 6 additions & 2 deletions src/tourmaline/client/payment_methods.cr
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@ module Tourmaline
description,
payload,
provider_token,
start_parameter,
currency,
prices,
max_tip_amount = nil,
suggested_tip_amounts = nil,
start_parameter = nil,
provider_data = nil,
photo_url = nil,
photo_size = nil,
Expand All @@ -37,9 +39,11 @@ module Tourmaline
description: description,
payload: payload,
provider_token: provider_token,
start_parameter: start_parameter,
currency: currency,
prices: prices.to_json,
max_tip_amount: max_tip_amount,
suggested_tip_amounts: suggested_tip_amounts,
start_parameter: start_parameter,
provider_data: provider_data,
photo_url: photo_url,
photo_size: photo_size,
Expand Down
5 changes: 5 additions & 0 deletions src/tourmaline/models/bot_command_scope.cr
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module Tourmaline
alias BotCommandScope = BotCommandScopeDefault | BotCommandScopeAllPrivateChats | BotCommandScopeAllGroupChats |
BotCommandScopeAllChatAdministrators | BotCommandScopeChat | BotCommandScopeChatAdministrators |
BotCommandScopeChatMember
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module Tourmaline
class BotCommandScopeAllChatAdministrators
include JSON::Serializable
include Tourmaline::Model

getter type : String = "all_chat_administrators"
end
end
8 changes: 8 additions & 0 deletions src/tourmaline/models/bot_command_scope_all_group_chats.cr
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module Tourmaline
class BotCommandScopeAllGroupChats
include JSON::Serializable
include Tourmaline::Model

getter type : String = "all_group_chats"
end
end
8 changes: 8 additions & 0 deletions src/tourmaline/models/bot_command_scope_all_private_chats.cr
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module Tourmaline
class BotCommandScopeAllPrivateChats
include JSON::Serializable
include Tourmaline::Model

getter type : String = "all_private_chats"
end
end
16 changes: 16 additions & 0 deletions src/tourmaline/models/bot_command_scope_chat.cr
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
module Tourmaline
class BotCommandScopeChat
include JSON::Serializable
include Tourmaline::Model

getter type : String = "chat"

# Unique identifier for the target chat or username of the target supergroup
# (in the format `@supergroupusername`)
property chat_id : Int64 | String

def initialize(chat : Chat | Int64 | String)
@chat_id = chat.is_a?(Chat) ? chat.id : chat
end
end
end
16 changes: 16 additions & 0 deletions src/tourmaline/models/bot_command_scope_chat_administrators.cr
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
module Tourmaline
class BotCommandScopeChatAdministrators
include JSON::Serializable
include Tourmaline::Model

getter type : String = "chat_administrators"

# Unique identifier for the target chat or username of the target supergroup
# (in the format `@supergroupusername`)
property chat_id : Int64 | String

def initialize(chat : Chat | Int64 | String)
@chat_id = chat.is_a?(Chat) ? chat.id : chat
end
end
end
20 changes: 20 additions & 0 deletions src/tourmaline/models/bot_command_scope_chat_member.cr
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
module Tourmaline
class BotCommandScopeChatMember
include JSON::Serializable
include Tourmaline::Model

getter type : String = "chat_member"

# Unique identifier for the target chat or username of the target supergroup
# (in the format `@supergroupusername`)
property chat_id : Int64 | String

# Unique identifier of the target user
property user_id : Int64

def initialize(chat : Chat | Int64 | String, user : User | Int64)
@chat_id = chat.is_a?(Chat) ? chat.id : chat
@user_id = user.is_a?(User) ? user.id : user
end
end
end
8 changes: 8 additions & 0 deletions src/tourmaline/models/bot_command_scope_default.cr
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module Tourmaline
class BotCommandScopeDefault
include JSON::Serializable
include Tourmaline::Model

getter type : String = "default"
end
end
2 changes: 2 additions & 0 deletions src/tourmaline/models/force_reply.cr
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ module Tourmaline

getter force_reply : Bool = true

getter input_field_placeholder : String? = nil

getter selective : Bool

def initialize(@selective : Bool, @force_reply : Bool = true)
Expand Down
22 changes: 12 additions & 10 deletions src/tourmaline/models/reply_keyboard_markup.cr
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ module Tourmaline
include JSON::Serializable
include Tourmaline::Model

getter text : String
property text : String

getter request_contact : Bool = false
property request_contact : Bool = false

getter request_location : Bool = false
property request_location : Bool = false

getter request_poll : KeyboardButtonPollType?
property request_poll : KeyboardButtonPollType?

def initialize(@text : String, @request_contact = false, @request_location = false, @request_poll = nil)
end
Expand All @@ -27,7 +27,7 @@ module Tourmaline
include Tourmaline::Model

@[JSON::Field(converter: Tourmaline::Poll::PollTypeConverter)]
getter type : Poll::Type
property type : Poll::Type

def initialize(@type)
end
Expand All @@ -37,15 +37,17 @@ module Tourmaline
include JSON::Serializable
include Tourmaline::Model

getter keyboard : Array(Array(KeyboardButton))
property keyboard : Array(Array(KeyboardButton))

getter resize_keyboard : Bool = false
property resize_keyboard : Bool = false

getter one_time_keyboard : Bool = false
property one_time_keyboard : Bool = false

getter selective : Bool = false
property input_field_placeholder : String? = nil

def initialize(@keyboard = [] of Array(KeyboardButton), @resize_keyboard = false, @one_time_keyboard = false, @selective = false)
property selective : Bool = false

def initialize(@keyboard = [] of Array(KeyboardButton), @resize_keyboard = false, @one_time_keyboard = false, @input_field_placeholder = nil, @selective = false)
end

def <<(row : Int32, key : KeyboardButton)
Expand Down

0 comments on commit eaeacba

Please sign in to comment.