diff --git a/commands/deleteLearnedData.go b/commands/deleteLearnedData.go index 5c84815..533d67e 100644 --- a/commands/deleteLearnedData.go +++ b/commands/deleteLearnedData.go @@ -61,7 +61,7 @@ func deleteLearnedDataRun(c *Command, s *discordgo.Session, m any, args *[]strin }, { 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, @@ -131,7 +131,7 @@ func deleteLearnedDataRun(c *Command, s *discordgo.Session, m any, args *[]strin embed := &discordgo.MessageEmbed{ 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, } diff --git a/commands/help.go b/commands/help.go index 6e69261..7a35c68 100644 --- a/commands/help.go +++ b/commands/help.go @@ -84,7 +84,7 @@ func helpRun(c *Command, s *discordgo.Session, m any, args *[]string) { if commandName == "" || Discommand.Commands[commandName] == nil { embed.Title = fmt.Sprintf("%s의 도움말", s.State.User.Username) - embed.Description = utils.CodeBlockWithLanguage( + embed.Description = utils.CodeBlock( "md", fmt.Sprintf("# 일반\n%s\n\n# 채팅\n%s", 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 { embed.Fields = append(embed.Fields, &discordgo.MessageEmbedField{ Name: "별칭", - Value: utils.CodeBlockWithLanguage("md", strings.Join(addPrefix(command.Aliases), "\n")), + Value: utils.CodeBlock("md", strings.Join(addPrefix(command.Aliases), "\n")), }) } else { 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 { embed.Fields = append(embed.Fields, &discordgo.MessageEmbedField{ Name: "예시", - Value: utils.CodeBlockWithLanguage("md", strings.Join(addPrefix(c.DetailedDescription.Examples), "\n")), + Value: utils.CodeBlock("md", strings.Join(addPrefix(c.DetailedDescription.Examples), "\n")), }) } else { embed.Fields = append(embed.Fields, &discordgo.MessageEmbedField{ diff --git a/commands/information.go b/commands/information.go index 61b6934..c1a12fb 100644 --- a/commands/information.go +++ b/commands/information.go @@ -45,12 +45,12 @@ func informationRun(s *discordgo.Session, m any) { }, { Name: "최근에 업데이트된 날짜", - Value: utils.TimeWithStyle(configs.UpdatedAt, utils.RelativeTime), + Value: utils.Time(configs.UpdatedAt, utils.RelativeTime), Inline: true, }, { Name: "업타임", - Value: utils.TimeWithStyle(configs.StartedAt, utils.RelativeTime), + Value: utils.Time(configs.StartedAt, utils.RelativeTime), Inline: true, }, }, diff --git a/commands/learn.go b/commands/learn.go index 51aafc5..7c98133 100644 --- a/commands/learn.go +++ b/commands/learn.go @@ -97,7 +97,7 @@ func learnRun(c *Command, s *discordgo.Session, m any, args *[]string) { }, { 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, diff --git a/commands/learnedDataList.go b/commands/learnedDataList.go index 2952cfd..cecde6b 100644 --- a/commands/learnedDataList.go +++ b/commands/learnedDataList.go @@ -104,7 +104,7 @@ func learnedDataListRun(s *discordgo.Session, m any) { embed := &discordgo.MessageEmbed{ 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, Thumbnail: &discordgo.MessageEmbedThumbnail{ URL: avatarUrl, diff --git a/handler/messageCreate.go b/handler/messageCreate.go index e31d7ea..881a2a3 100644 --- a/handler/messageCreate.go +++ b/handler/messageCreate.go @@ -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.globalName}", m.Author.GlobalName) 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.joinedAt}", utils.TimeWithStyle(&m.Member.JoinedAt, utils.RelativeTime)) + result = strings.ReplaceAll(result, "{user.createdAt}", utils.Time(&userCreatedAt, 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.updatedAt}", utils.TimeWithStyle(configs.UpdatedAt, utils.RelativeTime)) - result = strings.ReplaceAll(result, "{muffin.startedAt}", utils.TimeWithStyle(configs.StartedAt, utils.RelativeTime)) + result = strings.ReplaceAll(result, "{muffin.updatedAt}", utils.Time(configs.UpdatedAt, 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.id}", s.State.User.ID) return result diff --git a/utils/codeFormatter.go b/utils/codeFormatter.go index 70339da..47e1bd3 100644 --- a/utils/codeFormatter.go +++ b/utils/codeFormatter.go @@ -22,18 +22,16 @@ func InlineCode(content string) string { 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) } -func CodeBlock(content string) string { - return fmt.Sprintf("```\n%s\n```", content) -} - -func Time(time *time.Time) string { - return fmt.Sprintf("", time.Unix()) -} - -func TimeWithStyle(time *time.Time, style string) string { +func Time(time *time.Time, style string) string { + if style == "" { + return fmt.Sprintf("", time.Unix()) + } return fmt.Sprintf("", time.Unix(), style) }