From 4cf4b42989ee242d0cba7919a58ebc86919f0c82 Mon Sep 17 00:00:00 2001 From: Siwoo Jeon Date: Sat, 24 May 2025 16:31:26 +0900 Subject: [PATCH] feat: learn command componentsV2 --- commands/learn.go | 68 +++++++++++++++++---------------------------- configs/version.go | 2 +- utils/embed.go | 35 +++++++++++++++++++++++ utils/embedColor.go | 7 ----- 4 files changed, 62 insertions(+), 50 deletions(-) create mode 100644 utils/embed.go delete mode 100644 utils/embedColor.go diff --git a/commands/learn.go b/commands/learn.go index f3fb690..75dfaf8 100644 --- a/commands/learn.go +++ b/commands/learn.go @@ -60,27 +60,21 @@ var LearnCommand *Command = &Command{ MessageRun: func(ctx *MsgContext) { if len(*ctx.Args) < 2 { utils.NewMessageSender(ctx.Msg). - AddEmbeds(&discordgo.MessageEmbed{ - Title: "❌ 오류", - Description: "올바르지 않ㅇ은 용법이에요.", - Fields: []*discordgo.MessageEmbedField{ - { - Name: "사용법", - Value: utils.InlineCode(ctx.Command.DetailedDescription.Usage), - Inline: true, - }, - { - Name: "사용 가능한 인자", - Value: learnArguments, - Inline: true, - }, - { - Name: "예시", - Value: utils.CodeBlock("md", strings.Join(utils.AddPrefix("- ", ctx.Command.DetailedDescription.Examples), "\n")), - }, + AddComponents(utils.GetErrorContainer( + discordgo.TextDisplay{ + Content: "올바르지 않ㅇ은 용법이에요.", }, - Color: utils.EmbedFail, - }). + discordgo.TextDisplay{ + Content: fmt.Sprintf("- **사용법**\n> %s", ctx.Command.DetailedDescription.Usage), + }, + discordgo.TextDisplay{ + Content: fmt.Sprintf("- **예시**\n%s", strings.Join(utils.AddPrefix("> ", ctx.Command.DetailedDescription.Examples), "\n")), + }, + discordgo.TextDisplay{ + Content: fmt.Sprintf("- **사용 가능한 인자**\n%s", learnArguments), + }, + )). + SetComponentsV2(true). SetReply(true). Send() return @@ -127,12 +121,8 @@ func learnRun(m any, userId, command, result string) { for _, ig := range ignores { if strings.Contains(command, ig) { utils.NewMessageSender(m). - AddEmbeds( - &discordgo.MessageEmbed{ - Title: "❌ 오류", - Description: "해ㄷ당 단어는 배우기 껄끄ㄹ럽네요.", - Color: utils.EmbedFail, - }). + AddComponents(utils.GetErrorContainer(discordgo.TextDisplay{Content: "해ㄷ당 단어는 배우기 껄끄ㄹ럽네요."})). + SetComponentsV2(true). SetReply(true). Send() return @@ -142,12 +132,8 @@ func learnRun(m any, userId, command, result string) { for _, di := range disallows { if strings.Contains(result, di) { utils.NewMessageSender(m). - AddEmbeds( - &discordgo.MessageEmbed{ - Title: "❌ 오류", - Description: "해당 단ㅇ어의 대답으로 하기 좀 그렇ㄴ네요.", - Color: utils.EmbedFail, - }). + AddComponents(utils.GetErrorContainer(discordgo.TextDisplay{Content: "해당 단ㅇ어의 대답으로 하기 좀 그렇ㄴ네요."})). + SetComponentsV2(true). SetReply(true). Send() return @@ -164,22 +150,20 @@ func learnRun(m any, userId, command, result string) { log.Println(err) utils.NewMessageSender(m). - AddEmbeds(&discordgo.MessageEmbed{ - Title: "❌ 오류", - Description: "단어를 배우는데 오류가 생겼어요.", - Color: utils.EmbedFail, - }). + AddComponents(utils.GetErrorContainer(discordgo.TextDisplay{Content: "단어를 배우는데 오류가 생겼어요."})). + SetComponentsV2(true). SetReply(true). Send() return } utils.NewMessageSender(m). - AddEmbeds(&discordgo.MessageEmbed{ - Title: "✅ 성공", - Description: fmt.Sprintf("%s 배웠어요.", hangul.GetJosa(command, hangul.EUL_REUL)), - Color: utils.EmbedSuccess, - }). + AddComponents(utils.GetSuccessContainer( + discordgo.TextDisplay{ + Content: fmt.Sprintf("%s 배웠어요.", hangul.GetJosa(command, hangul.EUL_REUL)), + }, + )). + SetComponentsV2(true). SetReply(true). Send() } diff --git a/configs/version.go b/configs/version.go index c543835..bf28453 100644 --- a/configs/version.go +++ b/configs/version.go @@ -7,7 +7,7 @@ import ( "git.wh64.net/muffin/goMuffin/utils" ) -const MUFFIN_VERSION = "0.0.0-souffle_canary.250523a-componentsv2" +const MUFFIN_VERSION = "0.0.0-souffle_canary.250524a-componentsv2" var updatedString string = utils.RegexpDecimals.FindAllStringSubmatch(MUFFIN_VERSION, -1)[3][0] diff --git a/utils/embed.go b/utils/embed.go new file mode 100644 index 0000000..4093445 --- /dev/null +++ b/utils/embed.go @@ -0,0 +1,35 @@ +package utils + +import "github.com/bwmarrin/discordgo" + +const ( + EmbedDefault int = 0xaddb87 + EmbedFail int = 0xff0000 + EmbedSuccess int = 0x00ff00 +) + +func GetErrorContainer(components ...discordgo.MessageComponent) *discordgo.Container { + c := &discordgo.Container{ + Components: []discordgo.MessageComponent{ + discordgo.TextDisplay{ + Content: "### ❌ 오류", + }, + }, + } + + c.Components = append(c.Components, components...) + return c +} + +func GetSuccessContainer(components ...discordgo.MessageComponent) *discordgo.Container { + c := &discordgo.Container{ + Components: []discordgo.MessageComponent{ + discordgo.TextDisplay{ + Content: "### ✅ 성공", + }, + }, + } + + c.Components = append(c.Components, components...) + return c +} diff --git a/utils/embedColor.go b/utils/embedColor.go deleted file mode 100644 index acbaa91..0000000 --- a/utils/embedColor.go +++ /dev/null @@ -1,7 +0,0 @@ -package utils - -const ( - EmbedDefault int = 0xaddb87 - EmbedFail int = 0xff0000 - EmbedSuccess int = 0x00ff00 -)