Skip to content

Commit

Permalink
fix: 修复EventChannel中接收用c,打印用ctx问题
Browse files Browse the repository at this point in the history
  • Loading branch information
yqchilde committed Feb 6, 2023
1 parent c55d27c commit 44ba38e
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 23 deletions.
4 changes: 2 additions & 2 deletions engine/robot/channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ func (n *EventChannel) Next() <-chan *Ctx {
func (n *EventChannel) Repeat() (recv <-chan *Ctx, cancel func()) {
ch, done := make(chan *Ctx, 1), make(chan struct{})
go func() {
defer close(ch)
in := make(chan *Ctx, 1)
matcher := StoreMatcher(&Matcher{
Block: n.Block,
Expand All @@ -66,11 +65,12 @@ func (n *EventChannel) Repeat() (recv <-chan *Ctx, cancel func()) {
case <-done:
matcher.Delete()
close(in)
close(ch)
return
}
}
}()
return ch, func() {
close(done)
done <- struct{}{}
}
}
10 changes: 5 additions & 5 deletions plugins/chatgpt/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ type ApiKey struct {
func init() {
engine := control.Register("chatgpt", &control.Options[*robot.Ctx]{
Alias: "ChatGPT",
Help: "输入 {开始ChatGPT会话} => 进行ChatGPT连续会话",
Help: "输入 {开始会话} => 进行ChatGPT连续会话",
DataFolder: "chatgpt",
OnDisable: func(ctx *robot.Ctx) {
ctx.ReplyText("禁用成功")
Expand Down Expand Up @@ -76,8 +76,8 @@ func init() {
chatCTXMap.LoadAndDelete(ctx.Event.FromUniqueID)
ctx.ReplyText("已退出ChatGPT")
return
case c := <-recv:
msg := c.MessageString()
case ctx := <-recv:
msg := ctx.MessageString()
if msg == "" {
continue
} else if msg == "结束会话" {
Expand Down Expand Up @@ -106,9 +106,9 @@ func init() {
continue
}
chatCTXMap.Store(ctx.Event.FromUniqueID, question+"\n"+answer)
ctx.ReplyText(answer)
ctx.ReplyTextAndAt(answer)
} else {
ctx.ReplyText(r)
ctx.ReplyTextAndAt(r)
}
}
}
Expand Down
32 changes: 16 additions & 16 deletions plugins/manager/cronjob.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,10 @@ func registerCronjob() {
case <-time.After(20 * time.Second):
ctx.ReplyTextAndAt("操作时间太久了,请重新设置")
return
case c := <-recv:
case ctx := <-recv:
jobId := mid.UniqueId()
jobTag := strconv.Itoa(int(jobId))
remind := c.MessageString()
remind := ctx.MessageString()

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

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

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

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

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

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

jobId := mid.UniqueId()
jobTag := strconv.Itoa(int(jobId))
service := c.MessageString()
service := ctx.MessageString()

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

0 comments on commit 44ba38e

Please sign in to comment.