chore: Combing the codeFormatter functions
This commit is contained in:
parent
f43237083f
commit
ed81d98623
7 changed files with 21 additions and 23 deletions
|
@ -61,7 +61,7 @@ func deleteLearnedDataRun(c *Command, s *discordgo.Session, m any, args *[]strin
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Name: "예시",
|
Name: "예시",
|
||||||
Value: utils.CodeBlockWithLanguage("md", strings.Join(addPrefix(c.DetailedDescription.Examples), "\n")),
|
Value: utils.CodeBlock("md", strings.Join(addPrefix(c.DetailedDescription.Examples), "\n")),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Color: utils.EmbedFail,
|
Color: utils.EmbedFail,
|
||||||
|
@ -131,7 +131,7 @@ func deleteLearnedDataRun(c *Command, s *discordgo.Session, m any, args *[]strin
|
||||||
|
|
||||||
embed := &discordgo.MessageEmbed{
|
embed := &discordgo.MessageEmbed{
|
||||||
Title: fmt.Sprintf("%s 삭제", command),
|
Title: fmt.Sprintf("%s 삭제", command),
|
||||||
Description: utils.CodeBlockWithLanguage("md", fmt.Sprintf("# %s에 대한 대답 중 하나를 선ㅌ택하여 삭제해주세요.\n%s", command, description)),
|
Description: utils.CodeBlock("md", fmt.Sprintf("# %s에 대한 대답 중 하나를 선ㅌ택하여 삭제해주세요.\n%s", command, description)),
|
||||||
Color: utils.EmbedDefault,
|
Color: utils.EmbedDefault,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -84,7 +84,7 @@ func helpRun(c *Command, s *discordgo.Session, m any, args *[]string) {
|
||||||
|
|
||||||
if commandName == "" || Discommand.Commands[commandName] == nil {
|
if commandName == "" || Discommand.Commands[commandName] == nil {
|
||||||
embed.Title = fmt.Sprintf("%s의 도움말", s.State.User.Username)
|
embed.Title = fmt.Sprintf("%s의 도움말", s.State.User.Username)
|
||||||
embed.Description = utils.CodeBlockWithLanguage(
|
embed.Description = utils.CodeBlock(
|
||||||
"md",
|
"md",
|
||||||
fmt.Sprintf("# 일반\n%s\n\n# 채팅\n%s",
|
fmt.Sprintf("# 일반\n%s\n\n# 채팅\n%s",
|
||||||
strings.Join(getCommandsByCategory(Discommand, Generals), "\n"),
|
strings.Join(getCommandsByCategory(Discommand, Generals), "\n"),
|
||||||
|
@ -124,7 +124,7 @@ func helpRun(c *Command, s *discordgo.Session, m any, args *[]string) {
|
||||||
if command.Aliases != nil {
|
if command.Aliases != nil {
|
||||||
embed.Fields = append(embed.Fields, &discordgo.MessageEmbedField{
|
embed.Fields = append(embed.Fields, &discordgo.MessageEmbedField{
|
||||||
Name: "별칭",
|
Name: "별칭",
|
||||||
Value: utils.CodeBlockWithLanguage("md", strings.Join(addPrefix(command.Aliases), "\n")),
|
Value: utils.CodeBlock("md", strings.Join(addPrefix(command.Aliases), "\n")),
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
embed.Fields = append(embed.Fields, &discordgo.MessageEmbedField{
|
embed.Fields = append(embed.Fields, &discordgo.MessageEmbedField{
|
||||||
|
@ -136,7 +136,7 @@ func helpRun(c *Command, s *discordgo.Session, m any, args *[]string) {
|
||||||
if command.DetailedDescription.Examples != nil {
|
if command.DetailedDescription.Examples != nil {
|
||||||
embed.Fields = append(embed.Fields, &discordgo.MessageEmbedField{
|
embed.Fields = append(embed.Fields, &discordgo.MessageEmbedField{
|
||||||
Name: "예시",
|
Name: "예시",
|
||||||
Value: utils.CodeBlockWithLanguage("md", strings.Join(addPrefix(c.DetailedDescription.Examples), "\n")),
|
Value: utils.CodeBlock("md", strings.Join(addPrefix(c.DetailedDescription.Examples), "\n")),
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
embed.Fields = append(embed.Fields, &discordgo.MessageEmbedField{
|
embed.Fields = append(embed.Fields, &discordgo.MessageEmbedField{
|
||||||
|
|
|
@ -45,12 +45,12 @@ func informationRun(s *discordgo.Session, m any) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Name: "최근에 업데이트된 날짜",
|
Name: "최근에 업데이트된 날짜",
|
||||||
Value: utils.TimeWithStyle(configs.UpdatedAt, utils.RelativeTime),
|
Value: utils.Time(configs.UpdatedAt, utils.RelativeTime),
|
||||||
Inline: true,
|
Inline: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Name: "업타임",
|
Name: "업타임",
|
||||||
Value: utils.TimeWithStyle(configs.StartedAt, utils.RelativeTime),
|
Value: utils.Time(configs.StartedAt, utils.RelativeTime),
|
||||||
Inline: true,
|
Inline: true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
|
@ -97,7 +97,7 @@ func learnRun(c *Command, s *discordgo.Session, m any, args *[]string) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Name: "예시",
|
Name: "예시",
|
||||||
Value: utils.CodeBlockWithLanguage("md", strings.Join(addPrefix(c.DetailedDescription.Examples), "\n")),
|
Value: utils.CodeBlock("md", strings.Join(addPrefix(c.DetailedDescription.Examples), "\n")),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Color: utils.EmbedFail,
|
Color: utils.EmbedFail,
|
||||||
|
|
|
@ -104,7 +104,7 @@ func learnedDataListRun(s *discordgo.Session, m any) {
|
||||||
|
|
||||||
embed := &discordgo.MessageEmbed{
|
embed := &discordgo.MessageEmbed{
|
||||||
Title: fmt.Sprintf("%s님이 알려주신 지식", globalName),
|
Title: fmt.Sprintf("%s님이 알려주신 지식", globalName),
|
||||||
Description: utils.CodeBlockWithLanguage("md", fmt.Sprintf("# 총 %d개에요.\n%s", len(datas), strings.Join(getDescriptions(&datas), "\n"))),
|
Description: utils.CodeBlock("md", fmt.Sprintf("# 총 %d개에요.\n%s", len(datas), strings.Join(getDescriptions(&datas), "\n"))),
|
||||||
Color: utils.EmbedDefault,
|
Color: utils.EmbedDefault,
|
||||||
Thumbnail: &discordgo.MessageEmbedThumbnail{
|
Thumbnail: &discordgo.MessageEmbedThumbnail{
|
||||||
URL: avatarUrl,
|
URL: avatarUrl,
|
||||||
|
|
|
@ -36,12 +36,12 @@ func resultParser(content string, s *discordgo.Session, m *discordgo.MessageCrea
|
||||||
result = strings.ReplaceAll(result, "{user.mention}", m.Author.Mention())
|
result = strings.ReplaceAll(result, "{user.mention}", m.Author.Mention())
|
||||||
result = strings.ReplaceAll(result, "{user.globalName}", m.Author.GlobalName)
|
result = strings.ReplaceAll(result, "{user.globalName}", m.Author.GlobalName)
|
||||||
result = strings.ReplaceAll(result, "{user.id}", m.Author.ID)
|
result = strings.ReplaceAll(result, "{user.id}", m.Author.ID)
|
||||||
result = strings.ReplaceAll(result, "{user.createdAt}", utils.TimeWithStyle(&userCreatedAt, utils.RelativeTime))
|
result = strings.ReplaceAll(result, "{user.createdAt}", utils.Time(&userCreatedAt, utils.RelativeTime))
|
||||||
result = strings.ReplaceAll(result, "{user.joinedAt}", utils.TimeWithStyle(&m.Member.JoinedAt, utils.RelativeTime))
|
result = strings.ReplaceAll(result, "{user.joinedAt}", utils.Time(&m.Member.JoinedAt, utils.RelativeTime))
|
||||||
|
|
||||||
result = strings.ReplaceAll(result, "{muffin.version}", configs.MUFFIN_VERSION)
|
result = strings.ReplaceAll(result, "{muffin.version}", configs.MUFFIN_VERSION)
|
||||||
result = strings.ReplaceAll(result, "{muffin.updatedAt}", utils.TimeWithStyle(configs.UpdatedAt, utils.RelativeTime))
|
result = strings.ReplaceAll(result, "{muffin.updatedAt}", utils.Time(configs.UpdatedAt, utils.RelativeTime))
|
||||||
result = strings.ReplaceAll(result, "{muffin.startedAt}", utils.TimeWithStyle(configs.StartedAt, utils.RelativeTime))
|
result = strings.ReplaceAll(result, "{muffin.startedAt}", utils.Time(configs.StartedAt, utils.RelativeTime))
|
||||||
result = strings.ReplaceAll(result, "{muffin.name}", s.State.User.Username)
|
result = strings.ReplaceAll(result, "{muffin.name}", s.State.User.Username)
|
||||||
result = strings.ReplaceAll(result, "{muffin.id}", s.State.User.ID)
|
result = strings.ReplaceAll(result, "{muffin.id}", s.State.User.ID)
|
||||||
return result
|
return result
|
||||||
|
|
|
@ -22,18 +22,16 @@ func InlineCode(content string) string {
|
||||||
return fmt.Sprintf("`%s`", content)
|
return fmt.Sprintf("`%s`", content)
|
||||||
}
|
}
|
||||||
|
|
||||||
func CodeBlockWithLanguage(language string, content string) string {
|
func CodeBlock(language string, content string) string {
|
||||||
|
if content == "" {
|
||||||
|
return fmt.Sprintf("```\n%s\n```", language)
|
||||||
|
}
|
||||||
return fmt.Sprintf("```%s\n%s\n```", language, content)
|
return fmt.Sprintf("```%s\n%s\n```", language, content)
|
||||||
}
|
}
|
||||||
|
|
||||||
func CodeBlock(content string) string {
|
func Time(time *time.Time, style string) string {
|
||||||
return fmt.Sprintf("```\n%s\n```", content)
|
if style == "" {
|
||||||
}
|
|
||||||
|
|
||||||
func Time(time *time.Time) string {
|
|
||||||
return fmt.Sprintf("<t:%d>", time.Unix())
|
return fmt.Sprintf("<t:%d>", time.Unix())
|
||||||
}
|
}
|
||||||
|
|
||||||
func TimeWithStyle(time *time.Time, style string) string {
|
|
||||||
return fmt.Sprintf("<t:%d:%s>", time.Unix(), style)
|
return fmt.Sprintf("<t:%d:%s>", time.Unix(), style)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue