feat(lib,commands): Command interface
This commit is contained in:
@@ -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
22
lib/command.go
Normal 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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user