react: refactor

v3.3 v3.3.0-beta
Demian 3 months ago
parent 6fdf666a11
commit 9eb53434a0

@ -317,7 +317,7 @@ func TestBotProcessUpdate(t *testing.T) {
b.ProcessUpdate(Update{Message: &Message{Text: "/start@other_bot"}}) b.ProcessUpdate(Update{Message: &Message{Text: "/start@other_bot"}})
b.ProcessUpdate(Update{Message: &Message{Text: "hello"}}) b.ProcessUpdate(Update{Message: &Message{Text: "hello"}})
b.ProcessUpdate(Update{Message: &Message{Text: "text"}}) b.ProcessUpdate(Update{Message: &Message{Text: "text"}})
b.ProcessUpdate(Update{Message: &Message{PinnedMessage: &InaccessibleMessage{}}}) b.ProcessUpdate(Update{Message: &Message{PinnedMessage: &InaccessibleMessage{Message: &Message{}}}})
b.ProcessUpdate(Update{Message: &Message{Photo: &Photo{}}}) b.ProcessUpdate(Update{Message: &Message{Photo: &Photo{}}})
b.ProcessUpdate(Update{Message: &Message{Voice: &Voice{}}}) b.ProcessUpdate(Update{Message: &Message{Voice: &Voice{}}})
b.ProcessUpdate(Update{Message: &Message{Audio: &Audio{}}}) b.ProcessUpdate(Update{Message: &Message{Audio: &Audio{}}})
@ -342,7 +342,7 @@ func TestBotProcessUpdate(t *testing.T) {
b.ProcessUpdate(Update{Message: &Message{Chat: &Chat{ID: 1}, MigrateTo: 2}}) b.ProcessUpdate(Update{Message: &Message{Chat: &Chat{ID: 1}, MigrateTo: 2}})
b.ProcessUpdate(Update{EditedMessage: &Message{Text: "edited"}}) b.ProcessUpdate(Update{EditedMessage: &Message{Text: "edited"}})
b.ProcessUpdate(Update{ChannelPost: &Message{Text: "post"}}) b.ProcessUpdate(Update{ChannelPost: &Message{Text: "post"}})
b.ProcessUpdate(Update{ChannelPost: &Message{PinnedMessage: &InaccessibleMessage{}}}) b.ProcessUpdate(Update{ChannelPost: &Message{PinnedMessage: &InaccessibleMessage{Message: &Message{}}}})
b.ProcessUpdate(Update{EditedChannelPost: &Message{Text: "edited post"}}) b.ProcessUpdate(Update{EditedChannelPost: &Message{Text: "edited post"}})
b.ProcessUpdate(Update{Callback: &Callback{MessageID: "inline", Data: "callback"}}) b.ProcessUpdate(Update{Callback: &Callback{MessageID: "inline", Data: "callback"}})
b.ProcessUpdate(Update{Callback: &Callback{Data: "callback"}}) b.ProcessUpdate(Update{Callback: &Callback{Data: "callback"}})

@ -4,8 +4,6 @@ import (
"encoding/json" "encoding/json"
"strconv" "strconv"
"time" "time"
"gopkg.in/telebot.v3/react"
) )
// User object represents a Telegram user, bot. // User object represents a Telegram user, bot.
@ -49,32 +47,32 @@ type Chat struct {
Username string `json:"username"` Username string `json:"username"`
// Returns only in getChat // Returns only in getChat
Bio string `json:"bio,omitempty"` Bio string `json:"bio,omitempty"`
Photo *ChatPhoto `json:"photo,omitempty"` Photo *ChatPhoto `json:"photo,omitempty"`
Description string `json:"description,omitempty"` Description string `json:"description,omitempty"`
InviteLink string `json:"invite_link,omitempty"` InviteLink string `json:"invite_link,omitempty"`
PinnedMessage *Message `json:"pinned_message,omitempty"` PinnedMessage *Message `json:"pinned_message,omitempty"`
Permissions *Rights `json:"permissions,omitempty"` Permissions *Rights `json:"permissions,omitempty"`
Reactions []react.Reaction `json:"available_reactions"` Reactions []Reaction `json:"available_reactions"`
SlowMode int `json:"slow_mode_delay,omitempty"` SlowMode int `json:"slow_mode_delay,omitempty"`
StickerSet string `json:"sticker_set_name,omitempty"` StickerSet string `json:"sticker_set_name,omitempty"`
CanSetStickerSet bool `json:"can_set_sticker_set,omitempty"` CanSetStickerSet bool `json:"can_set_sticker_set,omitempty"`
CustomEmojiSetName string `json:"custom_emoji_sticker_set_name"` CustomEmojiSetName string `json:"custom_emoji_sticker_set_name"`
LinkedChatID int64 `json:"linked_chat_id,omitempty"` LinkedChatID int64 `json:"linked_chat_id,omitempty"`
ChatLocation *ChatLocation `json:"location,omitempty"` ChatLocation *ChatLocation `json:"location,omitempty"`
Private bool `json:"has_private_forwards,omitempty"` Private bool `json:"has_private_forwards,omitempty"`
Protected bool `json:"has_protected_content,omitempty"` Protected bool `json:"has_protected_content,omitempty"`
NoVoiceAndVideo bool `json:"has_restricted_voice_and_video_messages"` NoVoiceAndVideo bool `json:"has_restricted_voice_and_video_messages"`
HasHiddenMembers bool `json:"has_hidden_members,omitempty"` HasHiddenMembers bool `json:"has_hidden_members,omitempty"`
AggressiveAntiSpam bool `json:"has_aggressive_anti_spam_enabled,omitempty"` AggressiveAntiSpam bool `json:"has_aggressive_anti_spam_enabled,omitempty"`
CustomEmojiID string `json:"emoji_status_custom_emoji_id"` CustomEmojiID string `json:"emoji_status_custom_emoji_id"`
EmojiExpirationUnixtime int64 `json:"emoji_status_expiration_date"` EmojiExpirationUnixtime int64 `json:"emoji_status_expiration_date"`
BackgroundEmojiID string `json:"background_custom_emoji_id"` BackgroundEmojiID string `json:"background_custom_emoji_id"`
AccentColorID int `json:"accent_color_id"` AccentColorID int `json:"accent_color_id"`
ProfileAccentColorID int `json:"profile_accent_color_id"` ProfileAccentColorID int `json:"profile_accent_color_id"`
ProfileBackgroundEmojiID string `json:"profile_background_custom_emoji_id"` ProfileBackgroundEmojiID string `json:"profile_background_custom_emoji_id"`
HasVisibleHistory bool `json:"has_visible_history"` HasVisibleHistory bool `json:"has_visible_history"`
UnrestrictBoosts int `json:"unrestrict_boost_count"` UnrestrictBoosts int `json:"unrestrict_boost_count"`
} }
// Recipient returns chat ID (see Recipient interface). // Recipient returns chat ID (see Recipient interface).

@ -5,8 +5,6 @@ import (
"strconv" "strconv"
"time" "time"
"unicode/utf16" "unicode/utf16"
"gopkg.in/telebot.v3/react"
) )
// Message object represents a message. // Message object represents a message.
@ -107,7 +105,7 @@ type Message struct {
// etc. that appear in the text. // etc. that appear in the text.
Entities Entities `json:"entities,omitempty"` Entities Entities `json:"entities,omitempty"`
// (Optional) Options used for link preview generation for the message, // (Optional) ReactionOptions used for link preview generation for the message,
// if it is a text message and link preview options were changed // if it is a text message and link preview options were changed
PreviewOptions PreviewOptions `json:"link_preview_options,omitempty"` PreviewOptions PreviewOptions `json:"link_preview_options,omitempty"`
@ -551,10 +549,10 @@ type MessageReaction struct {
DateUnixtime int64 `json:"date"` DateUnixtime int64 `json:"date"`
// Previous list of reaction types that were set by the user. // Previous list of reaction types that were set by the user.
OldReaction []react.Reaction `json:"old_reaction"` OldReaction []Reaction `json:"old_reaction"`
// New list of reaction types that have been set by the user. // New list of reaction types that have been set by the user.
NewReaction []react.Reaction `json:"new_reaction"` NewReaction []Reaction `json:"new_reaction"`
} }
func (mu *MessageReaction) Time() time.Time { func (mu *MessageReaction) Time() time.Time {
@ -574,7 +572,7 @@ type MessageReactionCount struct {
DateUnixtime int64 `json:"date"` DateUnixtime int64 `json:"date"`
// List of reactions that are present on the message. // List of reactions that are present on the message.
Reactions *react.Count `json:"reactions"` Reactions *ReactionCount `json:"reactions"`
} }
// Time returns the moment of change in local time. // Time returns the moment of change in local time.
@ -649,7 +647,7 @@ type ExternalReplyInfo struct {
// Available only if the original chat is a supergroup or a channel. // Available only if the original chat is a supergroup or a channel.
MessageID int `json:"message_id"` MessageID int `json:"message_id"`
// (Optional) Options used for link preview generation for the original message, // (Optional) ReactionOptions used for link preview generation for the original message,
// if it is a text message. // if it is a text message.
PreviewOptions *PreviewOptions `json:"link_preview_options"` PreviewOptions *PreviewOptions `json:"link_preview_options"`
@ -746,7 +744,7 @@ type ReplyParams struct {
// React changes the chosen reactions on a message. Service messages can't be // 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 // reacted to. Automatically forwarded messages from a channel to its discussion group have
// the same available reactions as messages in the channel. // the same available reactions as messages in the channel.
func (b *Bot) React(to Recipient, msg Editable, opts ...react.Options) error { func (b *Bot) React(to Recipient, msg Editable, opts ...ReactionOptions) error {
if to == nil { if to == nil {
return ErrBadRecipient return ErrBadRecipient
} }

@ -0,0 +1,36 @@
package telebot
// EmojiType defines emoji types.
type EmojiType = string
// Reaction describes the type of reaction.
// Describes an instance of ReactionTypeCustomEmoji and ReactionTypeEmoji.
type Reaction struct {
// Type of the reaction, always “emoji”
Type string `json:"type"`
// Reaction emoji.
Emoji EmojiType `json:"emoji,omitempty"`
// Custom emoji identifier.
CustomEmoji string `json:"custom_emoji_id,omitempty"`
}
// ReactionCount represents a reaction added to a message along
// with the number of times it was added.
type ReactionCount struct {
// Type of the reaction.
Type Reaction `json:"type"`
// Number of times the reaction was added.
Count int `json:"total_count"`
}
// ReactionOptions represents an object of reaction options.
type ReactionOptions struct {
// List of reaction types to set on the message.
Reactions []Reaction `json:"reaction"`
// Pass True to set the reaction with a big animation.
Big bool `json:"is_big"`
}

@ -1,7 +1,8 @@
package react package react
// EmojiType defines emoji types. import "gopkg.in/telebot.v3"
type EmojiType = string
type Reaction = telebot.Reaction
// Currently available emojis. // Currently available emojis.
var ( var (
@ -78,35 +79,3 @@ var (
WomanShrugging = Reaction{Emoji: "🤷‍♀️"} WomanShrugging = Reaction{Emoji: "🤷‍♀️"}
PoutingFace = Reaction{Emoji: "😡"} PoutingFace = Reaction{Emoji: "😡"}
) )
// Reaction describes the type of reaction.
// Describes an instance of ReactionTypeCustomEmoji and ReactionTypeEmoji.
type Reaction struct {
// Type of the reaction, always “emoji”
Type string `json:"type"`
// Reaction emoji.
Emoji EmojiType `json:"emoji,omitempty"`
// Custom emoji identifier.
CustomEmoji string `json:"custom_emoji_id,omitempty"`
}
// Count represents a reaction added to a message along
// with the number of times it was added.
type Count struct {
// Type of the reaction.
Type Reaction `json:"type"`
// Number of times the reaction was added.
Count int `json:"total_count"`
}
// Options represents an object of reaction options.
type Options struct {
// List of reaction types to set on the message.
Reactions []Reaction `json:"reaction"`
// Pass True to set the reaction with a big animation.
Big bool `json:"is_big"`
}

Loading…
Cancel
Save