diff --git a/commands/dataLength.go b/commands/dataLength.go index f27823d..83e0de0 100644 --- a/commands/dataLength.go +++ b/commands/dataLength.go @@ -140,7 +140,7 @@ func dataLengthRun(s *discordgo.Session, m any) { // 지금은 임시방편 embed := &discordgo.MessageEmbed{ Title: "저장된 데이터량", - Description: "총합: " + utils.InlineCode(strconv.Itoa(sum)) + "개", + Description: fmt.Sprintf("총합: %s개", utils.InlineCode(strconv.Itoa(sum))), Color: int(utils.EDefault), Fields: []*discordgo.MessageEmbedField{ { @@ -163,7 +163,7 @@ func dataLengthRun(s *discordgo.Session, m any) { Inline: true, }, { - Name: username + "님이 가르쳐준 데이터량", + Name: fmt.Sprintf("%s님이 가르쳐준 데이터량", username), Value: utils.InlineCode(strconv.Itoa(userLearnLength)) + "개", Inline: true, }, diff --git a/commands/deleteLearnedData.go b/commands/deleteLearnedData.go index 6a7505b..10f1279 100644 --- a/commands/deleteLearnedData.go +++ b/commands/deleteLearnedData.go @@ -2,6 +2,7 @@ package commands import ( "context" + "fmt" "strconv" "strings" @@ -121,7 +122,7 @@ func deleteLearnedDataRun(c *Command, s *discordgo.Session, m any, args *[]strin data := datas[i] options = append(options, discordgo.SelectMenuOption{ - Label: strconv.Itoa(i+1) + "번 지식", + Label: fmt.Sprintf("%d번 지식", i+1), Description: data.Result, Value: utils.DeleteLearnedData + data.Id.Hex() + `&No.` + strconv.Itoa(i+1), }) @@ -129,10 +130,9 @@ func deleteLearnedDataRun(c *Command, s *discordgo.Session, m any, args *[]strin } embed := &discordgo.MessageEmbed{ - Title: command + " 삭제", - Description: utils.CodeBlockWithLanguage("md", "# "+command+" 에 대한 대답 중 하나를 선ㅌ택하여 삭제해주세요.\n"+ - description), - Color: int(utils.EDefault), + Title: fmt.Sprintf("%s 삭제", command), + Description: utils.CodeBlockWithLanguage("md", fmt.Sprintf("# %s에 대한 대답 중 하나를 선ㅌ택하여 삭제해주세요.\n%s", command, description)), + Color: int(utils.EDefault), } components := []discordgo.MessageComponent{ diff --git a/commands/help.go b/commands/help.go index 3f6b100..f57f943 100644 --- a/commands/help.go +++ b/commands/help.go @@ -1,6 +1,7 @@ package commands import ( + "fmt" "strings" "git.wh64.net/muffin/goMuffin/configs" @@ -50,7 +51,7 @@ func getCommandsByCategory(d *DiscommandStruct, category Category) []string { commands := []string{} for _, command := range d.Commands { if command.Category == category { - commands = append(commands, "- "+command.Name+": "+command.Description) + commands = append(commands, fmt.Sprintf("- %s: %s", command.Name, command.Description)) } } return commands @@ -61,7 +62,7 @@ func helpRun(c *Command, s *discordgo.Session, m any, args *[]string) { embed := &discordgo.MessageEmbed{ Color: int(utils.EDefault), Footer: &discordgo.MessageEmbedFooter{ - Text: "버전:" + configs.MUFFIN_VERSION, + Text: fmt.Sprintf("버전: %s", configs.MUFFIN_VERSION), }, Thumbnail: &discordgo.MessageEmbedThumbnail{ URL: s.State.User.AvatarURL("512"), @@ -82,13 +83,12 @@ func helpRun(c *Command, s *discordgo.Session, m any, args *[]string) { } if commandName == "" || Discommand.Commands[commandName] == nil { - embed.Title = s.State.User.Username + "의 도움말" + embed.Title = fmt.Sprintf("%s의 도움말", s.State.User.Username) embed.Description = utils.CodeBlockWithLanguage( "md", - "# 일반\n"+ - strings.Join(getCommandsByCategory(Discommand, Generals), "\n")+ - "\n\n# 채팅\n"+ - strings.Join(getCommandsByCategory(Discommand, Chattings), "\n"), + fmt.Sprintf("# 일반\n%s\n\n# 채팅\n%s", + strings.Join(getCommandsByCategory(Discommand, Generals), "\n"), + strings.Join(getCommandsByCategory(Discommand, Chattings), "\n")), ) switch m := m.(type) { @@ -107,7 +107,7 @@ func helpRun(c *Command, s *discordgo.Session, m any, args *[]string) { command := Discommand.Commands[commandName] - embed.Title = s.State.User.Username + "의 " + command.Name + " 도움말" + embed.Title = fmt.Sprintf("%s의 %s 도움말", s.State.User.Username, command.Name) embed.Fields = []*discordgo.MessageEmbedField{ { Name: "설명", diff --git a/commands/information.go b/commands/information.go index 9005b62..452cda6 100644 --- a/commands/information.go +++ b/commands/information.go @@ -1,6 +1,7 @@ package commands import ( + "fmt" "runtime" "git.wh64.net/muffin/goMuffin/configs" @@ -28,11 +29,11 @@ var InformationCommand *Command = &Command{ func informationRun(s *discordgo.Session, m any) { owner, _ := s.User(configs.Config.Bot.OwnerId) embed := &discordgo.MessageEmbed{ - Title: s.State.User.Username + "의 정보", + Title: fmt.Sprintf("%s의 정보", s.State.User.Username), Fields: []*discordgo.MessageEmbedField{ { Name: "운영 체제", - Value: utils.InlineCode(runtime.GOOS + " " + runtime.GOARCH), + Value: utils.InlineCode(fmt.Sprintf("%s %s", runtime.GOOS, runtime.GOARCH)), }, { Name: "제작자", diff --git a/commands/learn.go b/commands/learn.go index aede037..0317342 100644 --- a/commands/learn.go +++ b/commands/learn.go @@ -53,7 +53,7 @@ var LearnCommand *Command = &Command{ func addPrefix(arr []string) (newArr []string) { for _, item := range arr { - newArr = append(newArr, "- "+item) + newArr = append(newArr, fmt.Sprintf("- %s", item)) } return } @@ -123,7 +123,8 @@ func learnRun(c *Command, s *discordgo.Session, m any, args *[]string) { disallows := []string{ "@everyone", "@here", - "<@" + configs.Config.Bot.OwnerId + ">"} + fmt.Sprintf("<@%s>", configs.Config.Bot.OwnerId), + } for _, ig := range ignores { if strings.Contains(command, ig) { @@ -191,7 +192,7 @@ func learnRun(c *Command, s *discordgo.Session, m any, args *[]string) { embed := &discordgo.MessageEmbed{ Title: "✅ 성공", - Description: hangul.GetJosa(command, hangul.EUL_REUL) + " 배웠어요.", + Description: fmt.Sprintf("%s 배웠어요.", hangul.GetJosa(command, hangul.EUL_REUL)), Color: int(utils.ESuccess), } diff --git a/commands/learnedDataList.go b/commands/learnedDataList.go index beb2ce8..e77f9d4 100644 --- a/commands/learnedDataList.go +++ b/commands/learnedDataList.go @@ -3,7 +3,6 @@ package commands import ( "context" "fmt" - "strconv" "strings" "git.wh64.net/muffin/goMuffin/databases" @@ -34,7 +33,7 @@ var LearnedDataListCommand *Command = &Command{ func getDescriptions(datas *[]databases.Learn) (descriptions []string) { for _, data := range *datas { - descriptions = append(descriptions, "- "+data.Command+": "+data.Result) + descriptions = append(descriptions, fmt.Sprintf("- %s: %s", data.Command, data.Result)) } return } @@ -103,8 +102,8 @@ func learnedDataListRun(s *discordgo.Session, m any) { cur.All(context.TODO(), &datas) embed := &discordgo.MessageEmbed{ - Title: globalName + "님이 알려주신 지식", - Description: utils.CodeBlockWithLanguage("md", "# 총 "+strconv.Itoa(len(datas))+"개에요.\n"+strings.Join(getDescriptions(&datas), "\n")), + Title: fmt.Sprintf("%s님이 알려주신 지식", globalName), + Description: utils.CodeBlockWithLanguage("md", fmt.Sprintf("# 총 %d개에요.\n%s", len(datas), strings.Join(getDescriptions(&datas), "\n"))), Color: int(utils.EDefault), Thumbnail: &discordgo.MessageEmbedThumbnail{ URL: avatarUrl, diff --git a/components/deleteLearnedData.go b/components/deleteLearnedData.go index d3cfb90..5a6b476 100644 --- a/components/deleteLearnedData.go +++ b/components/deleteLearnedData.go @@ -2,6 +2,7 @@ package components import ( "context" + "fmt" "strings" "git.wh64.net/muffin/goMuffin/commands" @@ -68,7 +69,7 @@ var DeleteLearnedDataComponent *commands.Component = &commands.Component{ Embeds: &[]*discordgo.MessageEmbed{ { Title: "✅ 삭제 완료", - Description: itemId + "번을 삭ㅈ제했어요.", + Description: fmt.Sprintf("%s번을 삭ㅈ제했어요.", itemId), Color: int(utils.ESuccess), }, }, diff --git a/handler/messageCreate.go b/handler/messageCreate.go index db51036..3113182 100644 --- a/handler/messageCreate.go +++ b/handler/messageCreate.go @@ -2,6 +2,7 @@ package handler import ( "context" + "fmt" "log" "math/rand" "strings" @@ -65,7 +66,7 @@ func MessageCreate(s *discordgo.Session, m *discordgo.MessageCreate) { if _, err := databases.Texts.InsertOne(context.TODO(), databases.InsertText{ Text: content, - Persona: "user:" + m.Author.Username, + Persona: fmt.Sprintf("user:%s", m.Author.Username), CreatedAt: time.Now(), }); err != nil { log.Fatalln(err) @@ -108,7 +109,7 @@ func MessageCreate(s *discordgo.Session, m *discordgo.MessageCreate) { if x > 2 && len(learnDatas) != 0 { data := learnDatas[rand.Intn(len(learnDatas))] user, _ := s.User(data.UserId) - s.ChannelMessageSendReply(m.ChannelID, data.Result+"\n"+utils.InlineCode(user.Username+"님이 알려주셨어요."), m.Reference()) + s.ChannelMessageSendReply(m.ChannelID, fmt.Sprintf("%s\n%s", data.Result, utils.InlineCode(fmt.Sprintf("%s님이 알려주셨어요.", user.Username))), m.Reference()) return } diff --git a/utils/codeFormatter.go b/utils/codeFormatter.go index cc4a8f2..20324a5 100644 --- a/utils/codeFormatter.go +++ b/utils/codeFormatter.go @@ -1,7 +1,7 @@ package utils import ( - "strconv" + "fmt" "time" ) @@ -18,12 +18,12 @@ const ( RelativeTime = "R" ) -func InlineCode(str string) string { - return "`" + str + "`" +func InlineCode(content string) string { + return fmt.Sprintf("`%s`", content) } func CodeBlockWithLanguage(language string, content string) string { - return "```" + language + "\n" + content + "\n" + "```" + return fmt.Sprintf("```%s\n%s\n```", language, content) } func CodeBlock(content string) string { @@ -31,9 +31,9 @@ func CodeBlock(content string) string { } func Time(time *time.Time) string { - return "" + return fmt.Sprintf("", time.Unix()) } func TimeWithStyle(time *time.Time, style string) string { - return "" + return fmt.Sprintf("", time.Unix(), style) }