From 6468521ee1f6d9acb005f0ec534aebc910cbc26f Mon Sep 17 00:00:00 2001 From: Siwoo Jeon Date: Sat, 24 May 2025 15:52:27 +0900 Subject: [PATCH] feat: Add help command componentsV2 --- commands/help.go | 118 ++++++++++++++++++++++++++-------------------- commands/learn.go | 22 ++++----- 2 files changed, 78 insertions(+), 62 deletions(-) diff --git a/commands/help.go b/commands/help.go index cac8c6f..d6fbd26 100644 --- a/commands/help.go +++ b/commands/help.go @@ -47,84 +47,100 @@ func getCommandsByCategory(d *DiscommandStruct, category Category) []string { commands := []string{} for _, command := range d.Commands { if command.Category == category { - commands = append(commands, fmt.Sprintf("- %s: %s", command.Name, command.Description)) + commands = append(commands, fmt.Sprintf("> **%s**: %s", command.Name, command.Description)) } } return commands } func helpRun(s *discordgo.Session, m any, commandName string) { - embed := &discordgo.MessageEmbed{ - Color: utils.EmbedDefault, - Footer: &discordgo.MessageEmbedFooter{ - Text: fmt.Sprintf("버전: %s", configs.MUFFIN_VERSION), - }, - Thumbnail: &discordgo.MessageEmbedThumbnail{ - URL: s.State.User.AvatarURL("512"), + section := &discordgo.Section{ + Accessory: discordgo.Thumbnail{ + Media: discordgo.UnfurledMediaItem{ + URL: s.State.User.AvatarURL("512"), + }, }, } commandName = Discommand.Aliases[commandName] if commandName == "" || Discommand.Commands[commandName] == nil { - embed.Title = fmt.Sprintf("%s의 도움말", s.State.User.Username) - embed.Description = utils.CodeBlock( - "md", - fmt.Sprintf("# 일반\n%s\n\n# 채팅\n%s", - strings.Join(getCommandsByCategory(Discommand, General), "\n"), - strings.Join(getCommandsByCategory(Discommand, Chatting), "\n")), + section.Components = append(section.Components, + discordgo.TextDisplay{ + Content: fmt.Sprintf("### %s의 도움말", s.State.User.Username), + }, + discordgo.TextDisplay{ + Content: fmt.Sprintf("- **일반**\n%s", strings.Join(getCommandsByCategory(Discommand, General), "\n")), + }, + discordgo.TextDisplay{ + Content: fmt.Sprintf("- **채팅**\n%s", strings.Join(getCommandsByCategory(Discommand, Chatting), "\n")), + }, ) - - utils.NewMessageSender(m).AddEmbeds(embed).SetReply(true).Send() + utils.NewMessageSender(m). + AddComponents(&discordgo.Container{ + Components: []discordgo.MessageComponent{section}, + }). + SetComponentsV2(true). + SetReply(true). + Send() return } + var aliases, examples discordgo.TextDisplay + command := Discommand.Commands[commandName] - embed.Title = fmt.Sprintf("%s의 %s 명령어의 도움말", s.State.User.Username, command.Name) - embed.Fields = []*discordgo.MessageEmbedField{ - { - Name: "설명", - Value: utils.InlineCode(command.Description), - Inline: true, + section.Components = append(section.Components, + discordgo.TextDisplay{ + Content: fmt.Sprintf("### %s의 %s 명령어의 도움말", s.State.User.Username, command.Name), }, - { - Name: "사용법", - Value: utils.InlineCode(command.DetailedDescription.Usage), - Inline: true, + discordgo.TextDisplay{ + Content: fmt.Sprintf("- **설명**\n> %s", command.Description), }, - } - - if command.Name == LearnCommand.Name { - embed.Fields = append(embed.Fields, &discordgo.MessageEmbedField{ - Name: "대답에 쓸 수 있는 인자", - Value: learnArguments, - }) - } + discordgo.TextDisplay{ + Content: fmt.Sprintf("- **사용법**\n> %s", command.DetailedDescription.Usage), + }, + ) if command.Aliases != nil { - embed.Fields = append(embed.Fields, &discordgo.MessageEmbedField{ - Name: "별칭", - Value: utils.CodeBlock("md", strings.Join(addPrefix(command.Aliases), "\n")), - }) + aliases = discordgo.TextDisplay{ + Content: fmt.Sprintf("- **별칭**\n%s", strings.Join(utils.AddPrefix("> ", command.Aliases), "\n")), + } } else { - embed.Fields = append(embed.Fields, &discordgo.MessageEmbedField{ - Name: "별칭", - Value: "없음", - }) + aliases = discordgo.TextDisplay{ + Content: "- **별칭**\n> 없음", + } } if command.DetailedDescription.Examples != nil { - embed.Fields = append(embed.Fields, &discordgo.MessageEmbedField{ - Name: "예시", - Value: utils.CodeBlock("md", strings.Join(addPrefix(command.DetailedDescription.Examples), "\n")), - }) + examples = discordgo.TextDisplay{ + Content: fmt.Sprintf("- **예시**\n%s", strings.Join(utils.AddPrefix("> ", command.DetailedDescription.Examples), "\n")), + } } else { - embed.Fields = append(embed.Fields, &discordgo.MessageEmbedField{ - Name: "예시", - Value: "없음", - }) + aliases = discordgo.TextDisplay{ + Content: "- **예시**\n> 없음", + } } - utils.NewMessageSender(m).AddEmbeds(embed).SetReply(true).Send() + if command.Name == LearnCommand.Name { + learnArgs := discordgo.TextDisplay{ + Content: fmt.Sprintf("- **대답에 쓸 수 있는 인자**\n%s", learnArguments), + } + utils.NewMessageSender(m). + AddComponents(discordgo.Container{ + Components: []discordgo.MessageComponent{section, aliases, examples, learnArgs}, + }). + SetComponentsV2(true). + SetReply(true). + Send() + return + } + + utils.NewMessageSender(m). + AddComponents(discordgo.Container{ + Components: []discordgo.MessageComponent{section, aliases, examples}, + }). + SetComponentsV2(true). + SetReply(true). + Send() } diff --git a/commands/learn.go b/commands/learn.go index c7bd63c..f3fb690 100644 --- a/commands/learn.go +++ b/commands/learn.go @@ -14,17 +14,17 @@ import ( "github.com/bwmarrin/discordgo" ) -var learnArguments = utils.InlineCode("{user.name}") + "\n" + - utils.InlineCode("{user.mention}") + "\n" + - utils.InlineCode("{user.globalName}") + "\n" + - utils.InlineCode("{user.id}") + "\n" + - utils.InlineCode("{user.createdAt}") + "\n" + - utils.InlineCode("{user.joinedAt}") + "\n" + - utils.InlineCode("{muffin.version}") + "\n" + - utils.InlineCode("{muffin.updatedAt}") + "\n" + - utils.InlineCode("{muffin.statedAt}") + "\n" + - utils.InlineCode("{muffin.name}") + "\n" + - utils.InlineCode("{muffin.id}") +var learnArguments = "> " + utils.InlineCode("{user.name}") + "\n" + + "> " + utils.InlineCode("{user.mention}") + "\n" + + "> " + utils.InlineCode("{user.globalName}") + "\n" + + "> " + utils.InlineCode("{user.id}") + "\n" + + "> " + utils.InlineCode("{user.createdAt}") + "\n" + + "> " + utils.InlineCode("{user.joinedAt}") + "\n" + + "> " + utils.InlineCode("{muffin.version}") + "\n" + + "> " + utils.InlineCode("{muffin.updatedAt}") + "\n" + + "> " + utils.InlineCode("{muffin.statedAt}") + "\n" + + "> " + utils.InlineCode("{muffin.name}") + "\n" + + "> " + utils.InlineCode("{muffin.id}") var LearnCommand *Command = &Command{ ApplicationCommand: &discordgo.ApplicationCommand{