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"
|
"github.com/bwmarrin/discordgo"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// type messageRun func(s *discordgo.Session, m *discordgo.MessageCreate)
|
||||||
|
|
||||||
type DetailedDescription struct {
|
type DetailedDescription struct {
|
||||||
Usage string
|
Usage string
|
||||||
Examples []string
|
Examples []string
|
||||||
|
@ -17,17 +19,21 @@ type Command struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type DiscommandStruct struct {
|
type DiscommandStruct struct {
|
||||||
Commands map[string]Command
|
Commands map[string]Command
|
||||||
Aliases map[string]string
|
Aliases map[string]string
|
||||||
|
messageRuns map[string]interface{}
|
||||||
}
|
}
|
||||||
|
|
||||||
func new() *DiscommandStruct {
|
func new() *DiscommandStruct {
|
||||||
discommand := DiscommandStruct{
|
discommand := DiscommandStruct{
|
||||||
Commands: map[string]Command{},
|
Commands: map[string]Command{},
|
||||||
Aliases: map[string]string{},
|
Aliases: map[string]string{},
|
||||||
|
messageRuns: map[string]interface{}{},
|
||||||
}
|
}
|
||||||
|
|
||||||
discommand.loadCommands(HelpCommand)
|
discommand.loadCommands(HelpCommand)
|
||||||
|
|
||||||
|
discommand.addMessageRun(HelpCommand.Name, HelpCommand.helpMessageRun)
|
||||||
return &discommand
|
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) {
|
func (d *DiscommandStruct) MessageRun(command string, s *discordgo.Session, m *discordgo.MessageCreate) {
|
||||||
// 극한의 하드코딩 으아악
|
// 더욱 나아진
|
||||||
switch command {
|
d.messageRuns[command].(func(s *discordgo.Session, m *discordgo.MessageCreate))(s, m)
|
||||||
case "도움말":
|
|
||||||
HelpCommand.MessageRun(s, m)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var Discommand *DiscommandStruct = new()
|
var Discommand *DiscommandStruct = new()
|
||||||
|
|
|
@ -1,6 +1,10 @@
|
||||||
package commands
|
package commands
|
||||||
|
|
||||||
import "github.com/bwmarrin/discordgo"
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/bwmarrin/discordgo"
|
||||||
|
)
|
||||||
|
|
||||||
var HelpCommand Command = Command{
|
var HelpCommand Command = Command{
|
||||||
Name: "도움말",
|
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")
|
s.ChannelMessageSend(m.ChannelID, "asdf")
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,7 +8,7 @@ import (
|
||||||
"github.com/joho/godotenv"
|
"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 {
|
type botConfig struct {
|
||||||
Token string
|
Token string
|
||||||
|
|
Loading…
Reference in a new issue