Skip to content

Commit 44ba38e

Browse files
committed
fix: 修复EventChannel中接收用c,打印用ctx问题
1 parent c55d27c commit 44ba38e

File tree

3 files changed

+23
-23
lines changed

3 files changed

+23
-23
lines changed

engine/robot/channel.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ func (n *EventChannel) Next() <-chan *Ctx {
4848
func (n *EventChannel) Repeat() (recv <-chan *Ctx, cancel func()) {
4949
ch, done := make(chan *Ctx, 1), make(chan struct{})
5050
go func() {
51-
defer close(ch)
5251
in := make(chan *Ctx, 1)
5352
matcher := StoreMatcher(&Matcher{
5453
Block: n.Block,
@@ -66,11 +65,12 @@ func (n *EventChannel) Repeat() (recv <-chan *Ctx, cancel func()) {
6665
case <-done:
6766
matcher.Delete()
6867
close(in)
68+
close(ch)
6969
return
7070
}
7171
}
7272
}()
7373
return ch, func() {
74-
close(done)
74+
done <- struct{}{}
7575
}
7676
}

plugins/chatgpt/main.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ type ApiKey struct {
3131
func init() {
3232
engine := control.Register("chatgpt", &control.Options[*robot.Ctx]{
3333
Alias: "ChatGPT",
34-
Help: "输入 {开始ChatGPT会话} => 进行ChatGPT连续会话",
34+
Help: "输入 {开始会话} => 进行ChatGPT连续会话",
3535
DataFolder: "chatgpt",
3636
OnDisable: func(ctx *robot.Ctx) {
3737
ctx.ReplyText("禁用成功")
@@ -76,8 +76,8 @@ func init() {
7676
chatCTXMap.LoadAndDelete(ctx.Event.FromUniqueID)
7777
ctx.ReplyText("已退出ChatGPT")
7878
return
79-
case c := <-recv:
80-
msg := c.MessageString()
79+
case ctx := <-recv:
80+
msg := ctx.MessageString()
8181
if msg == "" {
8282
continue
8383
} else if msg == "结束会话" {
@@ -106,9 +106,9 @@ func init() {
106106
continue
107107
}
108108
chatCTXMap.Store(ctx.Event.FromUniqueID, question+"\n"+answer)
109-
ctx.ReplyText(answer)
109+
ctx.ReplyTextAndAt(answer)
110110
} else {
111-
ctx.ReplyText(r)
111+
ctx.ReplyTextAndAt(r)
112112
}
113113
}
114114
}

plugins/manager/cronjob.go

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -147,10 +147,10 @@ func registerCronjob() {
147147
case <-time.After(20 * time.Second):
148148
ctx.ReplyTextAndAt("操作时间太久了,请重新设置")
149149
return
150-
case c := <-recv:
150+
case ctx := <-recv:
151151
jobId := mid.UniqueId()
152152
jobTag := strconv.Itoa(int(jobId))
153-
remind := c.MessageString()
153+
remind := ctx.MessageString()
154154

155155
// 设置定时任务
156156
if _, err := AddRemindOfEveryMonth(ctx, jobTag, matched, func() { ctx.ReplyText(remind) }); err != nil {
@@ -190,10 +190,10 @@ func registerCronjob() {
190190
case <-time.After(20 * time.Second):
191191
ctx.ReplyTextAndAt("操作时间太久了,请重新设置")
192192
return
193-
case c := <-recv:
193+
case ctx := <-recv:
194194
jobId := mid.UniqueId()
195195
jobTag := strconv.Itoa(int(jobId))
196-
remind := c.MessageString()
196+
remind := ctx.MessageString()
197197

198198
// 设置定时任务
199199
if _, err := AddRemindOfEveryWeek(ctx, jobTag, matched, func() { ctx.ReplyText(remind) }); err != nil {
@@ -233,10 +233,10 @@ func registerCronjob() {
233233
case <-time.After(20 * time.Second):
234234
ctx.ReplyTextAndAt("操作时间太久了,请重新设置")
235235
return
236-
case c := <-recv:
236+
case ctx := <-recv:
237237
jobId := mid.UniqueId()
238238
jobTag := strconv.Itoa(int(jobId))
239-
remind := c.MessageString()
239+
remind := ctx.MessageString()
240240

241241
// 设置定时任务
242242
if _, err := AddRemindOfEveryDay(ctx, jobTag, matched, func() { ctx.ReplyText(remind) }); err != nil {
@@ -276,10 +276,10 @@ func registerCronjob() {
276276
case <-time.After(20 * time.Second):
277277
ctx.ReplyTextAndAt("操作时间太久了,请重新设置")
278278
return
279-
case c := <-recv:
279+
case ctx := <-recv:
280280
jobId := mid.UniqueId()
281281
jobTag := strconv.Itoa(int(jobId))
282-
remind := c.MessageString()
282+
remind := ctx.MessageString()
283283

284284
// 设置定时任务
285285
if _, err := AddRemindForInterval(ctx, jobTag, matched, func() { ctx.ReplyText(remind) }); err != nil {
@@ -319,10 +319,10 @@ func registerCronjob() {
319319
case <-time.After(20 * time.Second):
320320
ctx.ReplyTextAndAt("操作时间太久了,请重新设置")
321321
return
322-
case c := <-recv:
322+
case ctx := <-recv:
323323
jobId := mid.UniqueId()
324324
jobTag := strconv.Itoa(int(jobId))
325-
remind := c.MessageString()
325+
remind := ctx.MessageString()
326326

327327
// 设置定时任务
328328
if _, err := AddRemindForSpecifyTime(ctx, jobTag, matched, func() { ctx.ReplyText(remind) }); err != nil {
@@ -362,10 +362,10 @@ func registerCronjob() {
362362
case <-time.After(20 * time.Second):
363363
ctx.ReplyTextAndAt("操作时间太久了,请重新设置")
364364
return
365-
case c := <-recv:
365+
case ctx := <-recv:
366366
jobId := mid.UniqueId()
367367
jobTag := strconv.Itoa(int(jobId))
368-
remind := c.MessageString()
368+
remind := ctx.MessageString()
369369

370370
// 设置定时任务
371371
if _, err := AddRemindForExpression(ctx, jobTag, matched, func() { ctx.ReplyText(remind) }); err != nil {
@@ -410,19 +410,19 @@ func registerCronjob() {
410410
case <-time.After(20 * time.Second):
411411
ctx.ReplyTextAndAt("操作时间太久了,请重新设置")
412412
return
413-
case c := <-recv:
414-
s, ok := options[c.MessageString()]
413+
case ctx := <-recv:
414+
s, ok := options[ctx.MessageString()]
415415
if !ok {
416416
ctx.ReplyTextAndAt("没有这个插件服务,请重新设置")
417417
continue
418418
}
419419

420420
jobId := mid.UniqueId()
421421
jobTag := strconv.Itoa(int(jobId))
422-
service := c.MessageString()
422+
service := ctx.MessageString()
423423

424424
// 设置定时任务
425-
if _, err := AddPluginOfEveryDay(ctx, jobTag, matched, func() { s.Options.OnCronjob(c) }); err != nil {
425+
if _, err := AddPluginOfEveryDay(ctx, jobTag, matched, func() { s.Options.OnCronjob(ctx) }); err != nil {
426426
ctx.ReplyTextAndAt(fmt.Errorf("设置失败: %v", err).Error())
427427
return
428428
}

0 commit comments

Comments
 (0)