diff --git a/handler/messageCreate.go b/handler/messageCreate.go index ec101ee..962330e 100644 --- a/handler/messageCreate.go +++ b/handler/messageCreate.go @@ -1,15 +1,23 @@ package handler import ( + "strings" + "github.com/bwmarrin/discordgo" ) +// MessageCreate is handlers of messageCreate event func MessageCreate(s *discordgo.Session, m *discordgo.MessageCreate) { if m.Author.ID == s.State.User.ID && m.Author.Bot { return } - if m.Content == "!ping" { - s.ChannelMessageSend(m.ChannelID, "Pong!") + if strings.HasPrefix(m.Content, "머핀아 ") { + content := strings.TrimPrefix(m.Content, "머핀아 ") + if content == "안녕" { + s.ChannelMessageSend(m.ChannelID, "안녕") + } + } else { + return } } diff --git a/main.go b/main.go index 949c91b..12d60a5 100644 --- a/main.go +++ b/main.go @@ -9,18 +9,12 @@ import ( "github.com/Muffin-laboratory/goMuffin/handler" "github.com/bwmarrin/discordgo" - "github.com/joho/godotenv" ) func main() { - err := godotenv.Load() - token := os.Getenv("TOKEN") - if err != nil { - fmt.Println("[goMuffin] 봇의 설절파일을 불러올 수가 없어요.") - log.Fatalln(err) - } + config := LoadConfig() - dg, err := discordgo.New("Bot " + token) + dg, err := discordgo.New("Bot " + config.token) if err != nil { fmt.Println("[goMuffin] 봇의 세션을 만들수가 없어요.") log.Fatalln(err) @@ -35,6 +29,5 @@ func main() { signal.Notify(sc, syscall.SIGINT, syscall.SIGTERM, os.Interrupt) <-sc - // Cleanly close down the Discord session. dg.Close() }