feat: Use to fmt.Sprintf
This commit is contained in:
parent
143b97f476
commit
6bb97c9ebd
9 changed files with 36 additions and 33 deletions
|
@ -140,7 +140,7 @@ func dataLengthRun(s *discordgo.Session, m any) {
|
||||||
// 지금은 임시방편
|
// 지금은 임시방편
|
||||||
embed := &discordgo.MessageEmbed{
|
embed := &discordgo.MessageEmbed{
|
||||||
Title: "저장된 데이터량",
|
Title: "저장된 데이터량",
|
||||||
Description: "총합: " + utils.InlineCode(strconv.Itoa(sum)) + "개",
|
Description: fmt.Sprintf("총합: %s개", utils.InlineCode(strconv.Itoa(sum))),
|
||||||
Color: int(utils.EDefault),
|
Color: int(utils.EDefault),
|
||||||
Fields: []*discordgo.MessageEmbedField{
|
Fields: []*discordgo.MessageEmbedField{
|
||||||
{
|
{
|
||||||
|
@ -163,7 +163,7 @@ func dataLengthRun(s *discordgo.Session, m any) {
|
||||||
Inline: true,
|
Inline: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Name: username + "님이 가르쳐준 데이터량",
|
Name: fmt.Sprintf("%s님이 가르쳐준 데이터량", username),
|
||||||
Value: utils.InlineCode(strconv.Itoa(userLearnLength)) + "개",
|
Value: utils.InlineCode(strconv.Itoa(userLearnLength)) + "개",
|
||||||
Inline: true,
|
Inline: true,
|
||||||
},
|
},
|
||||||
|
|
|
@ -2,6 +2,7 @@ package commands
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"fmt"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
@ -121,7 +122,7 @@ func deleteLearnedDataRun(c *Command, s *discordgo.Session, m any, args *[]strin
|
||||||
data := datas[i]
|
data := datas[i]
|
||||||
|
|
||||||
options = append(options, discordgo.SelectMenuOption{
|
options = append(options, discordgo.SelectMenuOption{
|
||||||
Label: strconv.Itoa(i+1) + "번 지식",
|
Label: fmt.Sprintf("%d번 지식", i+1),
|
||||||
Description: data.Result,
|
Description: data.Result,
|
||||||
Value: utils.DeleteLearnedData + data.Id.Hex() + `&No.` + strconv.Itoa(i+1),
|
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{
|
embed := &discordgo.MessageEmbed{
|
||||||
Title: command + " 삭제",
|
Title: fmt.Sprintf("%s 삭제", command),
|
||||||
Description: utils.CodeBlockWithLanguage("md", "# "+command+" 에 대한 대답 중 하나를 선ㅌ택하여 삭제해주세요.\n"+
|
Description: utils.CodeBlockWithLanguage("md", fmt.Sprintf("# %s에 대한 대답 중 하나를 선ㅌ택하여 삭제해주세요.\n%s", command, description)),
|
||||||
description),
|
Color: int(utils.EDefault),
|
||||||
Color: int(utils.EDefault),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
components := []discordgo.MessageComponent{
|
components := []discordgo.MessageComponent{
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package commands
|
package commands
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"git.wh64.net/muffin/goMuffin/configs"
|
"git.wh64.net/muffin/goMuffin/configs"
|
||||||
|
@ -50,7 +51,7 @@ 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, "- "+command.Name+": "+command.Description)
|
commands = append(commands, fmt.Sprintf("- %s: %s", command.Name, command.Description))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return commands
|
return commands
|
||||||
|
@ -61,7 +62,7 @@ func helpRun(c *Command, s *discordgo.Session, m any, args *[]string) {
|
||||||
embed := &discordgo.MessageEmbed{
|
embed := &discordgo.MessageEmbed{
|
||||||
Color: int(utils.EDefault),
|
Color: int(utils.EDefault),
|
||||||
Footer: &discordgo.MessageEmbedFooter{
|
Footer: &discordgo.MessageEmbedFooter{
|
||||||
Text: "버전:" + configs.MUFFIN_VERSION,
|
Text: fmt.Sprintf("버전: %s", configs.MUFFIN_VERSION),
|
||||||
},
|
},
|
||||||
Thumbnail: &discordgo.MessageEmbedThumbnail{
|
Thumbnail: &discordgo.MessageEmbedThumbnail{
|
||||||
URL: s.State.User.AvatarURL("512"),
|
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 {
|
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(
|
embed.Description = utils.CodeBlockWithLanguage(
|
||||||
"md",
|
"md",
|
||||||
"# 일반\n"+
|
fmt.Sprintf("# 일반\n%s\n\n# 채팅\n%s",
|
||||||
strings.Join(getCommandsByCategory(Discommand, Generals), "\n")+
|
strings.Join(getCommandsByCategory(Discommand, Generals), "\n"),
|
||||||
"\n\n# 채팅\n"+
|
strings.Join(getCommandsByCategory(Discommand, Chattings), "\n")),
|
||||||
strings.Join(getCommandsByCategory(Discommand, Chattings), "\n"),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
switch m := m.(type) {
|
switch m := m.(type) {
|
||||||
|
@ -107,7 +107,7 @@ func helpRun(c *Command, s *discordgo.Session, m any, args *[]string) {
|
||||||
|
|
||||||
command := Discommand.Commands[commandName]
|
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{
|
embed.Fields = []*discordgo.MessageEmbedField{
|
||||||
{
|
{
|
||||||
Name: "설명",
|
Name: "설명",
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package commands
|
package commands
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
|
||||||
"git.wh64.net/muffin/goMuffin/configs"
|
"git.wh64.net/muffin/goMuffin/configs"
|
||||||
|
@ -28,11 +29,11 @@ var InformationCommand *Command = &Command{
|
||||||
func informationRun(s *discordgo.Session, m any) {
|
func informationRun(s *discordgo.Session, m any) {
|
||||||
owner, _ := s.User(configs.Config.Bot.OwnerId)
|
owner, _ := s.User(configs.Config.Bot.OwnerId)
|
||||||
embed := &discordgo.MessageEmbed{
|
embed := &discordgo.MessageEmbed{
|
||||||
Title: s.State.User.Username + "의 정보",
|
Title: fmt.Sprintf("%s의 정보", s.State.User.Username),
|
||||||
Fields: []*discordgo.MessageEmbedField{
|
Fields: []*discordgo.MessageEmbedField{
|
||||||
{
|
{
|
||||||
Name: "운영 체제",
|
Name: "운영 체제",
|
||||||
Value: utils.InlineCode(runtime.GOOS + " " + runtime.GOARCH),
|
Value: utils.InlineCode(fmt.Sprintf("%s %s", runtime.GOOS, runtime.GOARCH)),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Name: "제작자",
|
Name: "제작자",
|
||||||
|
|
|
@ -53,7 +53,7 @@ var LearnCommand *Command = &Command{
|
||||||
|
|
||||||
func addPrefix(arr []string) (newArr []string) {
|
func addPrefix(arr []string) (newArr []string) {
|
||||||
for _, item := range arr {
|
for _, item := range arr {
|
||||||
newArr = append(newArr, "- "+item)
|
newArr = append(newArr, fmt.Sprintf("- %s", item))
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -123,7 +123,8 @@ func learnRun(c *Command, s *discordgo.Session, m any, args *[]string) {
|
||||||
disallows := []string{
|
disallows := []string{
|
||||||
"@everyone",
|
"@everyone",
|
||||||
"@here",
|
"@here",
|
||||||
"<@" + configs.Config.Bot.OwnerId + ">"}
|
fmt.Sprintf("<@%s>", configs.Config.Bot.OwnerId),
|
||||||
|
}
|
||||||
|
|
||||||
for _, ig := range ignores {
|
for _, ig := range ignores {
|
||||||
if strings.Contains(command, ig) {
|
if strings.Contains(command, ig) {
|
||||||
|
@ -191,7 +192,7 @@ func learnRun(c *Command, s *discordgo.Session, m any, args *[]string) {
|
||||||
|
|
||||||
embed := &discordgo.MessageEmbed{
|
embed := &discordgo.MessageEmbed{
|
||||||
Title: "✅ 성공",
|
Title: "✅ 성공",
|
||||||
Description: hangul.GetJosa(command, hangul.EUL_REUL) + " 배웠어요.",
|
Description: fmt.Sprintf("%s 배웠어요.", hangul.GetJosa(command, hangul.EUL_REUL)),
|
||||||
Color: int(utils.ESuccess),
|
Color: int(utils.ESuccess),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,6 @@ package commands
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"strconv"
|
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"git.wh64.net/muffin/goMuffin/databases"
|
"git.wh64.net/muffin/goMuffin/databases"
|
||||||
|
@ -34,7 +33,7 @@ var LearnedDataListCommand *Command = &Command{
|
||||||
|
|
||||||
func getDescriptions(datas *[]databases.Learn) (descriptions []string) {
|
func getDescriptions(datas *[]databases.Learn) (descriptions []string) {
|
||||||
for _, data := range *datas {
|
for _, data := range *datas {
|
||||||
descriptions = append(descriptions, "- "+data.Command+": "+data.Result)
|
descriptions = append(descriptions, fmt.Sprintf("- %s: %s", data.Command, data.Result))
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -103,8 +102,8 @@ func learnedDataListRun(s *discordgo.Session, m any) {
|
||||||
cur.All(context.TODO(), &datas)
|
cur.All(context.TODO(), &datas)
|
||||||
|
|
||||||
embed := &discordgo.MessageEmbed{
|
embed := &discordgo.MessageEmbed{
|
||||||
Title: globalName + "님이 알려주신 지식",
|
Title: fmt.Sprintf("%s님이 알려주신 지식", globalName),
|
||||||
Description: utils.CodeBlockWithLanguage("md", "# 총 "+strconv.Itoa(len(datas))+"개에요.\n"+strings.Join(getDescriptions(&datas), "\n")),
|
Description: utils.CodeBlockWithLanguage("md", fmt.Sprintf("# 총 %d개에요.\n%s", len(datas), strings.Join(getDescriptions(&datas), "\n"))),
|
||||||
Color: int(utils.EDefault),
|
Color: int(utils.EDefault),
|
||||||
Thumbnail: &discordgo.MessageEmbedThumbnail{
|
Thumbnail: &discordgo.MessageEmbedThumbnail{
|
||||||
URL: avatarUrl,
|
URL: avatarUrl,
|
||||||
|
|
|
@ -2,6 +2,7 @@ package components
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"git.wh64.net/muffin/goMuffin/commands"
|
"git.wh64.net/muffin/goMuffin/commands"
|
||||||
|
@ -68,7 +69,7 @@ var DeleteLearnedDataComponent *commands.Component = &commands.Component{
|
||||||
Embeds: &[]*discordgo.MessageEmbed{
|
Embeds: &[]*discordgo.MessageEmbed{
|
||||||
{
|
{
|
||||||
Title: "✅ 삭제 완료",
|
Title: "✅ 삭제 완료",
|
||||||
Description: itemId + "번을 삭ㅈ제했어요.",
|
Description: fmt.Sprintf("%s번을 삭ㅈ제했어요.", itemId),
|
||||||
Color: int(utils.ESuccess),
|
Color: int(utils.ESuccess),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
|
@ -2,6 +2,7 @@ package handler
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"strings"
|
"strings"
|
||||||
|
@ -65,7 +66,7 @@ func MessageCreate(s *discordgo.Session, m *discordgo.MessageCreate) {
|
||||||
|
|
||||||
if _, err := databases.Texts.InsertOne(context.TODO(), databases.InsertText{
|
if _, err := databases.Texts.InsertOne(context.TODO(), databases.InsertText{
|
||||||
Text: content,
|
Text: content,
|
||||||
Persona: "user:" + m.Author.Username,
|
Persona: fmt.Sprintf("user:%s", m.Author.Username),
|
||||||
CreatedAt: time.Now(),
|
CreatedAt: time.Now(),
|
||||||
}); err != nil {
|
}); err != nil {
|
||||||
log.Fatalln(err)
|
log.Fatalln(err)
|
||||||
|
@ -108,7 +109,7 @@ func MessageCreate(s *discordgo.Session, m *discordgo.MessageCreate) {
|
||||||
if x > 2 && len(learnDatas) != 0 {
|
if x > 2 && len(learnDatas) != 0 {
|
||||||
data := learnDatas[rand.Intn(len(learnDatas))]
|
data := learnDatas[rand.Intn(len(learnDatas))]
|
||||||
user, _ := s.User(data.UserId)
|
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
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package utils
|
package utils
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"strconv"
|
"fmt"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -18,12 +18,12 @@ const (
|
||||||
RelativeTime = "R"
|
RelativeTime = "R"
|
||||||
)
|
)
|
||||||
|
|
||||||
func InlineCode(str string) string {
|
func InlineCode(content string) string {
|
||||||
return "`" + str + "`"
|
return fmt.Sprintf("`%s`", content)
|
||||||
}
|
}
|
||||||
|
|
||||||
func CodeBlockWithLanguage(language string, content string) string {
|
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 {
|
func CodeBlock(content string) string {
|
||||||
|
@ -31,9 +31,9 @@ func CodeBlock(content string) string {
|
||||||
}
|
}
|
||||||
|
|
||||||
func Time(time *time.Time) string {
|
func Time(time *time.Time) string {
|
||||||
return "<t:" + strconv.FormatInt(time.Unix(), 10) + ">"
|
return fmt.Sprintf("<t:%d>", time.Unix())
|
||||||
}
|
}
|
||||||
|
|
||||||
func TimeWithStyle(time *time.Time, style string) string {
|
func TimeWithStyle(time *time.Time, style string) string {
|
||||||
return "<t:" + strconv.FormatInt(time.Unix(), 10) + ":" + style + ">"
|
return fmt.Sprintf("<t:%d:%s>", time.Unix(), style)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue