diff --git a/commands/dataLength.go b/commands/dataLength.go index 8abbe46..6f74d75 100644 --- a/commands/dataLength.go +++ b/commands/dataLength.go @@ -116,7 +116,7 @@ func dataLengthRun(m any, username, userId string) { // 나중에 djs처럼 Embed 만들어 주는 함수 만들어야겠다 // 지금은 임시방편 utils.NewMessageSender(m). - AddEmbed(&discordgo.MessageEmbed{ + AddEmbeds(&discordgo.MessageEmbed{ Title: "저장된 데이터량", Description: fmt.Sprintf("총합: %s개", utils.InlineCode(strconv.Itoa(sum))), Color: utils.EmbedDefault, diff --git a/commands/deleteLearnedData.go b/commands/deleteLearnedData.go index a43137e..fc0f85e 100644 --- a/commands/deleteLearnedData.go +++ b/commands/deleteLearnedData.go @@ -34,7 +34,7 @@ var DeleteLearnedDataCommand *Command = &Command{ command := strings.Join(*ctx.Args, " ") if command == "" { utils.NewMessageSender(ctx.Msg). - AddEmbed(&discordgo.MessageEmbed{ + AddEmbeds(&discordgo.MessageEmbed{ Title: "❌ 오류", Description: "올바르지 않ㅇ은 용법이에요.", Fields: []*discordgo.MessageEmbedField{ @@ -75,7 +75,7 @@ func deleteLearnedDataRun(m any, command, userId string) { cur, err := databases.Database.Learns.Find(context.TODO(), bson.M{"user_id": userId, "command": command}) if err != nil { utils.NewMessageSender(m). - AddEmbed(&discordgo.MessageEmbed{ + AddEmbeds(&discordgo.MessageEmbed{ Title: "❌ 오류", Description: "데이터를 가져오는데 실패했어요.", Color: utils.EmbedFail, @@ -89,7 +89,7 @@ func deleteLearnedDataRun(m any, command, userId string) { if len(data) < 1 { utils.NewMessageSender(m). - AddEmbed(&discordgo.MessageEmbed{ + AddEmbeds(&discordgo.MessageEmbed{ Title: "❌ 오류", Description: "해당 하는 지식ㅇ을 찾을 수 없어요.", Color: utils.EmbedFail, @@ -111,30 +111,32 @@ func deleteLearnedDataRun(m any, command, userId string) { } utils.NewMessageSender(m). - AddEmbed(&discordgo.MessageEmbed{ + AddEmbeds(&discordgo.MessageEmbed{ Title: fmt.Sprintf("%s 삭제", command), Description: utils.CodeBlock("md", fmt.Sprintf("# %s에 대한 대답 중 하나를 선ㅌ택하여 삭제해주세요.\n%s", command, description)), Color: utils.EmbedDefault, }). - AddComponent(discordgo.ActionsRow{ - Components: []discordgo.MessageComponent{ - discordgo.SelectMenu{ - MenuType: discordgo.StringSelectMenu, - CustomID: utils.MakeDeleteLearnedDataUserId(userId), - Options: options, - Placeholder: "ㅈ지울 응답을 선택해주세요.", + AddComponents( + discordgo.ActionsRow{ + Components: []discordgo.MessageComponent{ + discordgo.SelectMenu{ + MenuType: discordgo.StringSelectMenu, + CustomID: utils.MakeDeleteLearnedDataUserId(userId), + Options: options, + Placeholder: "ㅈ지울 응답을 선택해주세요.", + }, }, }, - }). - AddComponent(discordgo.ActionsRow{ - Components: []discordgo.MessageComponent{ - discordgo.Button{ - CustomID: utils.MakeDeleteLearnedDataCancel(userId), - Label: "취소하기", - Style: discordgo.DangerButton, - Disabled: false, + discordgo.ActionsRow{ + Components: []discordgo.MessageComponent{ + discordgo.Button{ + CustomID: utils.MakeDeleteLearnedDataCancel(userId), + Label: "취소하기", + Style: discordgo.DangerButton, + Disabled: false, + }, }, }, - }). + ). Send() } diff --git a/commands/help.go b/commands/help.go index 5d71151..cac8c6f 100644 --- a/commands/help.go +++ b/commands/help.go @@ -75,7 +75,7 @@ func helpRun(s *discordgo.Session, m any, commandName string) { strings.Join(getCommandsByCategory(Discommand, Chatting), "\n")), ) - utils.NewMessageSender(m).AddEmbed(embed).SetReply(true).Send() + utils.NewMessageSender(m).AddEmbeds(embed).SetReply(true).Send() return } @@ -126,5 +126,5 @@ func helpRun(s *discordgo.Session, m any, commandName string) { }) } - utils.NewMessageSender(m).AddEmbed(embed).SetReply(true).Send() + utils.NewMessageSender(m).AddEmbeds(embed).SetReply(true).Send() } diff --git a/commands/information.go b/commands/information.go index 72ced24..f1928ee 100644 --- a/commands/information.go +++ b/commands/information.go @@ -29,7 +29,7 @@ var InformationCommand *Command = &Command{ func informationRun(s *discordgo.Session, m any) { owner, _ := s.User(configs.Config.Bot.OwnerId) utils.NewMessageSender(m). - AddEmbed(&discordgo.MessageEmbed{ + AddEmbeds(&discordgo.MessageEmbed{ Title: fmt.Sprintf("%s의 정보", s.State.User.Username), Fields: []*discordgo.MessageEmbedField{ { diff --git a/commands/learn.go b/commands/learn.go index ce38f10..a285f09 100644 --- a/commands/learn.go +++ b/commands/learn.go @@ -60,7 +60,7 @@ var LearnCommand *Command = &Command{ MessageRun: func(ctx *MsgContext) { if len(*ctx.Args) < 2 { utils.NewMessageSender(ctx.Msg). - AddEmbed(&discordgo.MessageEmbed{ + AddEmbeds(&discordgo.MessageEmbed{ Title: "❌ 오류", Description: "올바르지 않ㅇ은 용법이에요.", Fields: []*discordgo.MessageEmbedField{ @@ -132,7 +132,7 @@ func learnRun(m any, userId, command, result string) { for _, ig := range ignores { if strings.Contains(command, ig) { utils.NewMessageSender(m). - AddEmbed( + AddEmbeds( &discordgo.MessageEmbed{ Title: "❌ 오류", Description: "해ㄷ당 단어는 배우기 껄끄ㄹ럽네요.", @@ -147,7 +147,7 @@ func learnRun(m any, userId, command, result string) { for _, di := range disallows { if strings.Contains(result, di) { utils.NewMessageSender(m). - AddEmbed( + AddEmbeds( &discordgo.MessageEmbed{ Title: "❌ 오류", Description: "해당 단ㅇ어의 대답으로 하기 좀 그렇ㄴ네요.", @@ -169,7 +169,7 @@ func learnRun(m any, userId, command, result string) { log.Println(err) utils.NewMessageSender(m). - AddEmbed(&discordgo.MessageEmbed{ + AddEmbeds(&discordgo.MessageEmbed{ Title: "❌ 오류", Description: "단어를 배우는데 오류가 생겼어요.", Color: utils.EmbedFail, @@ -180,7 +180,7 @@ func learnRun(m any, userId, command, result string) { } utils.NewMessageSender(m). - AddEmbed(&discordgo.MessageEmbed{ + AddEmbeds(&discordgo.MessageEmbed{ Title: "✅ 성공", Description: fmt.Sprintf("%s 배웠어요.", hangul.GetJosa(command, hangul.EUL_REUL)), Color: utils.EmbedSuccess, diff --git a/commands/learnedDataList.go b/commands/learnedDataList.go index b863570..51103bb 100644 --- a/commands/learnedDataList.go +++ b/commands/learnedDataList.go @@ -87,7 +87,7 @@ var LearnedDataListCommand *Command = &Command{ if err != nil { utils.NewMessageSender(ctx.Msg). - AddEmbed(&discordgo.MessageEmbed{ + AddEmbeds(&discordgo.MessageEmbed{ Title: "❌ 오류", Description: "개수의 값은 숫자여야해요.", Color: utils.EmbedFail, @@ -99,7 +99,7 @@ var LearnedDataListCommand *Command = &Command{ if float64(length) < LIST_MIN_VALUE { utils.NewMessageSender(ctx.Msg). - AddEmbed(&discordgo.MessageEmbed{ + AddEmbeds(&discordgo.MessageEmbed{ Title: "❌ 오류", Description: fmt.Sprintf("개수의 값은 %d보다 커야해요.", int(LIST_MIN_VALUE)), Color: utils.EmbedFail, @@ -111,7 +111,7 @@ var LearnedDataListCommand *Command = &Command{ if float64(length) > LIST_MAX_VALUE { utils.NewMessageSender(ctx.Msg). - AddEmbed(&discordgo.MessageEmbed{ + AddEmbeds(&discordgo.MessageEmbed{ Title: "❌ 오류", Description: fmt.Sprintf("개수의 값은 %d보다 작아야해요.", int(LIST_MAX_VALUE)), Color: utils.EmbedFail, @@ -202,7 +202,7 @@ func learnedDataListRun(s *discordgo.Session, m any, globalName, avatarUrl strin if err != nil { if err == mongo.ErrNoDocuments { utils.NewMessageSender(m). - AddEmbed(&discordgo.MessageEmbed{ + AddEmbeds(&discordgo.MessageEmbed{ Title: "❌ 오류", Description: "당신은 지식ㅇ을 가르쳐준 적이 없어요!", Color: utils.EmbedFail, @@ -215,7 +215,7 @@ func learnedDataListRun(s *discordgo.Session, m any, globalName, avatarUrl strin fmt.Println(err) utils.NewMessageSender(m). - AddEmbed(&discordgo.MessageEmbed{ + AddEmbeds(&discordgo.MessageEmbed{ Title: "❌ 오류", Description: "데이터를 가져오는데 실패했어요.", Color: utils.EmbedFail, diff --git a/utils/messageBuilder.go b/utils/messageBuilder.go index 1d60b78..a17660e 100644 --- a/utils/messageBuilder.go +++ b/utils/messageBuilder.go @@ -20,23 +20,13 @@ func NewMessageSender(m any) *MessageSender { return &MessageSender{m: m} } -func (s *MessageSender) AddEmbed(embed *discordgo.MessageEmbed) *MessageSender { - s.Embeds = append(s.Embeds, embed) +func (s *MessageSender) AddEmbeds(embeds ...*discordgo.MessageEmbed) *MessageSender { + s.Embeds = append(s.Embeds, embeds...) return s } -func (s *MessageSender) SetEmbeds(embeds []*discordgo.MessageEmbed) *MessageSender { - s.Embeds = embeds - return s -} - -func (s *MessageSender) AddComponent(cmp discordgo.MessageComponent) *MessageSender { - s.Components = append(s.Components, cmp) - return s -} - -func (s *MessageSender) SetComponents(components []discordgo.MessageComponent) *MessageSender { - s.Components = components +func (s *MessageSender) AddComponents(components ...discordgo.MessageComponent) *MessageSender { + s.Components = append(s.Components, components...) return s } diff --git a/utils/paginationEmbed.go b/utils/paginationEmbed.go index 99c444d..f8f7585 100644 --- a/utils/paginationEmbed.go +++ b/utils/paginationEmbed.go @@ -52,14 +52,14 @@ func (b *PaginationEmbedBuilder) Start() { } } -func makeComponents(id string, current, total int) *[]discordgo.MessageComponent { +func makeComponents(id string, current, total int) []discordgo.MessageComponent { disabled := false if total == 1 { disabled = true } - return &[]discordgo.MessageComponent{ + return []discordgo.MessageComponent{ discordgo.ActionsRow{ Components: []discordgo.MessageComponent{ discordgo.Button{ @@ -115,8 +115,8 @@ func startPaginationEmbed(m any, userId string, e *discordgo.MessageEmbed, data } NewMessageSender(m). - AddEmbed(e). - SetComponents(*makeComponents(id, p.Current, p.Total)). + AddEmbeds(e). + AddComponents(makeComponents(id, p.Current, p.Total)...). SetReply(true). SetEphemeral(true). Send() @@ -152,7 +152,7 @@ func (p *PaginationEmbed) Prev(i *InteractionCreate) { i.Update(&discordgo.InteractionResponseData{ Embeds: []*discordgo.MessageEmbed{p.Embed}, - Components: *makeComponents(p.id, p.Current, p.Total), + Components: makeComponents(p.id, p.Current, p.Total), }) } @@ -177,7 +177,7 @@ func (p *PaginationEmbed) Next(i *InteractionCreate) { i.Update(&discordgo.InteractionResponseData{ Embeds: []*discordgo.MessageEmbed{p.Embed}, - Components: *makeComponents(p.id, p.Current, p.Total), + Components: makeComponents(p.id, p.Current, p.Total), }) } @@ -216,7 +216,7 @@ func (p *PaginationEmbed) Set(i *InteractionCreate, page int) { i.Update(&discordgo.InteractionResponseData{ Embeds: []*discordgo.MessageEmbed{p.Embed}, - Components: *makeComponents(p.id, p.Current, p.Total), + Components: makeComponents(p.id, p.Current, p.Total), }) }