feat: learn command componentsV2

This commit is contained in:
Siwoo Jeon 2025-05-24 16:31:26 +09:00
parent 3a5cfd6a58
commit 4cf4b42989
Signed by: migan
GPG key ID: 036E9A8C5E8E48DA
4 changed files with 62 additions and 50 deletions

View file

@ -60,27 +60,21 @@ var LearnCommand *Command = &Command{
MessageRun: func(ctx *MsgContext) { MessageRun: func(ctx *MsgContext) {
if len(*ctx.Args) < 2 { if len(*ctx.Args) < 2 {
utils.NewMessageSender(ctx.Msg). utils.NewMessageSender(ctx.Msg).
AddEmbeds(&discordgo.MessageEmbed{ AddComponents(utils.GetErrorContainer(
Title: "❌ 오류", discordgo.TextDisplay{
Description: "올바르지 않ㅇ은 용법이에요.", Content: "올바르지 않ㅇ은 용법이에요.",
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")),
},
}, },
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). SetReply(true).
Send() Send()
return return
@ -127,12 +121,8 @@ func learnRun(m any, userId, command, result string) {
for _, ig := range ignores { for _, ig := range ignores {
if strings.Contains(command, ig) { if strings.Contains(command, ig) {
utils.NewMessageSender(m). utils.NewMessageSender(m).
AddEmbeds( AddComponents(utils.GetErrorContainer(discordgo.TextDisplay{Content: "해ㄷ당 단어는 배우기 껄끄ㄹ럽네요."})).
&discordgo.MessageEmbed{ SetComponentsV2(true).
Title: "❌ 오류",
Description: "해ㄷ당 단어는 배우기 껄끄ㄹ럽네요.",
Color: utils.EmbedFail,
}).
SetReply(true). SetReply(true).
Send() Send()
return return
@ -142,12 +132,8 @@ func learnRun(m any, userId, command, result string) {
for _, di := range disallows { for _, di := range disallows {
if strings.Contains(result, di) { if strings.Contains(result, di) {
utils.NewMessageSender(m). utils.NewMessageSender(m).
AddEmbeds( AddComponents(utils.GetErrorContainer(discordgo.TextDisplay{Content: "해당 단ㅇ어의 대답으로 하기 좀 그렇ㄴ네요."})).
&discordgo.MessageEmbed{ SetComponentsV2(true).
Title: "❌ 오류",
Description: "해당 단ㅇ어의 대답으로 하기 좀 그렇ㄴ네요.",
Color: utils.EmbedFail,
}).
SetReply(true). SetReply(true).
Send() Send()
return return
@ -164,22 +150,20 @@ func learnRun(m any, userId, command, result string) {
log.Println(err) log.Println(err)
utils.NewMessageSender(m). utils.NewMessageSender(m).
AddEmbeds(&discordgo.MessageEmbed{ AddComponents(utils.GetErrorContainer(discordgo.TextDisplay{Content: "단어를 배우는데 오류가 생겼어요."})).
Title: "❌ 오류", SetComponentsV2(true).
Description: "단어를 배우는데 오류가 생겼어요.",
Color: utils.EmbedFail,
}).
SetReply(true). SetReply(true).
Send() Send()
return return
} }
utils.NewMessageSender(m). utils.NewMessageSender(m).
AddEmbeds(&discordgo.MessageEmbed{ AddComponents(utils.GetSuccessContainer(
Title: "✅ 성공", discordgo.TextDisplay{
Description: fmt.Sprintf("%s 배웠어요.", hangul.GetJosa(command, hangul.EUL_REUL)), Content: fmt.Sprintf("%s 배웠어요.", hangul.GetJosa(command, hangul.EUL_REUL)),
Color: utils.EmbedSuccess, },
}). )).
SetComponentsV2(true).
SetReply(true). SetReply(true).
Send() Send()
} }

View file

@ -7,7 +7,7 @@ import (
"git.wh64.net/muffin/goMuffin/utils" "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] var updatedString string = utils.RegexpDecimals.FindAllStringSubmatch(MUFFIN_VERSION, -1)[3][0]

35
utils/embed.go Normal file
View file

@ -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
}

View file

@ -1,7 +0,0 @@
package utils
const (
EmbedDefault int = 0xaddb87
EmbedFail int = 0xff0000
EmbedSuccess int = 0x00ff00
)