feat(lib,commands): Command interface

This commit is contained in:
Guz
2024-11-21 21:24:46 -03:00
parent ac523cba73
commit c8f45183f6
2 changed files with 27 additions and 0 deletions

View File

@@ -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)
}

22
lib/command.go Normal file
View File

@@ -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)
}