package laniakea type CommandExecutor func(ctx *MsgContext) type PluginBuilder struct { name string commands map[string]*CommandExecutor payload string } type Plugin struct { Name string Commands map[string]*CommandExecutor Payload string } func NewPlugin(name string) *PluginBuilder { return &PluginBuilder{ name: name, commands: make(map[string]*CommandExecutor), } } func (p *PluginBuilder) Command(cmd string, f CommandExecutor) *PluginBuilder { p.commands[cmd] = &f return p } func (p *PluginBuilder) Payload(payload string) *PluginBuilder { p.payload = payload return p } func (p *PluginBuilder) Build() *Plugin { if len(p.commands) == 0 { return nil } plugin := &Plugin{ Name: p.name, Commands: p.commands, Payload: p.payload, } return plugin } func (p *Plugin) Execute(cmd string, ctx *MsgContext) { (*p.Commands[cmd])(ctx) }