MCPcopy Index your code
hub / github.com/FloatTech/ZeroBot-Plugin / init

Function init

plugin/llm/main.go:45–227  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

43)
44
45func init() {
46 // 添加群聊总结功能
47 en.OnRegex(`^群聊总结\s?(\d*)$`, chat.EnsureConfig, zero.OnlyGroup, zero.AdminPermission).SetBlock(true).Limit(limit.LimitByGroup).Handle(func(ctx *zero.Ctx) {
48 ctx.SendChain(message.Text("少女思考中..."))
49 gid := ctx.Event.GroupID
50 if gid == 0 {
51 gid = -ctx.Event.UserID
52 }
53 p, _ := strconv.ParseInt(ctx.State["regex_matched"].([]string)[1], 10, 64)
54 if p > 1000 {
55 p = 1000
56 }
57 if p == 0 {
58 p = 200
59 }
60 group := ctx.GetGroupInfo(gid, false)
61 if group.MemberCount == 0 {
62 ctx.SendChain(message.Text(zero.BotConfig.NickName[0], "未加入", group.Name, "(", gid, "),无法获取总结"))
63 return
64 }
65
66 var messages []string
67
68 h := ctx.GetGroupMessageHistory(gid, 0, p, false)
69 h.Get("messages").ForEach(func(_, msgObj gjson.Result) bool {
70 nickname := msgObj.Get("sender.nickname").Str
71 text := strings.TrimSpace(message.ParseMessageFromString(msgObj.Get("raw_message").Str).ExtractPlainText())
72 if text != "" {
73 messages = append(messages, nickname+": "+text)
74 }
75 return true
76 })
77
78 if len(messages) == 0 {
79 ctx.SendChain(message.Text("ERROR: 历史消息为空或者无法获得历史消息"))
80 return
81 }
82
83 // 构造总结请求提示 (使用通用版省流提示词)
84 // 使用反引号定义多行字符串,更清晰
85 promptTemplate := `请对以下群聊对话进行【极简总结】。
86要求:
871. 剔除客套与废话,直击主题。
882. 使用 Markdown 列表格式。
893. 按以下结构输出:
90 - 🎯 核心议题:(一句话概括)
91 - 💡 关键观点/结论:(提取3-5个重点)
92 - ✅ 下一步/待办:(如果有,明确谁做什么)
93
94群聊对话内容如下:
95`
96 summaryPrompt := promptTemplate + strings.Join(messages, "\n")
97
98 stor, err := chat.NewStorage(ctx, gid)
99 if err != nil {
100 ctx.SendChain(message.Text("ERROR: ", err))
101 return
102 }

Callers

nothing calls this directly

Calls 2

llmchatFunction · 0.85
StringMethod · 0.45

Tested by

no test coverage detected