feat: Add help command componentsV2

This commit is contained in:
Siwoo Jeon 2025-05-24 15:52:27 +09:00
parent 6fd272ef5f
commit 6468521ee1
Signed by: migan
GPG key ID: 036E9A8C5E8E48DA
2 changed files with 78 additions and 62 deletions

View file

@ -47,84 +47,100 @@ func getCommandsByCategory(d *DiscommandStruct, category Category) []string {
commands := []string{} commands := []string{}
for _, command := range d.Commands { for _, command := range d.Commands {
if command.Category == category { 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 return commands
} }
func helpRun(s *discordgo.Session, m any, commandName string) { func helpRun(s *discordgo.Session, m any, commandName string) {
embed := &discordgo.MessageEmbed{ section := &discordgo.Section{
Color: utils.EmbedDefault, Accessory: discordgo.Thumbnail{
Footer: &discordgo.MessageEmbedFooter{ Media: discordgo.UnfurledMediaItem{
Text: fmt.Sprintf("버전: %s", configs.MUFFIN_VERSION), URL: s.State.User.AvatarURL("512"),
}, },
Thumbnail: &discordgo.MessageEmbedThumbnail{
URL: s.State.User.AvatarURL("512"),
}, },
} }
commandName = Discommand.Aliases[commandName] commandName = Discommand.Aliases[commandName]
if commandName == "" || Discommand.Commands[commandName] == nil { if commandName == "" || Discommand.Commands[commandName] == nil {
embed.Title = fmt.Sprintf("%s의 도움말", s.State.User.Username) section.Components = append(section.Components,
embed.Description = utils.CodeBlock( discordgo.TextDisplay{
"md", Content: fmt.Sprintf("### %s의 도움말", s.State.User.Username),
fmt.Sprintf("# 일반\n%s\n\n# 채팅\n%s", },
strings.Join(getCommandsByCategory(Discommand, General), "\n"), discordgo.TextDisplay{
strings.Join(getCommandsByCategory(Discommand, Chatting), "\n")), 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).
utils.NewMessageSender(m).AddEmbeds(embed).SetReply(true).Send() AddComponents(&discordgo.Container{
Components: []discordgo.MessageComponent{section},
}).
SetComponentsV2(true).
SetReply(true).
Send()
return return
} }
var aliases, examples discordgo.TextDisplay
command := Discommand.Commands[commandName] command := Discommand.Commands[commandName]
embed.Title = fmt.Sprintf("%s의 %s 명령어의 도움말", s.State.User.Username, command.Name) section.Components = append(section.Components,
embed.Fields = []*discordgo.MessageEmbedField{ discordgo.TextDisplay{
{ Content: fmt.Sprintf("### %s의 %s 명령어의 도움말", s.State.User.Username, command.Name),
Name: "설명",
Value: utils.InlineCode(command.Description),
Inline: true,
}, },
{ discordgo.TextDisplay{
Name: "사용법", Content: fmt.Sprintf("- **설명**\n> %s", command.Description),
Value: utils.InlineCode(command.DetailedDescription.Usage),
Inline: true,
}, },
} discordgo.TextDisplay{
Content: fmt.Sprintf("- **사용법**\n> %s", command.DetailedDescription.Usage),
if command.Name == LearnCommand.Name { },
embed.Fields = append(embed.Fields, &discordgo.MessageEmbedField{ )
Name: "대답에 쓸 수 있는 인자",
Value: learnArguments,
})
}
if command.Aliases != nil { if command.Aliases != nil {
embed.Fields = append(embed.Fields, &discordgo.MessageEmbedField{ aliases = discordgo.TextDisplay{
Name: "별칭", Content: fmt.Sprintf("- **별칭**\n%s", strings.Join(utils.AddPrefix("> ", command.Aliases), "\n")),
Value: utils.CodeBlock("md", strings.Join(addPrefix(command.Aliases), "\n")), }
})
} else { } else {
embed.Fields = append(embed.Fields, &discordgo.MessageEmbedField{ aliases = discordgo.TextDisplay{
Name: "별칭", Content: "- **별칭**\n> 없음",
Value: "없음", }
})
} }
if command.DetailedDescription.Examples != nil { if command.DetailedDescription.Examples != nil {
embed.Fields = append(embed.Fields, &discordgo.MessageEmbedField{ examples = discordgo.TextDisplay{
Name: "예시", Content: fmt.Sprintf("- **예시**\n%s", strings.Join(utils.AddPrefix("> ", command.DetailedDescription.Examples), "\n")),
Value: utils.CodeBlock("md", strings.Join(addPrefix(command.DetailedDescription.Examples), "\n")), }
})
} else { } else {
embed.Fields = append(embed.Fields, &discordgo.MessageEmbedField{ aliases = discordgo.TextDisplay{
Name: "예시", Content: "- **예시**\n> 없음",
Value: "없음", }
})
} }
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()
} }

View file

@ -14,17 +14,17 @@ import (
"github.com/bwmarrin/discordgo" "github.com/bwmarrin/discordgo"
) )
var learnArguments = utils.InlineCode("{user.name}") + "\n" + var learnArguments = "> " + utils.InlineCode("{user.name}") + "\n" +
utils.InlineCode("{user.mention}") + "\n" + "> " + utils.InlineCode("{user.mention}") + "\n" +
utils.InlineCode("{user.globalName}") + "\n" + "> " + utils.InlineCode("{user.globalName}") + "\n" +
utils.InlineCode("{user.id}") + "\n" + "> " + utils.InlineCode("{user.id}") + "\n" +
utils.InlineCode("{user.createdAt}") + "\n" + "> " + utils.InlineCode("{user.createdAt}") + "\n" +
utils.InlineCode("{user.joinedAt}") + "\n" + "> " + utils.InlineCode("{user.joinedAt}") + "\n" +
utils.InlineCode("{muffin.version}") + "\n" + "> " + utils.InlineCode("{muffin.version}") + "\n" +
utils.InlineCode("{muffin.updatedAt}") + "\n" + "> " + utils.InlineCode("{muffin.updatedAt}") + "\n" +
utils.InlineCode("{muffin.statedAt}") + "\n" + "> " + utils.InlineCode("{muffin.statedAt}") + "\n" +
utils.InlineCode("{muffin.name}") + "\n" + "> " + utils.InlineCode("{muffin.name}") + "\n" +
utils.InlineCode("{muffin.id}") "> " + utils.InlineCode("{muffin.id}")
var LearnCommand *Command = &Command{ var LearnCommand *Command = &Command{
ApplicationCommand: &discordgo.ApplicationCommand{ ApplicationCommand: &discordgo.ApplicationCommand{