Skip to content

Commit e807487

Browse files
committed
examples/receive-and-send: 补充设置公告用例
1 parent aaa839a commit e807487

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

examples/receive-and-send/process.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ type Processor struct {
1616
}
1717

1818
func (p Processor) ProcessMessage(input string, data *dto.WSATMessageData) error {
19+
ctx := context.Background()
1920
cmd := message.ParseCommand(input)
2021
toCreate := &dto.MessageToCreate{
2122
Content: "默认回复 <emoji:37>",
@@ -32,6 +33,7 @@ func (p Processor) ProcessMessage(input string, data *dto.WSATMessageData) error
3233
}
3334

3435
var reply bool
36+
var announcement bool
3537
switch cmd.Cmd {
3638
case "time":
3739
toCreate.Content = genReplyContent(data)
@@ -41,12 +43,21 @@ func (p Processor) ProcessMessage(input string, data *dto.WSATMessageData) error
4143
reply = true
4244
case "hi":
4345
reply = true
46+
case "公告":
47+
announcement = true
4448
default:
4549
}
46-
fmt.Println("1111111", reply, []byte(cmd.Cmd), len(cmd.Cmd))
4750
// 是否命中上面的指令,不回复多余的内容
4851
if reply {
49-
if _, err := p.api.PostMessage(context.Background(), data.ChannelID, toCreate); err != nil {
52+
if _, err := p.api.PostMessage(ctx, data.ChannelID, toCreate); err != nil {
53+
log.Println(err)
54+
}
55+
}
56+
if announcement {
57+
if _, err := p.api.CreateChannelAnnounces(
58+
ctx, data.ChannelID,
59+
&dto.ChannelAnnouncesToCreate{MessageID: data.ID},
60+
); err != nil {
5061
log.Println(err)
5162
}
5263
}

0 commit comments

Comments
 (0)