groupmemo

package
v1.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 11, 2026 License: MIT Imports: 3 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

groupmemo

群便签插件示例:管理员用 /remember <内容> 更新当前群便签,群友用 /memo 查看。

示例覆盖:

  • AllowedGroups 群白名单。
  • RequireAdmin 管理员权限。
  • GroupState[T] 群维度 typed state。

在仓库根目录本地测试:

go test ./examples/plugins/groupmemo

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

type Config

type Config struct {
	ViewCommand   string   `yaml:"view_command"`
	SetCommand    string   `yaml:"set_command"`
	AllowedGroups []string `yaml:"allowed_groups"`
	Admins        []string `yaml:"admins"`
}

func (Config) Validate

func (cfg Config) Validate() error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL