Add some missing fields, generalize configs, remove unneeded methods.
This commit is contained in:
parent
1f859674f7
commit
4d758f17d4
5 changed files with 349 additions and 234 deletions
110
bot.go
110
bot.go
|
@ -329,11 +329,9 @@ func (bot *BotAPI) GetUserProfilePhotos(config UserProfilePhotosConfig) (UserPro
|
|||
//
|
||||
// Requires FileID.
|
||||
func (bot *BotAPI) GetFile(config FileConfig) (File, error) {
|
||||
params := make(Params)
|
||||
params, _ := config.params()
|
||||
|
||||
params["file_id"] = config.FileID
|
||||
|
||||
resp, err := bot.MakeRequest("getFile", params)
|
||||
resp, err := bot.MakeRequest(config.method(), params)
|
||||
if err != nil {
|
||||
return File{}, err
|
||||
}
|
||||
|
@ -437,12 +435,10 @@ func (bot *BotAPI) ListenForWebhook(pattern string) UpdatesChannel {
|
|||
}
|
||||
|
||||
// GetChat gets information about a chat.
|
||||
func (bot *BotAPI) GetChat(config ChatConfig) (Chat, error) {
|
||||
params := make(Params)
|
||||
func (bot *BotAPI) GetChat(config ChatInfoConfig) (Chat, error) {
|
||||
params, _ := config.params()
|
||||
|
||||
params.AddFirstValid("chat_id", config.ChatID, config.SuperGroupUsername)
|
||||
|
||||
resp, err := bot.MakeRequest("getChat", params)
|
||||
resp, err := bot.MakeRequest(config.method(), params)
|
||||
if err != nil {
|
||||
return Chat{}, err
|
||||
}
|
||||
|
@ -457,12 +453,10 @@ func (bot *BotAPI) GetChat(config ChatConfig) (Chat, error) {
|
|||
//
|
||||
// If none have been appointed, only the creator will be returned.
|
||||
// Bots are not shown, even if they are an administrator.
|
||||
func (bot *BotAPI) GetChatAdministrators(config ChatConfig) ([]ChatMember, error) {
|
||||
params := make(Params)
|
||||
func (bot *BotAPI) GetChatAdministrators(config ChatAdministratorsConfig) ([]ChatMember, error) {
|
||||
params, _ := config.params()
|
||||
|
||||
params.AddFirstValid("chat_id", config.ChatID, config.SuperGroupUsername)
|
||||
|
||||
resp, err := bot.MakeRequest("getChatAdministrators", params)
|
||||
resp, err := bot.MakeRequest(config.method(), params)
|
||||
if err != nil {
|
||||
return []ChatMember{}, err
|
||||
}
|
||||
|
@ -474,12 +468,10 @@ func (bot *BotAPI) GetChatAdministrators(config ChatConfig) ([]ChatMember, error
|
|||
}
|
||||
|
||||
// GetChatMembersCount gets the number of users in a chat.
|
||||
func (bot *BotAPI) GetChatMembersCount(config ChatConfig) (int, error) {
|
||||
params := make(Params)
|
||||
func (bot *BotAPI) GetChatMembersCount(config ChatMemberCountConfig) (int, error) {
|
||||
params, _ := config.params()
|
||||
|
||||
params.AddFirstValid("chat_id", config.ChatID, config.SuperGroupUsername)
|
||||
|
||||
resp, err := bot.MakeRequest("getChatMembersCount", params)
|
||||
resp, err := bot.MakeRequest(config.method(), params)
|
||||
if err != nil {
|
||||
return -1, err
|
||||
}
|
||||
|
@ -491,13 +483,10 @@ func (bot *BotAPI) GetChatMembersCount(config ChatConfig) (int, error) {
|
|||
}
|
||||
|
||||
// GetChatMember gets a specific chat member.
|
||||
func (bot *BotAPI) GetChatMember(config ChatConfigWithUser) (ChatMember, error) {
|
||||
params := make(Params)
|
||||
func (bot *BotAPI) GetChatMember(config GetChatMemberConfig) (ChatMember, error) {
|
||||
params, _ := config.params()
|
||||
|
||||
params.AddFirstValid("chat_id", config.ChatID, config.SuperGroupUsername)
|
||||
params.AddNonZero("user_id", config.UserID)
|
||||
|
||||
resp, err := bot.MakeRequest("getChatMember", params)
|
||||
resp, err := bot.MakeRequest(config.method(), params)
|
||||
if err != nil {
|
||||
return ChatMember{}, err
|
||||
}
|
||||
|
@ -508,63 +497,11 @@ func (bot *BotAPI) GetChatMember(config ChatConfigWithUser) (ChatMember, error)
|
|||
return member, err
|
||||
}
|
||||
|
||||
// UnbanChatMember unbans a user from a chat. Note that this only will work
|
||||
// in supergroups and channels, and requires the bot to be an admin.
|
||||
func (bot *BotAPI) UnbanChatMember(config ChatMemberConfig) (APIResponse, error) {
|
||||
params := make(Params)
|
||||
|
||||
params.AddFirstValid("chat_id", config.ChatID, config.SuperGroupUsername, config.ChannelUsername)
|
||||
params.AddNonZero("user_id", config.UserID)
|
||||
|
||||
return bot.MakeRequest("unbanChatMember", params)
|
||||
}
|
||||
|
||||
// RestrictChatMember to restrict a user in a supergroup. The bot must be an
|
||||
//administrator in the supergroup for this to work and must have the
|
||||
//appropriate admin rights. Pass True for all boolean parameters to lift
|
||||
//restrictions from a user. Returns True on success.
|
||||
func (bot *BotAPI) RestrictChatMember(config RestrictChatMemberConfig) (APIResponse, error) {
|
||||
params := make(Params)
|
||||
|
||||
params.AddFirstValid("chat_id", config.ChatID, config.SuperGroupUsername, config.ChannelUsername)
|
||||
params.AddNonZero("user_id", config.UserID)
|
||||
|
||||
params.AddNonNilBool("can_send_messages", config.CanSendMessages)
|
||||
params.AddNonNilBool("can_send_media_messages", config.CanSendMediaMessages)
|
||||
params.AddNonNilBool("can_send_other_messages", config.CanSendOtherMessages)
|
||||
params.AddNonNilBool("can_add_web_page_previews", config.CanAddWebPagePreviews)
|
||||
params.AddNonZero64("until_date", config.UntilDate)
|
||||
|
||||
return bot.MakeRequest("restrictChatMember", params)
|
||||
}
|
||||
|
||||
// PromoteChatMember add admin rights to user
|
||||
func (bot *BotAPI) PromoteChatMember(config PromoteChatMemberConfig) (APIResponse, error) {
|
||||
params := make(Params)
|
||||
|
||||
params.AddFirstValid("chat_id", config.ChatID, config.SuperGroupUsername, config.ChannelUsername)
|
||||
params.AddNonZero("user_id", config.UserID)
|
||||
|
||||
params.AddNonNilBool("can_change_info", config.CanChangeInfo)
|
||||
params.AddNonNilBool("can_post_messages", config.CanPostMessages)
|
||||
params.AddNonNilBool("can_edit_messages", config.CanEditMessages)
|
||||
params.AddNonNilBool("can_delete_messages", config.CanDeleteMessages)
|
||||
params.AddNonNilBool("can_invite_members", config.CanInviteUsers)
|
||||
params.AddNonNilBool("can_restrict_members", config.CanRestrictMembers)
|
||||
params.AddNonNilBool("can_pin_messages", config.CanPinMessages)
|
||||
params.AddNonNilBool("can_promote_members", config.CanPromoteMembers)
|
||||
|
||||
return bot.MakeRequest("promoteChatMember", params)
|
||||
}
|
||||
|
||||
// GetGameHighScores allows you to get the high scores for a game.
|
||||
func (bot *BotAPI) GetGameHighScores(config GetGameHighScoresConfig) ([]GameHighScore, error) {
|
||||
v, err := config.params()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
params, _ := config.params()
|
||||
|
||||
resp, err := bot.MakeRequest(config.method(), v)
|
||||
resp, err := bot.MakeRequest(config.method(), params)
|
||||
if err != nil {
|
||||
return []GameHighScore{}, err
|
||||
}
|
||||
|
@ -576,12 +513,10 @@ func (bot *BotAPI) GetGameHighScores(config GetGameHighScoresConfig) ([]GameHigh
|
|||
}
|
||||
|
||||
// GetInviteLink get InviteLink for a chat
|
||||
func (bot *BotAPI) GetInviteLink(config ChatConfig) (string, error) {
|
||||
params := make(Params)
|
||||
func (bot *BotAPI) GetInviteLink(config ChatInviteLinkConfig) (string, error) {
|
||||
params, _ := config.params()
|
||||
|
||||
params.AddFirstValid("chat_id", config.ChatID, config.SuperGroupUsername)
|
||||
|
||||
resp, err := bot.MakeRequest("exportChatInviteLink", params)
|
||||
resp, err := bot.MakeRequest(config.method(), params)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
@ -594,12 +529,9 @@ func (bot *BotAPI) GetInviteLink(config ChatConfig) (string, error) {
|
|||
|
||||
// GetStickerSet returns a StickerSet.
|
||||
func (bot *BotAPI) GetStickerSet(config GetStickerSetConfig) (StickerSet, error) {
|
||||
v, err := config.params()
|
||||
if err != nil {
|
||||
return StickerSet{}, nil
|
||||
}
|
||||
params, _ := config.params()
|
||||
|
||||
resp, err := bot.MakeRequest(config.method(), v)
|
||||
resp, err := bot.MakeRequest(config.method(), params)
|
||||
if err != nil {
|
||||
return StickerSet{}, nil
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue