react: refactor

v3 v3.3.6
Demian 2 weeks ago
parent 10fbde9b66
commit a8acf84301

@ -1,7 +1,6 @@
package telebot
import (
"encoding/json"
"strconv"
"time"
"unicode/utf16"
@ -720,33 +719,3 @@ type ReplyParams struct {
// (Optional) Position of the quote in the original message in UTF-16 code units.
QuotePosition int `json:"quote_position"`
}
// React changes the chosen reactions on a message. Service messages can't be
// reacted to. Automatically forwarded messages from a channel to its discussion group have
// the same available reactions as messages in the channel.
func (b *Bot) React(to Recipient, msg Editable, opts ...ReactionOptions) error {
if to == nil {
return ErrBadRecipient
}
msgID, _ := msg.MessageSig()
params := map[string]string{
"chat_id": to.Recipient(),
"message_id": msgID,
}
if len(opts) > 0 {
opt := opts[0]
if len(opt.Reactions) > 0 {
data, _ := json.Marshal(opt.Reactions)
params["reaction"] = string(data)
}
if opt.Big {
params["is_big"] = "true"
}
}
_, err := b.Raw("setMessageReaction", params)
return err
}

@ -1,7 +1,8 @@
package telebot
// EmojiType defines emoji types.
type EmojiType = string
import (
"encoding/json"
)
// Reaction describes the type of reaction.
// Describes an instance of ReactionTypeCustomEmoji and ReactionTypeEmoji.
@ -10,7 +11,7 @@ type Reaction struct {
Type string `json:"type"`
// Reaction emoji.
Emoji EmojiType `json:"emoji,omitempty"`
Emoji string `json:"emoji,omitempty"`
// Custom emoji identifier.
CustomEmoji string `json:"custom_emoji_id,omitempty"`
@ -34,3 +35,33 @@ type ReactionOptions struct {
// Pass True to set the reaction with a big animation.
Big bool `json:"is_big"`
}
// React changes the chosen reactions on a message. Service messages can't be
// reacted to. Automatically forwarded messages from a channel to its discussion group have
// the same available reactions as messages in the channel.
func (b *Bot) React(to Recipient, msg Editable, opts ...ReactionOptions) error {
if to == nil {
return ErrBadRecipient
}
msgID, _ := msg.MessageSig()
params := map[string]string{
"chat_id": to.Recipient(),
"message_id": msgID,
}
if len(opts) > 0 {
opt := opts[0]
if len(opt.Reactions) > 0 {
data, _ := json.Marshal(opt.Reactions)
params["reaction"] = string(data)
}
if opt.Big {
params["is_big"] = "true"
}
}
_, err := b.Raw("setMessageReaction", params)
return err
}

@ -1,8 +1,14 @@
package react
import "gopkg.in/telebot.v3"
import (
tele "gopkg.in/telebot.v3"
)
type Reaction = tele.Reaction
type Reaction = telebot.Reaction
func React(r ...Reaction) tele.ReactionOptions {
return tele.ReactionOptions{Reactions: r}
}
// Currently available emojis.
var (
Loading…
Cancel
Save