Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var Plugin = absdk.Define(absdk.Spec[Config]{ Manifest: absdk.Manifest{Name: "groupmemo_example", Version: "0.1.0", Description: "群便签插件示例"}, DefaultConfig: Config{ ViewCommand: "memo", SetCommand: "remember", AllowedGroups: nil, Admins: nil, }, Setup: func(ctx *absdk.Context, cfg Config) error { groupRules := []absdk.Rule{absdk.Group(), absdk.AllowedGroups(cfg.AllowedGroups...)} ctx.OnMessage(append(groupRules, absdk.CommandRule(cfg.ViewCommand))...). Name("memo.view"). Handle(func(c *absdk.EventContext) error { state, err := absdk.GroupState[memoState](ctx, c, "memo").LoadOr(memoState{}) if err != nil { return err } text := strings.TrimSpace(state.Text) if text == "" { text = "这个群还没有便签。" } _, err = c.ReplyText(text) return err }) ctx.OnMessage(append(groupRules, absdk.CommandRule(cfg.SetCommand))...). Name("memo.set"). Use(absdk.RequireAdmin(cfg.Admins...)). Handle(func(c *absdk.EventContext) error { text := strings.TrimSpace(c.Args()) if text == "" { _, err := c.ReplyText("用法:/" + cfg.SetCommand + " <便签内容>") return err } if err := absdk.GroupState[memoState](ctx, c, "memo").Save(memoState{Text: text}, 0); err != nil { return err } _, err := c.ReplyText("群便签已更新。") return err }) return nil }, })
Functions ¶
This section is empty.
Types ¶
Click to show internal directories.
Click to hide internal directories.