From c8f45183f658e61b2a6ada2d1f9ad25e2283be62 Mon Sep 17 00:00:00 2001 From: "Gustavo L de Mello (Guz)" Date: Thu, 21 Nov 2024 21:24:46 -0300 Subject: [PATCH] feat(lib,commands): Command interface --- lib/bot.go | 5 +++++ lib/command.go | 22 ++++++++++++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 lib/command.go diff --git a/lib/bot.go b/lib/bot.go index ac4d4b0..38604c6 100644 --- a/lib/bot.go +++ b/lib/bot.go @@ -6,6 +6,7 @@ import ( type Bot struct { session *discordgo.Session + commands []Command } func New(token string) (*Bot, error) { @@ -29,3 +30,7 @@ func (b *Bot) Start() error { return nil } + +func (b *Bot) HandleCommand(c Command) { + b.commands = append(b.commands, c) +} diff --git a/lib/command.go b/lib/command.go new file mode 100644 index 0000000..63fcbea --- /dev/null +++ b/lib/command.go @@ -0,0 +1,22 @@ +package bot + +import "github.com/bwmarrin/discordgo" + +type Command interface { + ApplicationCommand() *discordgo.ApplicationCommand + Validate() (bool, error) +} + +type Handler interface { + Handle(s *discordgo.Session, ic *discordgo.InteractionCreate) error +} + +type HandlerFunc func(s *discordgo.Session, ic *discordgo.InteractionCreate) error + +func (h HandlerFunc) Handle( + s *discordgo.Session, + ic *discordgo.InteractionCreate, +) error { + return h(s, ic) +} +