This repository has been archived by the owner on Dec 31, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
/
event_context_helper.go
87 lines (77 loc) · 2.24 KB
/
event_context_helper.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package kook
// Reply is a helper function for replying to a message.
//
// It accept optional MessageCreateOption, DirectMessageCreateOption and ReplyOption arguments.
func (c *TextMessageContext) Reply(text string, options ...interface{}) (*MessageResp, error) {
if c.Common.ChannelType == "PERSON" {
dmc := &DirectMessageCreate{
ChatCode: c.Common.TargetID,
MessageCreateBase: MessageCreateBase{
Quote: c.Common.MsgID,
Content: text,
},
}
for _, item := range options {
switch v := item.(type) {
case DirectMessageCreateOption:
v(dmc)
default:
}
}
return c.Session.DirectMessageCreate(dmc)
}
mc := &MessageCreate{
MessageCreateBase: MessageCreateBase{
Quote: c.Common.MsgID,
Content: text,
TargetID: c.Common.TargetID,
},
}
for _, item := range options {
switch v := item.(type) {
case MessageCreateOption:
v(mc)
case ReplyOption:
switch v {
case ReplyOptionTemp:
mc.TempTargetID = c.Extra.Author.ID
}
default:
}
}
return c.Session.MessageCreate(mc)
}
// MessageCreateOption is the type for decorator of MessageCreate.
type MessageCreateOption func(*MessageCreate)
// MessageCreateWithKmarkdown changes message type to Kmarkdown.
func MessageCreateWithKmarkdown() MessageCreateOption {
return func(mc *MessageCreate) {
mc.Type = MessageTypeKMarkdown
}
}
// MessageCreateWithCard changes message type to card.
func MessageCreateWithCard() MessageCreateOption {
return func(mc *MessageCreate) {
mc.Type = MessageTypeCard
}
}
// DirectMessageCreateOption is the type for decorator of DirectMessageCreate.
type DirectMessageCreateOption func(*DirectMessageCreate)
// DirectMessageCreateWithKmarkdown changes message type to Kmarkdown.
func DirectMessageCreateWithKmarkdown() DirectMessageCreateOption {
return func(mc *DirectMessageCreate) {
mc.Type = MessageTypeKMarkdown
}
}
// DirectMessageCreateWithCard changes message type to card.
func DirectMessageCreateWithCard() DirectMessageCreateOption {
return func(mc *DirectMessageCreate) {
mc.Type = MessageTypeCard
}
}
// ReplyOption is the type providing additional options to Message event reply.
type ReplyOption string
const (
// ReplyOptionTemp let reply temporary.
ReplyOptionTemp ReplyOption = "reply_option_temp"
)