Remove remaining methods that returned an APIResponse.
This commit is contained in:
parent
95a923dc4c
commit
ac87082c55
3 changed files with 234 additions and 213 deletions
209
bot.go
209
bot.go
|
@ -377,37 +377,6 @@ func (bot *BotAPI) GetUpdates(config UpdateConfig) ([]Update, error) {
|
|||
return updates, nil
|
||||
}
|
||||
|
||||
// SetWebhook sets a webhook.
|
||||
//
|
||||
// If this is set, GetUpdates will not get any data!
|
||||
//
|
||||
// If you do not have a legitimate TLS certificate, you need to include
|
||||
// your self signed certificate with the config.
|
||||
func (bot *BotAPI) SetWebhook(config WebhookConfig) (APIResponse, error) {
|
||||
if config.Certificate == nil {
|
||||
v := url.Values{}
|
||||
v.Add("url", config.URL.String())
|
||||
if config.MaxConnections != 0 {
|
||||
v.Add("max_connections", strconv.Itoa(config.MaxConnections))
|
||||
}
|
||||
|
||||
return bot.MakeRequest("setWebhook", v)
|
||||
}
|
||||
|
||||
params := make(map[string]string)
|
||||
params["url"] = config.URL.String()
|
||||
if config.MaxConnections != 0 {
|
||||
params["max_connections"] = strconv.Itoa(config.MaxConnections)
|
||||
}
|
||||
|
||||
resp, err := bot.UploadFile("setWebhook", params, "certificate", config.Certificate)
|
||||
if err != nil {
|
||||
return APIResponse{}, err
|
||||
}
|
||||
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
// GetWebhookInfo allows you to fetch information about a webhook and if
|
||||
// one currently is set, along with pending update count and error messages.
|
||||
func (bot *BotAPI) GetWebhookInfo() (WebhookInfo, error) {
|
||||
|
@ -465,85 +434,6 @@ func (bot *BotAPI) ListenForWebhook(pattern string) UpdatesChannel {
|
|||
return ch
|
||||
}
|
||||
|
||||
// AnswerInlineQuery sends a response to an inline query.
|
||||
//
|
||||
// Note that you must respond to an inline query within 30 seconds.
|
||||
func (bot *BotAPI) AnswerInlineQuery(config InlineConfig) (APIResponse, error) {
|
||||
v := url.Values{}
|
||||
|
||||
v.Add("inline_query_id", config.InlineQueryID)
|
||||
v.Add("cache_time", strconv.Itoa(config.CacheTime))
|
||||
v.Add("is_personal", strconv.FormatBool(config.IsPersonal))
|
||||
v.Add("next_offset", config.NextOffset)
|
||||
data, err := json.Marshal(config.Results)
|
||||
if err != nil {
|
||||
return APIResponse{}, err
|
||||
}
|
||||
v.Add("results", string(data))
|
||||
v.Add("switch_pm_text", config.SwitchPMText)
|
||||
v.Add("switch_pm_parameter", config.SwitchPMParameter)
|
||||
|
||||
bot.debugLog("answerInlineQuery", v, nil)
|
||||
|
||||
return bot.MakeRequest("answerInlineQuery", v)
|
||||
}
|
||||
|
||||
// AnswerCallbackQuery sends a response to an inline query callback.
|
||||
func (bot *BotAPI) AnswerCallbackQuery(config CallbackConfig) (APIResponse, error) {
|
||||
v := url.Values{}
|
||||
|
||||
v.Add("callback_query_id", config.CallbackQueryID)
|
||||
if config.Text != "" {
|
||||
v.Add("text", config.Text)
|
||||
}
|
||||
v.Add("show_alert", strconv.FormatBool(config.ShowAlert))
|
||||
if config.URL != "" {
|
||||
v.Add("url", config.URL)
|
||||
}
|
||||
v.Add("cache_time", strconv.Itoa(config.CacheTime))
|
||||
|
||||
bot.debugLog("answerCallbackQuery", v, nil)
|
||||
|
||||
return bot.MakeRequest("answerCallbackQuery", v)
|
||||
}
|
||||
|
||||
// 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 KickChatMemberConfig) (APIResponse, error) {
|
||||
v := url.Values{}
|
||||
|
||||
if config.SuperGroupUsername == "" {
|
||||
v.Add("chat_id", strconv.FormatInt(config.ChatID, 10))
|
||||
} else {
|
||||
v.Add("chat_id", config.SuperGroupUsername)
|
||||
}
|
||||
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)
|
||||
}
|
||||
|
||||
// LeaveChat makes the bot leave the chat.
|
||||
func (bot *BotAPI) LeaveChat(config ChatConfig) (APIResponse, error) {
|
||||
v := url.Values{}
|
||||
|
||||
if config.SuperGroupUsername == "" {
|
||||
v.Add("chat_id", strconv.FormatInt(config.ChatID, 10))
|
||||
} else {
|
||||
v.Add("chat_id", config.SuperGroupUsername)
|
||||
}
|
||||
|
||||
bot.debugLog("leaveChat", v, nil)
|
||||
|
||||
return bot.MakeRequest("leaveChat", v)
|
||||
}
|
||||
|
||||
// GetChat gets information about a chat.
|
||||
func (bot *BotAPI) GetChat(config ChatConfig) (Chat, error) {
|
||||
v := url.Values{}
|
||||
|
@ -640,105 +530,6 @@ 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) {
|
||||
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))
|
||||
|
||||
bot.debugLog("unbanChatMember", v, nil)
|
||||
|
||||
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))
|
||||
}
|
||||
if config.UntilDate != 0 {
|
||||
v.Add("until_date", strconv.FormatInt(config.UntilDate, 10))
|
||||
}
|
||||
|
||||
bot.debugLog("restrictChatMember", v, nil)
|
||||
|
||||
return bot.MakeRequest("restrictChatMember", v)
|
||||
}
|
||||
|
||||
// PromoteChatMember add admin rights to user
|
||||
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()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue