Two methods, one module
Embed goroku.Base and the lifecycle, storage, translator and client are already wired. Declare Name and Commands; override the rest only when you need it.
A module is a struct with a name and some commands. Everything else has a default.
package modules
import "goroku/goroku"
type HTML struct{ goroku.Base }
func (m *HTML) Name() string { return "HTML" }
func (m *HTML) Commands() map[string]goroku.CommandHandler {
return map[string]goroku.CommandHandler{"html": m.HTMLCmd}
}
func (m *HTML) HTMLCmd(msg *goroku.Message) error {
code := msg.ArgsOrReply()
if code == "" {
return msg.Answer(m.T("no_args", "❌ <b>Send text or reply to a message</b>"))
}
return msg.Answer(code)
}That is the complete file. .html <b>hi</b> renders bold text; replying to a message with .html renders that message instead.
| You want to | Read |
|---|---|
| Get something working in five minutes | Your first module |
| Understand what each method is for | Anatomy of a module |
| Restrict a command to groups, admins, or replies | CommandMeta |
| Persist data between restarts | Storage |
| Let users configure your module | Configuration |
| Ship it to other people | Installing a module |