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 만들어 주는 함수 만들어야겠다
// 지금은 임시방편
utils.NewMessageSender(m).
AddEmbed(&discordgo.MessageEmbed{
AddEmbeds(&discordgo.MessageEmbed{
Title: "저장된 데이터량",
Description: fmt.Sprintf("총합: %s개", utils.InlineCode(strconv.Itoa(sum))),
Color: utils.EmbedDefault,

View file

@ -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,12 +111,13 @@ 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{
AddComponents(
discordgo.ActionsRow{
Components: []discordgo.MessageComponent{
discordgo.SelectMenu{
MenuType: discordgo.StringSelectMenu,
@ -125,8 +126,8 @@ func deleteLearnedDataRun(m any, command, userId string) {
Placeholder: "ㅈ지울 응답을 선택해주세요.",
},
},
}).
AddComponent(discordgo.ActionsRow{
},
discordgo.ActionsRow{
Components: []discordgo.MessageComponent{
discordgo.Button{
CustomID: utils.MakeDeleteLearnedDataCancel(userId),
@ -135,6 +136,7 @@ func deleteLearnedDataRun(m any, command, userId string) {
Disabled: false,
},
},
}).
},
).
Send()
}

View file

@ -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()
}

View file

@ -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{
{

View file

@ -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,

View file

@ -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,

View file

@ -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
}

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
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),
})
}