♻️ Use fasthttp.Args more safe
This commit is contained in:
parent
ed3989675d
commit
174aa0730f
|
@ -14,10 +14,11 @@ import (
|
|||
// Note: In regular groups (non-supergroups), this method will only work if the
|
||||
// 'All Members Are Admins' setting is off in the target group.
|
||||
func (bot *Bot) DeleteChatPhoto(chatID int64) (bool, error) {
|
||||
var args http.Args
|
||||
args := http.AcquireArgs()
|
||||
defer http.ReleaseArgs(args)
|
||||
args.Add("chat_id", strconv.FormatInt(chatID, 10))
|
||||
|
||||
resp, err := bot.request(nil, "deleteChatPhoto", &args)
|
||||
resp, err := bot.request(nil, "deleteChatPhoto", args)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
|
|
@ -12,10 +12,11 @@ import (
|
|||
// can_set_sticker_set optionally returned in getChat requests to check if the bot can use this
|
||||
// method. Returns True on success.
|
||||
func (bot *Bot) DeleteChatStickerSet(chatID int64) (bool, error) {
|
||||
var args http.Args
|
||||
args := http.AcquireArgs()
|
||||
defer http.ReleaseArgs(args)
|
||||
args.Add("chat_id", strconv.FormatInt(chatID, 10))
|
||||
|
||||
resp, err := bot.request(nil, "deleteChatStickerSet", &args)
|
||||
resp, err := bot.request(nil, "deleteChatStickerSet", args)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
|
|
@ -15,11 +15,12 @@ import (
|
|||
// bot has can_delete_messages permission in a supergroup or a channel, it can
|
||||
// delete any message there. Returns True on success.
|
||||
func (bot *Bot) DeleteMessage(chatID int64, message int) (bool, error) {
|
||||
var args http.Args
|
||||
args := http.AcquireArgs()
|
||||
defer http.ReleaseArgs(args)
|
||||
args.Add("message_id", strconv.Itoa(message))
|
||||
args.Add("chat_id", strconv.FormatInt(chatID, 10))
|
||||
|
||||
resp, err := bot.request(nil, "deleteMessage", &args)
|
||||
resp, err := bot.request(nil, "deleteMessage", args)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
|
|
@ -8,10 +8,11 @@ import (
|
|||
// DeleteStickerFromSet delete a sticker from a set created by the bot. Returns
|
||||
// True on success.
|
||||
func (bot *Bot) DeleteStickerFromSet(sticker string) (bool, error) {
|
||||
var args http.Args
|
||||
args := http.AcquireArgs()
|
||||
defer http.ReleaseArgs(args)
|
||||
args.Add("sticker", sticker)
|
||||
|
||||
resp, err := bot.request(nil, "deleteStickerFromSet", &args)
|
||||
resp, err := bot.request(nil, "deleteStickerFromSet", args)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
|
|
@ -11,10 +11,11 @@ import (
|
|||
// bot must be an administrator in the chat for this to work and must have the
|
||||
// appropriate admin rights. Returns exported invite link as String on success.
|
||||
func (bot *Bot) ExportChatInviteLink(chatID int64) (string, error) {
|
||||
var args http.Args
|
||||
args := http.AcquireArgs()
|
||||
defer http.ReleaseArgs(args)
|
||||
args.Add("chat_id", strconv.FormatInt(chatID, 10))
|
||||
|
||||
resp, err := bot.request(nil, "exportChatInviteLink", &args)
|
||||
resp, err := bot.request(nil, "exportChatInviteLink", args)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
|
|
@ -11,10 +11,11 @@ import (
|
|||
// for one-on-one conversations, current username of a user, group or channel,
|
||||
// etc.). Returns a Chat object on success.
|
||||
func (bot *Bot) GetChat(chatID int64) (*Chat, error) {
|
||||
var args http.Args
|
||||
args := http.AcquireArgs()
|
||||
defer http.ReleaseArgs(args)
|
||||
args.Add("chat_id", strconv.FormatInt(chatID, 10))
|
||||
|
||||
resp, err := bot.request(nil, "getChat", &args)
|
||||
resp, err := bot.request(nil, "getChat", args)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
@ -12,10 +12,11 @@ import (
|
|||
// chat administrators except other bots. If the chat is a group or a supergroup
|
||||
// and no administrators were appointed, only the creator will be returned.
|
||||
func (bot *Bot) GetChatAdministrators(chatID int64) (*[]ChatMember, error) {
|
||||
var args http.Args
|
||||
args := http.AcquireArgs()
|
||||
defer http.ReleaseArgs(args)
|
||||
args.Add("chat_id", strconv.FormatInt(chatID, 10))
|
||||
|
||||
resp, err := bot.request(nil, "getChatAdministrators", &args)
|
||||
resp, err := bot.request(nil, "getChatAdministrators", args)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
@ -10,11 +10,12 @@ import (
|
|||
// GetChatMember get information about a member of a chat. Returns a ChatMember
|
||||
// object on success.
|
||||
func (bot *Bot) GetChatMember(chatID int64, user int) (*ChatMember, error) {
|
||||
var args http.Args
|
||||
args := http.AcquireArgs()
|
||||
defer http.ReleaseArgs(args)
|
||||
args.Add("user_id", strconv.Itoa(user))
|
||||
args.Add("chat_id", strconv.FormatInt(chatID, 10))
|
||||
|
||||
resp, err := bot.request(nil, "getChatMember", &args)
|
||||
resp, err := bot.request(nil, "getChatMember", args)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
@ -10,10 +10,11 @@ import (
|
|||
// GetChatMembersCount get the number of members in a chat. Returns Int on
|
||||
// success.
|
||||
func (bot *Bot) GetChatMembersCount(chatID int64) (int, error) {
|
||||
var args http.Args
|
||||
args := http.AcquireArgs()
|
||||
defer http.ReleaseArgs(args)
|
||||
args.Add("chat_id", strconv.FormatInt(chatID, 10))
|
||||
|
||||
resp, err := bot.request(nil, "getChatMembersCount", &args)
|
||||
resp, err := bot.request(nil, "getChatMembersCount", args)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
|
|
@ -17,10 +17,11 @@ import (
|
|||
// should save the file's MIME type and name (if available) when the File object
|
||||
// is received.
|
||||
func (bot *Bot) GetFile(file string) (*File, error) {
|
||||
var args http.Args
|
||||
args := http.AcquireArgs()
|
||||
defer http.ReleaseArgs(args)
|
||||
args.Add("file_id", file)
|
||||
|
||||
resp, err := bot.request(nil, "getFile", &args)
|
||||
resp, err := bot.request(nil, "getFile", args)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
@ -7,10 +7,11 @@ import (
|
|||
|
||||
// GetStickerSet get a sticker set. On success, a StickerSet object is returned.
|
||||
func (bot *Bot) GetStickerSet(name string) (*StickerSet, error) {
|
||||
var args http.Args
|
||||
args := http.AcquireArgs()
|
||||
defer http.ReleaseArgs(args)
|
||||
args.Add("name", name)
|
||||
|
||||
resp, err := bot.request(nil, "getStickerSet", &args)
|
||||
resp, err := bot.request(nil, "getStickerSet", args)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
@ -16,12 +16,13 @@ import (
|
|||
// Admins' setting is off in the target group. Otherwise members may only be removed by the group's
|
||||
// creator or by the member that added them.
|
||||
func (bot *Bot) KickChatMember(chatID int64, userID int, untilDate int64) (bool, error) {
|
||||
var args http.Args
|
||||
args := http.AcquireArgs()
|
||||
defer http.ReleaseArgs(args)
|
||||
args.Add("chat_id", strconv.FormatInt(chatID, 10))
|
||||
args.Add("user_id", strconv.Itoa(userID))
|
||||
args.Add("until_date", strconv.FormatInt(untilDate, 10))
|
||||
|
||||
resp, err := bot.request(nil, "kickChatMember", &args)
|
||||
resp, err := bot.request(nil, "kickChatMember", args)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
|
|
@ -9,10 +9,11 @@ import (
|
|||
|
||||
// LeaveChat leave a group, supergroup or channel. Returns True on success.
|
||||
func (bot *Bot) LeaveChat(chat int64) (bool, error) {
|
||||
var args http.Args
|
||||
args := http.AcquireArgs()
|
||||
defer http.ReleaseArgs(args)
|
||||
args.Add("chat_id", strconv.FormatInt(chat, 10))
|
||||
|
||||
resp, err := bot.request(nil, "leaveChat", &args)
|
||||
resp, err := bot.request(nil, "leaveChat", args)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
|
|
@ -14,11 +14,12 @@ import (
|
|||
// We only recommend using this method when a response from the bot will take a
|
||||
// noticeable amount of time to arrive.
|
||||
func (bot *Bot) SendChatAction(chatID int64, action string) (bool, error) {
|
||||
var args http.Args
|
||||
args := http.AcquireArgs()
|
||||
defer http.ReleaseArgs(args)
|
||||
args.Add("action", action) // Type of action to broadcast
|
||||
args.Add("chat_id", strconv.FormatInt(chatID, 10))
|
||||
|
||||
resp, err := bot.request(nil, "sendChatAction", &args)
|
||||
resp, err := bot.request(nil, "sendChatAction", args)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
|
|
@ -51,7 +51,8 @@ func NewSticker(chatID int64, sticker interface{}) *SendStickerParameters {
|
|||
|
||||
// SendSticker send .webp stickers. On success, the sent Message is returned.
|
||||
func (bot *Bot) SendSticker(params *SendStickerParameters) (*Message, error) {
|
||||
var args http.Args
|
||||
args := http.AcquireArgs()
|
||||
defer http.ReleaseArgs(args)
|
||||
args.Add("chat_id", params.ChatID)
|
||||
args.Add("disable_notification", strconv.FormatBool(params.DisableNotification))
|
||||
|
||||
|
@ -86,7 +87,7 @@ func (bot *Bot) SendSticker(params *SendStickerParameters) (*Message, error) {
|
|||
return false, errors.New("use string only (for current version of go-telegram)")
|
||||
}
|
||||
|
||||
resp, err := bot.upload(buffer.Bytes(), multi.Boundary(), "setWebhook", &args)
|
||||
resp, err := bot.upload(buffer.Bytes(), multi.Boundary(), "setWebhook", args)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
|
|
@ -14,10 +14,11 @@ import (
|
|||
// Note: In regular groups (non-supergroups), this method will only work if the 'All Members Are
|
||||
// Admins' setting is off in the target group.
|
||||
func (bot *Bot) SetChatPhoto(chatID int64, photo InputFile) (bool, error) {
|
||||
var args http.Args
|
||||
args := http.AcquireArgs()
|
||||
defer http.ReleaseArgs(args)
|
||||
args.Add("chat_id", strconv.FormatInt(chatID, 10))
|
||||
|
||||
resp, err := bot.upload(photo, TypePhoto, "chat_photo", "setChatPhoto", &args)
|
||||
resp, err := bot.upload(photo, TypePhoto, "chat_photo", "setChatPhoto", args)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
|
|
@ -12,11 +12,12 @@ import (
|
|||
// can_set_sticker_set optionally returned in getChat requests to check if the bot can use this
|
||||
// method. Returns True on success.
|
||||
func (bot *Bot) SetChatStickerSet(chatID int64, stickerSetName string) (bool, error) {
|
||||
var args http.Args
|
||||
args := http.AcquireArgs()
|
||||
defer http.ReleaseArgs(args)
|
||||
args.Add("chat_id", strconv.FormatInt(chatID, 10))
|
||||
args.Add("sticker_set_name", stickerSetName)
|
||||
|
||||
resp, err := bot.request(nil, "setChatStickerSet", &args)
|
||||
resp, err := bot.request(nil, "setChatStickerSet", args)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
|
|
@ -14,11 +14,12 @@ import (
|
|||
// Note: In regular groups (non-supergroups), this method will only work if the
|
||||
// 'All Members Are Admins' setting is off in the target group.
|
||||
func (bot *Bot) SetChatTitle(chatID int64, title string) (bool, error) {
|
||||
var args http.Args
|
||||
args := http.AcquireArgs()
|
||||
defer http.ReleaseArgs(args)
|
||||
args.Add("title", title)
|
||||
args.Add("chat_id", strconv.FormatInt(chatID, 10))
|
||||
|
||||
resp, err := bot.request(nil, "setChatTitle", &args)
|
||||
resp, err := bot.request(nil, "setChatTitle", args)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
|
|
@ -10,11 +10,12 @@ import (
|
|||
// SetStickerPositionInSet move a sticker in a set created by the bot to a
|
||||
// specific position. Returns True on success.
|
||||
func (bot *Bot) SetStickerPositionInSet(sticker string, position int) (bool, error) {
|
||||
var args http.Args
|
||||
args := http.AcquireArgs()
|
||||
defer http.ReleaseArgs(args)
|
||||
args.Add("sticker", sticker)
|
||||
args.Add("position", strconv.Itoa(position))
|
||||
|
||||
resp, err := bot.request(nil, "setStickerPositionInSet", &args)
|
||||
resp, err := bot.request(nil, "setStickerPositionInSet", args)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
|
|
@ -55,7 +55,8 @@ func NewWebhook(url string, file interface{}) *SetWebhookParameters {
|
|||
// recommend using a secret path in the URL, e.g. https://www.example.com/<token>.
|
||||
// Since nobody else knows your bot‘s token, you can be pretty sure it’s us.
|
||||
func (bot *Bot) SetWebhook(params *SetWebhookParameters) (bool, error) {
|
||||
var args http.Args
|
||||
args := http.AcquireArgs()
|
||||
defer http.ReleaseArgs(args)
|
||||
args.Add("url", params.URL)
|
||||
|
||||
if len(params.AllowedUpdates) > 0 {
|
||||
|
@ -70,10 +71,10 @@ func (bot *Bot) SetWebhook(params *SetWebhookParameters) (bool, error) {
|
|||
resp := &Response{}
|
||||
if params.Certificate != nil {
|
||||
resp, err = bot.upload(
|
||||
params.Certificate, "certificate", "cert.pem", setWebhook, &args,
|
||||
params.Certificate, "certificate", "cert.pem", setWebhook, args,
|
||||
)
|
||||
} else {
|
||||
resp, err = bot.request(nil, setWebhook, &args)
|
||||
resp, err = bot.request(nil, setWebhook, args)
|
||||
}
|
||||
if err != nil {
|
||||
return false, err
|
||||
|
|
|
@ -12,11 +12,12 @@ import (
|
|||
// to join via link, etc. The bot must be an administrator for this to work.
|
||||
// Returns True on success.
|
||||
func (bot *Bot) UnbanChatMember(chatID int64, user int) (bool, error) {
|
||||
var args http.Args
|
||||
args := http.AcquireArgs()
|
||||
defer http.ReleaseArgs(args)
|
||||
args.Add("user_id", strconv.Itoa(user))
|
||||
args.Add("chat_id", strconv.FormatInt(chatID, 10))
|
||||
|
||||
resp, err := bot.request(nil, "unbanChatMember", &args)
|
||||
resp, err := bot.request(nil, "unbanChatMember", args)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
|
|
@ -11,10 +11,11 @@ import (
|
|||
// administrator in the chat for this to work and must have the appropriate admin
|
||||
// rights. Returns True on success.
|
||||
func (bot *Bot) UnpinChatMessage(chatID int64) (bool, error) {
|
||||
var args http.Args
|
||||
args := http.AcquireArgs()
|
||||
defer http.ReleaseArgs(args)
|
||||
args.Add("chat_id", strconv.FormatInt(chatID, 10))
|
||||
|
||||
resp, err := bot.request(nil, "unpinChatMessage", &args)
|
||||
resp, err := bot.request(nil, "unpinChatMessage", args)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user