Skip to content

Commit 4d758f1

Browse files
committed
Add some missing fields, generalize configs, remove unneeded methods.
1 parent 1f85967 commit 4d758f1

File tree

5 files changed

+350
-235
lines changed

5 files changed

+350
-235
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ func main() {
6363
```
6464

6565
There are more examples on the [wiki](https://github.com/go-telegram-bot-api/telegram-bot-api/wiki)
66-
with detailed information on how to do many differen kinds of things.
66+
with detailed information on how to do many different kinds of things.
6767
It's a great place to get started on using keyboards, commands, or other
6868
kinds of reply markup.
6969

bot.go

Lines changed: 21 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -329,11 +329,9 @@ func (bot *BotAPI) GetUserProfilePhotos(config UserProfilePhotosConfig) (UserPro
329329
//
330330
// Requires FileID.
331331
func (bot *BotAPI) GetFile(config FileConfig) (File, error) {
332-
params := make(Params)
333-
334-
params["file_id"] = config.FileID
332+
params, _ := config.params()
335333

336-
resp, err := bot.MakeRequest("getFile", params)
334+
resp, err := bot.MakeRequest(config.method(), params)
337335
if err != nil {
338336
return File{}, err
339337
}
@@ -437,12 +435,10 @@ func (bot *BotAPI) ListenForWebhook(pattern string) UpdatesChannel {
437435
}
438436

439437
// GetChat gets information about a chat.
440-
func (bot *BotAPI) GetChat(config ChatConfig) (Chat, error) {
441-
params := make(Params)
442-
443-
params.AddFirstValid("chat_id", config.ChatID, config.SuperGroupUsername)
438+
func (bot *BotAPI) GetChat(config ChatInfoConfig) (Chat, error) {
439+
params, _ := config.params()
444440

445-
resp, err := bot.MakeRequest("getChat", params)
441+
resp, err := bot.MakeRequest(config.method(), params)
446442
if err != nil {
447443
return Chat{}, err
448444
}
@@ -457,12 +453,10 @@ func (bot *BotAPI) GetChat(config ChatConfig) (Chat, error) {
457453
//
458454
// If none have been appointed, only the creator will be returned.
459455
// Bots are not shown, even if they are an administrator.
460-
func (bot *BotAPI) GetChatAdministrators(config ChatConfig) ([]ChatMember, error) {
461-
params := make(Params)
462-
463-
params.AddFirstValid("chat_id", config.ChatID, config.SuperGroupUsername)
456+
func (bot *BotAPI) GetChatAdministrators(config ChatAdministratorsConfig) ([]ChatMember, error) {
457+
params, _ := config.params()
464458

465-
resp, err := bot.MakeRequest("getChatAdministrators", params)
459+
resp, err := bot.MakeRequest(config.method(), params)
466460
if err != nil {
467461
return []ChatMember{}, err
468462
}
@@ -474,12 +468,10 @@ func (bot *BotAPI) GetChatAdministrators(config ChatConfig) ([]ChatMember, error
474468
}
475469

476470
// GetChatMembersCount gets the number of users in a chat.
477-
func (bot *BotAPI) GetChatMembersCount(config ChatConfig) (int, error) {
478-
params := make(Params)
479-
480-
params.AddFirstValid("chat_id", config.ChatID, config.SuperGroupUsername)
471+
func (bot *BotAPI) GetChatMembersCount(config ChatMemberCountConfig) (int, error) {
472+
params, _ := config.params()
481473

482-
resp, err := bot.MakeRequest("getChatMembersCount", params)
474+
resp, err := bot.MakeRequest(config.method(), params)
483475
if err != nil {
484476
return -1, err
485477
}
@@ -491,13 +483,10 @@ func (bot *BotAPI) GetChatMembersCount(config ChatConfig) (int, error) {
491483
}
492484

493485
// GetChatMember gets a specific chat member.
494-
func (bot *BotAPI) GetChatMember(config ChatConfigWithUser) (ChatMember, error) {
495-
params := make(Params)
496-
497-
params.AddFirstValid("chat_id", config.ChatID, config.SuperGroupUsername)
498-
params.AddNonZero("user_id", config.UserID)
486+
func (bot *BotAPI) GetChatMember(config GetChatMemberConfig) (ChatMember, error) {
487+
params, _ := config.params()
499488

500-
resp, err := bot.MakeRequest("getChatMember", params)
489+
resp, err := bot.MakeRequest(config.method(), params)
501490
if err != nil {
502491
return ChatMember{}, err
503492
}
@@ -508,63 +497,11 @@ func (bot *BotAPI) GetChatMember(config ChatConfigWithUser) (ChatMember, error)
508497
return member, err
509498
}
510499

511-
// UnbanChatMember unbans a user from a chat. Note that this only will work
512-
// in supergroups and channels, and requires the bot to be an admin.
513-
func (bot *BotAPI) UnbanChatMember(config ChatMemberConfig) (APIResponse, error) {
514-
params := make(Params)
515-
516-
params.AddFirstValid("chat_id", config.ChatID, config.SuperGroupUsername, config.ChannelUsername)
517-
params.AddNonZero("user_id", config.UserID)
518-
519-
return bot.MakeRequest("unbanChatMember", params)
520-
}
521-
522-
// RestrictChatMember to restrict a user in a supergroup. The bot must be an
523-
//administrator in the supergroup for this to work and must have the
524-
//appropriate admin rights. Pass True for all boolean parameters to lift
525-
//restrictions from a user. Returns True on success.
526-
func (bot *BotAPI) RestrictChatMember(config RestrictChatMemberConfig) (APIResponse, error) {
527-
params := make(Params)
528-
529-
params.AddFirstValid("chat_id", config.ChatID, config.SuperGroupUsername, config.ChannelUsername)
530-
params.AddNonZero("user_id", config.UserID)
531-
532-
params.AddNonNilBool("can_send_messages", config.CanSendMessages)
533-
params.AddNonNilBool("can_send_media_messages", config.CanSendMediaMessages)
534-
params.AddNonNilBool("can_send_other_messages", config.CanSendOtherMessages)
535-
params.AddNonNilBool("can_add_web_page_previews", config.CanAddWebPagePreviews)
536-
params.AddNonZero64("until_date", config.UntilDate)
537-
538-
return bot.MakeRequest("restrictChatMember", params)
539-
}
540-
541-
// PromoteChatMember add admin rights to user
542-
func (bot *BotAPI) PromoteChatMember(config PromoteChatMemberConfig) (APIResponse, error) {
543-
params := make(Params)
544-
545-
params.AddFirstValid("chat_id", config.ChatID, config.SuperGroupUsername, config.ChannelUsername)
546-
params.AddNonZero("user_id", config.UserID)
547-
548-
params.AddNonNilBool("can_change_info", config.CanChangeInfo)
549-
params.AddNonNilBool("can_post_messages", config.CanPostMessages)
550-
params.AddNonNilBool("can_edit_messages", config.CanEditMessages)
551-
params.AddNonNilBool("can_delete_messages", config.CanDeleteMessages)
552-
params.AddNonNilBool("can_invite_members", config.CanInviteUsers)
553-
params.AddNonNilBool("can_restrict_members", config.CanRestrictMembers)
554-
params.AddNonNilBool("can_pin_messages", config.CanPinMessages)
555-
params.AddNonNilBool("can_promote_members", config.CanPromoteMembers)
556-
557-
return bot.MakeRequest("promoteChatMember", params)
558-
}
559-
560500
// GetGameHighScores allows you to get the high scores for a game.
561501
func (bot *BotAPI) GetGameHighScores(config GetGameHighScoresConfig) ([]GameHighScore, error) {
562-
v, err := config.params()
563-
if err != nil {
564-
return nil, err
565-
}
502+
params, _ := config.params()
566503

567-
resp, err := bot.MakeRequest(config.method(), v)
504+
resp, err := bot.MakeRequest(config.method(), params)
568505
if err != nil {
569506
return []GameHighScore{}, err
570507
}
@@ -576,12 +513,10 @@ func (bot *BotAPI) GetGameHighScores(config GetGameHighScoresConfig) ([]GameHigh
576513
}
577514

578515
// GetInviteLink get InviteLink for a chat
579-
func (bot *BotAPI) GetInviteLink(config ChatConfig) (string, error) {
580-
params := make(Params)
581-
582-
params.AddFirstValid("chat_id", config.ChatID, config.SuperGroupUsername)
516+
func (bot *BotAPI) GetInviteLink(config ChatInviteLinkConfig) (string, error) {
517+
params, _ := config.params()
583518

584-
resp, err := bot.MakeRequest("exportChatInviteLink", params)
519+
resp, err := bot.MakeRequest(config.method(), params)
585520
if err != nil {
586521
return "", err
587522
}
@@ -594,12 +529,9 @@ func (bot *BotAPI) GetInviteLink(config ChatConfig) (string, error) {
594529

595530
// GetStickerSet returns a StickerSet.
596531
func (bot *BotAPI) GetStickerSet(config GetStickerSetConfig) (StickerSet, error) {
597-
v, err := config.params()
598-
if err != nil {
599-
return StickerSet{}, nil
600-
}
532+
params, _ := config.params()
601533

602-
resp, err := bot.MakeRequest(config.method(), v)
534+
resp, err := bot.MakeRequest(config.method(), params)
603535
if err != nil {
604536
return StickerSet{}, nil
605537
}

0 commit comments

Comments
 (0)