Fix naming

pull/452/head
zry98 2 years ago
parent 6cc14872e4
commit a596da19f7
No known key found for this signature in database
GPG Key ID: D239A8A2222B2691

@ -1442,7 +1442,7 @@ func (b *Bot) ChatMemberOf(chat, user Recipient) (*ChatMember, error) {
// Commands returns the current list of the bot's commands for the given scope and user language.
func (b *Bot) Commands(opts ...interface{}) ([]Command, error) {
params := extractBotCommandsParams(opts...)
params := extractCommandsParams(opts...)
data, err := b.Raw("getMyCommands", params)
if err != nil {
return nil, err
@ -1459,14 +1459,14 @@ func (b *Bot) Commands(opts ...interface{}) ([]Command, error) {
// SetCommands changes the list of the bot's commands.
func (b *Bot) SetCommands(opts ...interface{}) error {
params := extractBotCommandsParams(opts...)
params := extractCommandsParams(opts...)
_, err := b.Raw("setMyCommands", params)
return err
}
// DeleteCommands deletes the list of the bot's commands for the given scope and user language.
func (b *Bot) DeleteCommands(opts ...interface{}) ([]Command, error) {
params := extractBotCommandsParams(opts...)
params := extractCommandsParams(opts...)
data, err := b.Raw("deleteMyCommands", params)
if err != nil {
return nil, err

@ -587,13 +587,13 @@ func TestBot(t *testing.T) {
Text: "test_2",
Description: "test command 2",
}}
require.NoError(t, b.SetCommands(orig2, BotCommandScope{Type: BotCommandScopeChat, ChatID: chatID}, "en"))
require.NoError(t, b.SetCommands(orig2, CommandScope{Type: CommandScopeChat, ChatID: chatID}, "en"))
cmds, err = b.Commands()
require.NoError(t, err)
assert.Equal(t, orig, cmds)
cmds, err = b.Commands(BotCommandScope{Type: BotCommandScopeChat, ChatID: chatID}, "en")
cmds, err = b.Commands(CommandScope{Type: CommandScopeChat, ChatID: chatID}, "en")
require.NoError(t, err)
assert.Equal(t, orig2, cmds)
})

@ -320,27 +320,27 @@ func (b Btn) Reply() *ReplyButton {
}
}
// BotCommandParams controls parameters for commands-related methods (setMyCommands, deleteMyCommands and getMyCommands).
type BotCommandParams struct {
Commands []Command `json:"commands,omitempty"`
Scope *BotCommandScope `json:"scope,omitempty"`
LanguageCode string `json:"language_code,omitempty"`
// CommandParams controls parameters for commands-related methods (setMyCommands, deleteMyCommands and getMyCommands).
type CommandParams struct {
Commands []Command `json:"commands,omitempty"`
Scope *CommandScope `json:"scope,omitempty"`
LanguageCode string `json:"language_code,omitempty"`
}
// BotCommandScope object represents a scope to which bot commands are applied.
type BotCommandScope struct {
// CommandScope object represents a scope to which bot commands are applied.
type CommandScope struct {
Type string `json:"type"`
ChatID int64 `json:"chat_id,omitempty"`
UserID int64 `json:"user_id,omitempty"`
}
// CommandScope types
const (
// BotCommandScope types
BotCommandScopeDefault = "default"
BotCommandScopeAllPrivateChats = "all_private_chats"
BotCommandScopeAllGroupChats = "all_group_chats"
BotCommandScopeAllChatAdministrators = "all_chat_administrators"
BotCommandScopeChat = "chat"
BotCommandScopeChatAdministrators = "chat_administrators"
BotScopeChatMember = "chat_member"
CommandScopeDefault = "default"
CommandScopeAllPrivateChats = "all_private_chats"
CommandScopeAllGroupChats = "all_group_chats"
CommandScopeAllChatAdmin = "all_chat_administrators"
CommandScopeChat = "chat"
CommandScopeChatAdmin = "chat_administrators"
CommandScopeChatMember = "chat_member"
)

@ -273,15 +273,15 @@ func intsToStrs(ns []int) (s []string) {
return
}
// extractBotCommandsParams extracts parameters for commands-related methods from the given options.
func extractBotCommandsParams(opts ...interface{}) (params BotCommandParams) {
// extractCommandsParams extracts parameters for commands-related methods from the given options.
func extractCommandsParams(opts ...interface{}) (params CommandParams) {
for _, opt := range opts {
switch value := opt.(type) {
case []Command:
params.Commands = value
case string:
params.LanguageCode = value
case BotCommandScope:
case CommandScope:
params.Scope = &value
}
}

Loading…
Cancel
Save