fix!: remove AddEmbed, AddComponent and add AddEmbeds, AddComponents

This commit is contained in:
Siwoo Jeon 2025-05-17 22:04:05 +09:00
parent 5f0bb32e9b
commit 797bd56b3d
Signed by: migan
GPG key ID: 036E9A8C5E8E48DA
8 changed files with 47 additions and 55 deletions

View file

@ -116,7 +116,7 @@ func dataLengthRun(m any, username, userId string) {
// 나중에 djs처럼 Embed 만들어 주는 함수 만들어야겠다 // 나중에 djs처럼 Embed 만들어 주는 함수 만들어야겠다
// 지금은 임시방편 // 지금은 임시방편
utils.NewMessageSender(m). utils.NewMessageSender(m).
AddEmbed(&discordgo.MessageEmbed{ AddEmbeds(&discordgo.MessageEmbed{
Title: "저장된 데이터량", Title: "저장된 데이터량",
Description: fmt.Sprintf("총합: %s개", utils.InlineCode(strconv.Itoa(sum))), Description: fmt.Sprintf("총합: %s개", utils.InlineCode(strconv.Itoa(sum))),
Color: utils.EmbedDefault, Color: utils.EmbedDefault,

View file

@ -34,7 +34,7 @@ var DeleteLearnedDataCommand *Command = &Command{
command := strings.Join(*ctx.Args, " ") command := strings.Join(*ctx.Args, " ")
if command == "" { if command == "" {
utils.NewMessageSender(ctx.Msg). utils.NewMessageSender(ctx.Msg).
AddEmbed(&discordgo.MessageEmbed{ AddEmbeds(&discordgo.MessageEmbed{
Title: "❌ 오류", Title: "❌ 오류",
Description: "올바르지 않ㅇ은 용법이에요.", Description: "올바르지 않ㅇ은 용법이에요.",
Fields: []*discordgo.MessageEmbedField{ 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}) cur, err := databases.Database.Learns.Find(context.TODO(), bson.M{"user_id": userId, "command": command})
if err != nil { if err != nil {
utils.NewMessageSender(m). utils.NewMessageSender(m).
AddEmbed(&discordgo.MessageEmbed{ AddEmbeds(&discordgo.MessageEmbed{
Title: "❌ 오류", Title: "❌ 오류",
Description: "데이터를 가져오는데 실패했어요.", Description: "데이터를 가져오는데 실패했어요.",
Color: utils.EmbedFail, Color: utils.EmbedFail,
@ -89,7 +89,7 @@ func deleteLearnedDataRun(m any, command, userId string) {
if len(data) < 1 { if len(data) < 1 {
utils.NewMessageSender(m). utils.NewMessageSender(m).
AddEmbed(&discordgo.MessageEmbed{ AddEmbeds(&discordgo.MessageEmbed{
Title: "❌ 오류", Title: "❌ 오류",
Description: "해당 하는 지식ㅇ을 찾을 수 없어요.", Description: "해당 하는 지식ㅇ을 찾을 수 없어요.",
Color: utils.EmbedFail, Color: utils.EmbedFail,
@ -111,30 +111,32 @@ func deleteLearnedDataRun(m any, command, userId string) {
} }
utils.NewMessageSender(m). utils.NewMessageSender(m).
AddEmbed(&discordgo.MessageEmbed{ AddEmbeds(&discordgo.MessageEmbed{
Title: fmt.Sprintf("%s 삭제", command), Title: fmt.Sprintf("%s 삭제", command),
Description: utils.CodeBlock("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,
}). }).
AddComponent(discordgo.ActionsRow{ AddComponents(
Components: []discordgo.MessageComponent{ discordgo.ActionsRow{
discordgo.SelectMenu{ Components: []discordgo.MessageComponent{
MenuType: discordgo.StringSelectMenu, discordgo.SelectMenu{
CustomID: utils.MakeDeleteLearnedDataUserId(userId), MenuType: discordgo.StringSelectMenu,
Options: options, CustomID: utils.MakeDeleteLearnedDataUserId(userId),
Placeholder: "ㅈ지울 응답을 선택해주세요.", Options: options,
Placeholder: "ㅈ지울 응답을 선택해주세요.",
},
}, },
}, },
}). discordgo.ActionsRow{
AddComponent(discordgo.ActionsRow{ Components: []discordgo.MessageComponent{
Components: []discordgo.MessageComponent{ discordgo.Button{
discordgo.Button{ CustomID: utils.MakeDeleteLearnedDataCancel(userId),
CustomID: utils.MakeDeleteLearnedDataCancel(userId), Label: "취소하기",
Label: "취소하기", Style: discordgo.DangerButton,
Style: discordgo.DangerButton, Disabled: false,
Disabled: false, },
}, },
}, },
}). ).
Send() Send()
} }

View file

@ -75,7 +75,7 @@ func helpRun(s *discordgo.Session, m any, commandName string) {
strings.Join(getCommandsByCategory(Discommand, Chatting), "\n")), strings.Join(getCommandsByCategory(Discommand, Chatting), "\n")),
) )
utils.NewMessageSender(m).AddEmbed(embed).SetReply(true).Send() utils.NewMessageSender(m).AddEmbeds(embed).SetReply(true).Send()
return 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()
} }

View file

@ -29,7 +29,7 @@ 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)
utils.NewMessageSender(m). utils.NewMessageSender(m).
AddEmbed(&discordgo.MessageEmbed{ AddEmbeds(&discordgo.MessageEmbed{
Title: fmt.Sprintf("%s의 정보", s.State.User.Username), Title: fmt.Sprintf("%s의 정보", s.State.User.Username),
Fields: []*discordgo.MessageEmbedField{ Fields: []*discordgo.MessageEmbedField{
{ {

View file

@ -60,7 +60,7 @@ var LearnCommand *Command = &Command{
MessageRun: func(ctx *MsgContext) { MessageRun: func(ctx *MsgContext) {
if len(*ctx.Args) < 2 { if len(*ctx.Args) < 2 {
utils.NewMessageSender(ctx.Msg). utils.NewMessageSender(ctx.Msg).
AddEmbed(&discordgo.MessageEmbed{ AddEmbeds(&discordgo.MessageEmbed{
Title: "❌ 오류", Title: "❌ 오류",
Description: "올바르지 않ㅇ은 용법이에요.", Description: "올바르지 않ㅇ은 용법이에요.",
Fields: []*discordgo.MessageEmbedField{ Fields: []*discordgo.MessageEmbedField{
@ -132,7 +132,7 @@ func learnRun(m any, userId, command, result string) {
for _, ig := range ignores { for _, ig := range ignores {
if strings.Contains(command, ig) { if strings.Contains(command, ig) {
utils.NewMessageSender(m). utils.NewMessageSender(m).
AddEmbed( AddEmbeds(
&discordgo.MessageEmbed{ &discordgo.MessageEmbed{
Title: "❌ 오류", Title: "❌ 오류",
Description: "해ㄷ당 단어는 배우기 껄끄ㄹ럽네요.", Description: "해ㄷ당 단어는 배우기 껄끄ㄹ럽네요.",
@ -147,7 +147,7 @@ func learnRun(m any, userId, command, result string) {
for _, di := range disallows { for _, di := range disallows {
if strings.Contains(result, di) { if strings.Contains(result, di) {
utils.NewMessageSender(m). utils.NewMessageSender(m).
AddEmbed( AddEmbeds(
&discordgo.MessageEmbed{ &discordgo.MessageEmbed{
Title: "❌ 오류", Title: "❌ 오류",
Description: "해당 단ㅇ어의 대답으로 하기 좀 그렇ㄴ네요.", Description: "해당 단ㅇ어의 대답으로 하기 좀 그렇ㄴ네요.",
@ -169,7 +169,7 @@ func learnRun(m any, userId, command, result string) {
log.Println(err) log.Println(err)
utils.NewMessageSender(m). utils.NewMessageSender(m).
AddEmbed(&discordgo.MessageEmbed{ AddEmbeds(&discordgo.MessageEmbed{
Title: "❌ 오류", Title: "❌ 오류",
Description: "단어를 배우는데 오류가 생겼어요.", Description: "단어를 배우는데 오류가 생겼어요.",
Color: utils.EmbedFail, Color: utils.EmbedFail,
@ -180,7 +180,7 @@ func learnRun(m any, userId, command, result string) {
} }
utils.NewMessageSender(m). utils.NewMessageSender(m).
AddEmbed(&discordgo.MessageEmbed{ AddEmbeds(&discordgo.MessageEmbed{
Title: "✅ 성공", Title: "✅ 성공",
Description: fmt.Sprintf("%s 배웠어요.", hangul.GetJosa(command, hangul.EUL_REUL)), Description: fmt.Sprintf("%s 배웠어요.", hangul.GetJosa(command, hangul.EUL_REUL)),
Color: utils.EmbedSuccess, Color: utils.EmbedSuccess,

View file

@ -87,7 +87,7 @@ var LearnedDataListCommand *Command = &Command{
if err != nil { if err != nil {
utils.NewMessageSender(ctx.Msg). utils.NewMessageSender(ctx.Msg).
AddEmbed(&discordgo.MessageEmbed{ AddEmbeds(&discordgo.MessageEmbed{
Title: "❌ 오류", Title: "❌ 오류",
Description: "개수의 값은 숫자여야해요.", Description: "개수의 값은 숫자여야해요.",
Color: utils.EmbedFail, Color: utils.EmbedFail,
@ -99,7 +99,7 @@ var LearnedDataListCommand *Command = &Command{
if float64(length) < LIST_MIN_VALUE { if float64(length) < LIST_MIN_VALUE {
utils.NewMessageSender(ctx.Msg). utils.NewMessageSender(ctx.Msg).
AddEmbed(&discordgo.MessageEmbed{ AddEmbeds(&discordgo.MessageEmbed{
Title: "❌ 오류", Title: "❌ 오류",
Description: fmt.Sprintf("개수의 값은 %d보다 커야해요.", int(LIST_MIN_VALUE)), Description: fmt.Sprintf("개수의 값은 %d보다 커야해요.", int(LIST_MIN_VALUE)),
Color: utils.EmbedFail, Color: utils.EmbedFail,
@ -111,7 +111,7 @@ var LearnedDataListCommand *Command = &Command{
if float64(length) > LIST_MAX_VALUE { if float64(length) > LIST_MAX_VALUE {
utils.NewMessageSender(ctx.Msg). utils.NewMessageSender(ctx.Msg).
AddEmbed(&discordgo.MessageEmbed{ AddEmbeds(&discordgo.MessageEmbed{
Title: "❌ 오류", Title: "❌ 오류",
Description: fmt.Sprintf("개수의 값은 %d보다 작아야해요.", int(LIST_MAX_VALUE)), Description: fmt.Sprintf("개수의 값은 %d보다 작아야해요.", int(LIST_MAX_VALUE)),
Color: utils.EmbedFail, Color: utils.EmbedFail,
@ -202,7 +202,7 @@ func learnedDataListRun(s *discordgo.Session, m any, globalName, avatarUrl strin
if err != nil { if err != nil {
if err == mongo.ErrNoDocuments { if err == mongo.ErrNoDocuments {
utils.NewMessageSender(m). utils.NewMessageSender(m).
AddEmbed(&discordgo.MessageEmbed{ AddEmbeds(&discordgo.MessageEmbed{
Title: "❌ 오류", Title: "❌ 오류",
Description: "당신은 지식ㅇ을 가르쳐준 적이 없어요!", Description: "당신은 지식ㅇ을 가르쳐준 적이 없어요!",
Color: utils.EmbedFail, Color: utils.EmbedFail,
@ -215,7 +215,7 @@ func learnedDataListRun(s *discordgo.Session, m any, globalName, avatarUrl strin
fmt.Println(err) fmt.Println(err)
utils.NewMessageSender(m). utils.NewMessageSender(m).
AddEmbed(&discordgo.MessageEmbed{ AddEmbeds(&discordgo.MessageEmbed{
Title: "❌ 오류", Title: "❌ 오류",
Description: "데이터를 가져오는데 실패했어요.", Description: "데이터를 가져오는데 실패했어요.",
Color: utils.EmbedFail, Color: utils.EmbedFail,

View file

@ -20,23 +20,13 @@ func NewMessageSender(m any) *MessageSender {
return &MessageSender{m: m} return &MessageSender{m: m}
} }
func (s *MessageSender) AddEmbed(embed *discordgo.MessageEmbed) *MessageSender { func (s *MessageSender) AddEmbeds(embeds ...*discordgo.MessageEmbed) *MessageSender {
s.Embeds = append(s.Embeds, embed) s.Embeds = append(s.Embeds, embeds...)
return s return s
} }
func (s *MessageSender) SetEmbeds(embeds []*discordgo.MessageEmbed) *MessageSender { func (s *MessageSender) AddComponents(components ...discordgo.MessageComponent) *MessageSender {
s.Embeds = embeds s.Components = append(s.Components, components...)
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
return s return s
} }

View file

@ -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 disabled := false
if total == 1 { if total == 1 {
disabled = true disabled = true
} }
return &[]discordgo.MessageComponent{ return []discordgo.MessageComponent{
discordgo.ActionsRow{ discordgo.ActionsRow{
Components: []discordgo.MessageComponent{ Components: []discordgo.MessageComponent{
discordgo.Button{ discordgo.Button{
@ -115,8 +115,8 @@ func startPaginationEmbed(m any, userId string, e *discordgo.MessageEmbed, data
} }
NewMessageSender(m). NewMessageSender(m).
AddEmbed(e). AddEmbeds(e).
SetComponents(*makeComponents(id, p.Current, p.Total)). AddComponents(makeComponents(id, p.Current, p.Total)...).
SetReply(true). SetReply(true).
SetEphemeral(true). SetEphemeral(true).
Send() Send()
@ -152,7 +152,7 @@ func (p *PaginationEmbed) Prev(i *InteractionCreate) {
i.Update(&discordgo.InteractionResponseData{ i.Update(&discordgo.InteractionResponseData{
Embeds: []*discordgo.MessageEmbed{p.Embed}, 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{ i.Update(&discordgo.InteractionResponseData{
Embeds: []*discordgo.MessageEmbed{p.Embed}, 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{ i.Update(&discordgo.InteractionResponseData{
Embeds: []*discordgo.MessageEmbed{p.Embed}, Embeds: []*discordgo.MessageEmbed{p.Embed},
Components: *makeComponents(p.id, p.Current, p.Total), Components: makeComponents(p.id, p.Current, p.Total),
}) })
} }