Compare commits
2 commits
2e12ff158d
...
ebcfe54cf0
Author | SHA1 | Date | |
---|---|---|---|
ebcfe54cf0 | |||
1ec391d478 |
5 changed files with 77 additions and 6 deletions
49
commands/discommand.go
Normal file
49
commands/discommand.go
Normal file
|
@ -0,0 +1,49 @@
|
||||||
|
package commands
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/bwmarrin/discordgo"
|
||||||
|
)
|
||||||
|
|
||||||
|
type DetailedDescription struct {
|
||||||
|
Usage string
|
||||||
|
Examples []string
|
||||||
|
}
|
||||||
|
|
||||||
|
type Command struct {
|
||||||
|
Name string
|
||||||
|
Aliases []string
|
||||||
|
Description string
|
||||||
|
DetailedDescription DetailedDescription
|
||||||
|
}
|
||||||
|
|
||||||
|
type DiscommandStruct struct {
|
||||||
|
Commands map[string]Command
|
||||||
|
Aliases map[string]string
|
||||||
|
}
|
||||||
|
|
||||||
|
func new() *DiscommandStruct {
|
||||||
|
discommand := DiscommandStruct{}
|
||||||
|
discommand.Commands = make(map[string]Command)
|
||||||
|
discommand.Aliases = make(map[string]string)
|
||||||
|
discommand.loadCommands(HelpCommand)
|
||||||
|
return &discommand
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *DiscommandStruct) loadCommands(command Command) {
|
||||||
|
d.Commands[command.Name] = command
|
||||||
|
d.Aliases[command.Name] = command.Name
|
||||||
|
|
||||||
|
for _, alias := range command.Aliases {
|
||||||
|
d.Aliases[alias] = command.Name
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *DiscommandStruct) MessageRun(command string, s *discordgo.Session, m *discordgo.MessageCreate) {
|
||||||
|
// 극한의 하드코딩 으아악
|
||||||
|
switch command {
|
||||||
|
case "도움말":
|
||||||
|
HelpCommand.MessageRun(s, m)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var Discommand *DiscommandStruct = new()
|
17
commands/help.go
Normal file
17
commands/help.go
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
package commands
|
||||||
|
|
||||||
|
import "github.com/bwmarrin/discordgo"
|
||||||
|
|
||||||
|
var HelpCommand Command = Command{
|
||||||
|
Name: "도움말",
|
||||||
|
Aliases: []string{"도움", "명령어", "help"},
|
||||||
|
Description: "기본적인 사용ㅂ법이에요.",
|
||||||
|
DetailedDescription: DetailedDescription{
|
||||||
|
Usage: "머핀아 도움말 [명령어]",
|
||||||
|
Examples: []string{"머핀아 도움말", "머핀아 도움말 배워"},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Command) MessageRun(s *discordgo.Session, m *discordgo.MessageCreate) {
|
||||||
|
s.ChannelMessageSend(m.ChannelID, "asdf")
|
||||||
|
}
|
2
go.mod
2
go.mod
|
@ -1,4 +1,4 @@
|
||||||
module gitlab.wh64.net/muffin/goMuffin
|
module git.wh64.net/muffin/goMuffin
|
||||||
|
|
||||||
go 1.23.2
|
go 1.23.2
|
||||||
|
|
||||||
|
|
|
@ -3,8 +3,9 @@ package handler
|
||||||
import (
|
import (
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"git.wh64.net/muffin/goMuffin/commands"
|
||||||
|
"git.wh64.net/muffin/goMuffin/configs"
|
||||||
"github.com/bwmarrin/discordgo"
|
"github.com/bwmarrin/discordgo"
|
||||||
"gitlab.wh64.net/muffin/goMuffin/configs"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// MessageCreate is handlers of messageCreate event
|
// MessageCreate is handlers of messageCreate event
|
||||||
|
@ -16,9 +17,13 @@ func MessageCreate(s *discordgo.Session, m *discordgo.MessageCreate) {
|
||||||
|
|
||||||
if strings.HasPrefix(m.Content, config.Prefix) {
|
if strings.HasPrefix(m.Content, config.Prefix) {
|
||||||
content := strings.TrimPrefix(m.Content, config.Prefix)
|
content := strings.TrimPrefix(m.Content, config.Prefix)
|
||||||
if content == "안녕" {
|
command := commands.Discommand.Aliases[content]
|
||||||
s.ChannelMessageSend(m.ChannelID, "안녕")
|
|
||||||
|
if command == "" {
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
commands.Discommand.MessageRun(command, s, m)
|
||||||
} else {
|
} else {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
4
main.go
4
main.go
|
@ -7,9 +7,9 @@ import (
|
||||||
"os/signal"
|
"os/signal"
|
||||||
"syscall"
|
"syscall"
|
||||||
|
|
||||||
|
"git.wh64.net/muffin/goMuffin/configs"
|
||||||
|
"git.wh64.net/muffin/goMuffin/handler"
|
||||||
"github.com/bwmarrin/discordgo"
|
"github.com/bwmarrin/discordgo"
|
||||||
"gitlab.wh64.net/muffin/goMuffin/configs"
|
|
||||||
"gitlab.wh64.net/muffin/goMuffin/handler"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|
Loading…
Reference in a new issue