Skip to content

Commit a8acf84

Browse files
committed
react: refactor
1 parent 10fbde9 commit a8acf84

File tree

3 files changed

+42
-36
lines changed

3 files changed

+42
-36
lines changed

message.go

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package telebot
22

33
import (
4-
"encoding/json"
54
"strconv"
65
"time"
76
"unicode/utf16"
@@ -720,33 +719,3 @@ type ReplyParams struct {
720719
// (Optional) Position of the quote in the original message in UTF-16 code units.
721720
QuotePosition int `json:"quote_position"`
722721
}
723-
724-
// React changes the chosen reactions on a message. Service messages can't be
725-
// reacted to. Automatically forwarded messages from a channel to its discussion group have
726-
// the same available reactions as messages in the channel.
727-
func (b *Bot) React(to Recipient, msg Editable, opts ...ReactionOptions) error {
728-
if to == nil {
729-
return ErrBadRecipient
730-
}
731-
msgID, _ := msg.MessageSig()
732-
733-
params := map[string]string{
734-
"chat_id": to.Recipient(),
735-
"message_id": msgID,
736-
}
737-
738-
if len(opts) > 0 {
739-
opt := opts[0]
740-
741-
if len(opt.Reactions) > 0 {
742-
data, _ := json.Marshal(opt.Reactions)
743-
params["reaction"] = string(data)
744-
}
745-
if opt.Big {
746-
params["is_big"] = "true"
747-
}
748-
}
749-
750-
_, err := b.Raw("setMessageReaction", params)
751-
return err
752-
}

react.go

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
package telebot
22

3-
// EmojiType defines emoji types.
4-
type EmojiType = string
3+
import (
4+
"encoding/json"
5+
)
56

67
// Reaction describes the type of reaction.
78
// Describes an instance of ReactionTypeCustomEmoji and ReactionTypeEmoji.
@@ -10,7 +11,7 @@ type Reaction struct {
1011
Type string `json:"type"`
1112

1213
// Reaction emoji.
13-
Emoji EmojiType `json:"emoji,omitempty"`
14+
Emoji string `json:"emoji,omitempty"`
1415

1516
// Custom emoji identifier.
1617
CustomEmoji string `json:"custom_emoji_id,omitempty"`
@@ -34,3 +35,33 @@ type ReactionOptions struct {
3435
// Pass True to set the reaction with a big animation.
3536
Big bool `json:"is_big"`
3637
}
38+
39+
// React changes the chosen reactions on a message. Service messages can't be
40+
// reacted to. Automatically forwarded messages from a channel to its discussion group have
41+
// the same available reactions as messages in the channel.
42+
func (b *Bot) React(to Recipient, msg Editable, opts ...ReactionOptions) error {
43+
if to == nil {
44+
return ErrBadRecipient
45+
}
46+
msgID, _ := msg.MessageSig()
47+
48+
params := map[string]string{
49+
"chat_id": to.Recipient(),
50+
"message_id": msgID,
51+
}
52+
53+
if len(opts) > 0 {
54+
opt := opts[0]
55+
56+
if len(opt.Reactions) > 0 {
57+
data, _ := json.Marshal(opt.Reactions)
58+
params["reaction"] = string(data)
59+
}
60+
if opt.Big {
61+
params["is_big"] = "true"
62+
}
63+
}
64+
65+
_, err := b.Raw("setMessageReaction", params)
66+
return err
67+
}

react/reaction.go renamed to react/react.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
package react
22

3-
import "gopkg.in/telebot.v3"
3+
import (
4+
tele "gopkg.in/telebot.v3"
5+
)
6+
7+
type Reaction = tele.Reaction
48

5-
type Reaction = telebot.Reaction
9+
func React(r ...Reaction) tele.ReactionOptions {
10+
return tele.ReactionOptions{Reactions: r}
11+
}
612

713
// Currently available emojis.
814
var (

0 commit comments

Comments
 (0)