commit
ebe7b8254e
82
bot.go
82
bot.go
|
@ -547,7 +547,7 @@ func (bot *BotAPI) AnswerCallbackQuery(config CallbackConfig) (APIResponse, erro
|
|||
// KickChatMember kicks a user from a chat. Note that this only will work
|
||||
// in supergroups, and requires the bot to be an admin. Also note they
|
||||
// will be unable to rejoin until they are unbanned.
|
||||
func (bot *BotAPI) KickChatMember(config ChatMemberConfig) (APIResponse, error) {
|
||||
func (bot *BotAPI) KickChatMember(config KickChatMemberConfig) (APIResponse, error) {
|
||||
v := url.Values{}
|
||||
|
||||
if config.SuperGroupUsername == "" {
|
||||
|
@ -557,6 +557,10 @@ func (bot *BotAPI) KickChatMember(config ChatMemberConfig) (APIResponse, error)
|
|||
}
|
||||
v.Add("user_id", strconv.Itoa(config.UserID))
|
||||
|
||||
if config.UntilDate != 0 {
|
||||
v.Add("until_date", strconv.FormatInt(config.UntilDate, 10))
|
||||
}
|
||||
|
||||
bot.debugLog("kickChatMember", v, nil)
|
||||
|
||||
return bot.MakeRequest("kickChatMember", v)
|
||||
|
@ -692,6 +696,82 @@ func (bot *BotAPI) UnbanChatMember(config ChatMemberConfig) (APIResponse, error)
|
|||
return bot.MakeRequest("unbanChatMember", v)
|
||||
}
|
||||
|
||||
// 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) {
|
||||
v := url.Values{}
|
||||
|
||||
if config.SuperGroupUsername != "" {
|
||||
v.Add("chat_id", config.SuperGroupUsername)
|
||||
} else if config.ChannelUsername != "" {
|
||||
v.Add("chat_id", config.ChannelUsername)
|
||||
} else {
|
||||
v.Add("chat_id", strconv.FormatInt(config.ChatID, 10))
|
||||
}
|
||||
v.Add("user_id", strconv.Itoa(config.UserID))
|
||||
|
||||
if &config.CanSendMessages != nil {
|
||||
v.Add("can_send_messages", strconv.FormatBool(*config.CanSendMessages))
|
||||
}
|
||||
if &config.CanSendMediaMessages != nil {
|
||||
v.Add("can_send_media_messages", strconv.FormatBool(*config.CanSendMediaMessages))
|
||||
}
|
||||
if &config.CanSendOtherMessages != nil {
|
||||
v.Add("can_send_other_messages", strconv.FormatBool(*config.CanSendOtherMessages))
|
||||
}
|
||||
if &config.CanAddWebPagePreviews != nil {
|
||||
v.Add("can_add_web_page_previews", strconv.FormatBool(*config.CanAddWebPagePreviews))
|
||||
}
|
||||
|
||||
bot.debugLog("restrictChatMember", v, nil)
|
||||
|
||||
return bot.MakeRequest("restrictChatMember", v)
|
||||
}
|
||||
|
||||
func (bot *BotAPI) PromoteChatMember(config PromoteChatMemberConfig) (APIResponse, error) {
|
||||
v := url.Values{}
|
||||
|
||||
if config.SuperGroupUsername != "" {
|
||||
v.Add("chat_id", config.SuperGroupUsername)
|
||||
} else if config.ChannelUsername != "" {
|
||||
v.Add("chat_id", config.ChannelUsername)
|
||||
} else {
|
||||
v.Add("chat_id", strconv.FormatInt(config.ChatID, 10))
|
||||
}
|
||||
v.Add("user_id", strconv.Itoa(config.UserID))
|
||||
|
||||
if &config.CanChangeInfo != nil {
|
||||
v.Add("can_change_info", strconv.FormatBool(*config.CanChangeInfo))
|
||||
}
|
||||
if &config.CanPostMessages != nil {
|
||||
v.Add("can_post_messages", strconv.FormatBool(*config.CanPostMessages))
|
||||
}
|
||||
if &config.CanEditMessages != nil {
|
||||
v.Add("can_edit_messages", strconv.FormatBool(*config.CanEditMessages))
|
||||
}
|
||||
if &config.CanDeleteMessages != nil {
|
||||
v.Add("can_delete_messages", strconv.FormatBool(*config.CanDeleteMessages))
|
||||
}
|
||||
if &config.CanInviteUsers != nil {
|
||||
v.Add("can_invite_users", strconv.FormatBool(*config.CanInviteUsers))
|
||||
}
|
||||
if &config.CanRestrictMembers != nil {
|
||||
v.Add("can_restrict_members", strconv.FormatBool(*config.CanRestrictMembers))
|
||||
}
|
||||
if &config.CanPinMessages != nil {
|
||||
v.Add("can_pin_messages", strconv.FormatBool(*config.CanPinMessages))
|
||||
}
|
||||
if &config.CanPromoteMembers != nil {
|
||||
v.Add("can_promote_members", strconv.FormatBool(*config.CanPromoteMembers))
|
||||
}
|
||||
|
||||
bot.debugLog("promoteChatMember", v, nil)
|
||||
|
||||
return bot.MakeRequest("promoteChatMember", v)
|
||||
}
|
||||
|
||||
// GetGameHighScores allows you to get the high scores for a game.
|
||||
func (bot *BotAPI) GetGameHighScores(config GetGameHighScoresConfig) ([]GameHighScore, error) {
|
||||
v, _ := config.values()
|
||||
|
|
29
configs.go
29
configs.go
|
@ -887,6 +887,35 @@ type ChatMemberConfig struct {
|
|||
UserID int
|
||||
}
|
||||
|
||||
// KickChatMemberConfig contains extra fields to kick user
|
||||
type KickChatMemberConfig struct {
|
||||
ChatMemberConfig
|
||||
UntilDate int64
|
||||
}
|
||||
|
||||
// RestrictChatMemberConfig contains fields to restrict members of chat
|
||||
type RestrictChatMemberConfig struct {
|
||||
ChatMemberConfig
|
||||
UntilDate int64
|
||||
CanSendMessages *bool
|
||||
CanSendMediaMessages *bool
|
||||
CanSendOtherMessages *bool
|
||||
CanAddWebPagePreviews *bool
|
||||
}
|
||||
|
||||
// PromoteChatMemberConfig contains fields to promote members of chat
|
||||
type PromoteChatMemberConfig struct {
|
||||
ChatMemberConfig
|
||||
CanChangeInfo *bool
|
||||
CanPostMessages *bool
|
||||
CanEditMessages *bool
|
||||
CanDeleteMessages *bool
|
||||
CanInviteUsers *bool
|
||||
CanRestrictMembers *bool
|
||||
CanPinMessages *bool
|
||||
CanPromoteMembers *bool
|
||||
}
|
||||
|
||||
// ChatConfig contains information about getting information on a chat.
|
||||
type ChatConfig struct {
|
||||
ChatID int64
|
||||
|
|
14
types.go
14
types.go
|
@ -411,6 +411,20 @@ type ForceReply struct {
|
|||
type ChatMember struct {
|
||||
User *User `json:"user"`
|
||||
Status string `json:"status"`
|
||||
UntilDate int64 `json:"until_date,omitempty"` // optional
|
||||
CanBeEdited bool `json:"can_be_edited,omitempty"` // optional
|
||||
CanChangeInfo bool `json:"can_change_info,omitempty"` // optional
|
||||
CanPostMessages bool `json:"can_post_messages,omitempty"` // optional
|
||||
CanEditMessages bool `json:"can_edit_messages,omitempty"` // optional
|
||||
CanDeleteMessages bool `json:"can_delete_messages,omitempty"` // optional
|
||||
CanInviteUsers bool `json:"can_invite_users,omitempty"` // optional
|
||||
CanRestrictMembers bool `json:"can_restrict_members,omitempty"` // optional
|
||||
CanPinMessages bool `json:"can_pin_messages,omitempty"` // optional
|
||||
CanPromoteMembers bool `json:"can_promote_members,omitempty"` // optional
|
||||
CanSendMessages bool `json:"can_send_messages,omitempty"` // optional
|
||||
CanSendMediaMessages bool `json:"can_send_media_messages,omitempty"` // optional
|
||||
CanSendOtherMessages bool `json:"can_send_other_messages,omitempty"` // optional
|
||||
CanAddWebPagePreviews bool `json:"can_add_web_page_previews,omitempty"` // optional
|
||||
}
|
||||
|
||||
// IsCreator returns if the ChatMember was the creator of the chat.
|
||||
|
|
Loading…
Reference in New Issue