feat: Add DiscommandStruct.messageRuns
This commit is contained in:
parent
4ac0ab6a77
commit
965a976d44
3 changed files with 24 additions and 12 deletions
|
@ -4,6 +4,8 @@ import (
|
|||
"github.com/bwmarrin/discordgo"
|
||||
)
|
||||
|
||||
// type messageRun func(s *discordgo.Session, m *discordgo.MessageCreate)
|
||||
|
||||
type DetailedDescription struct {
|
||||
Usage string
|
||||
Examples []string
|
||||
|
@ -17,17 +19,21 @@ type Command struct {
|
|||
}
|
||||
|
||||
type DiscommandStruct struct {
|
||||
Commands map[string]Command
|
||||
Aliases map[string]string
|
||||
Commands map[string]Command
|
||||
Aliases map[string]string
|
||||
messageRuns map[string]interface{}
|
||||
}
|
||||
|
||||
func new() *DiscommandStruct {
|
||||
discommand := DiscommandStruct{
|
||||
Commands: map[string]Command{},
|
||||
Aliases: map[string]string{},
|
||||
Commands: map[string]Command{},
|
||||
Aliases: map[string]string{},
|
||||
messageRuns: map[string]interface{}{},
|
||||
}
|
||||
|
||||
discommand.loadCommands(HelpCommand)
|
||||
|
||||
discommand.addMessageRun(HelpCommand.Name, HelpCommand.helpMessageRun)
|
||||
return &discommand
|
||||
}
|
||||
|
||||
|
@ -40,12 +46,13 @@ func (d *DiscommandStruct) loadCommands(command Command) {
|
|||
}
|
||||
}
|
||||
|
||||
func (d *DiscommandStruct) addMessageRun(name string, run func(s *discordgo.Session, m *discordgo.MessageCreate)) {
|
||||
d.messageRuns[name] = run
|
||||
}
|
||||
|
||||
func (d *DiscommandStruct) MessageRun(command string, s *discordgo.Session, m *discordgo.MessageCreate) {
|
||||
// 극한의 하드코딩 으아악
|
||||
switch command {
|
||||
case "도움말":
|
||||
HelpCommand.MessageRun(s, m)
|
||||
}
|
||||
// 더욱 나아진
|
||||
d.messageRuns[command].(func(s *discordgo.Session, m *discordgo.MessageCreate))(s, m)
|
||||
}
|
||||
|
||||
var Discommand *DiscommandStruct = new()
|
||||
|
|
|
@ -1,6 +1,10 @@
|
|||
package commands
|
||||
|
||||
import "github.com/bwmarrin/discordgo"
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/bwmarrin/discordgo"
|
||||
)
|
||||
|
||||
var HelpCommand Command = Command{
|
||||
Name: "도움말",
|
||||
|
@ -12,6 +16,7 @@ var HelpCommand Command = Command{
|
|||
},
|
||||
}
|
||||
|
||||
func (c *Command) MessageRun(s *discordgo.Session, m *discordgo.MessageCreate) {
|
||||
func (c *Command) helpMessageRun(s *discordgo.Session, m *discordgo.MessageCreate) {
|
||||
fmt.Println(c.Name)
|
||||
s.ChannelMessageSend(m.ChannelID, "asdf")
|
||||
}
|
||||
|
|
|
@ -8,7 +8,7 @@ import (
|
|||
"github.com/joho/godotenv"
|
||||
)
|
||||
|
||||
var MUFFIN_VERSION = "0.0.0-gopher_canary.250324a"
|
||||
var MUFFIN_VERSION = "0.0.0-gopher_canary.250325a"
|
||||
|
||||
type botConfig struct {
|
||||
Token string
|
||||
|
|
Loading…
Reference in a new issue