diff --git a/components/selectChat.go b/components/selectChat.go index 0514b51..9dc3ac9 100644 --- a/components/selectChat.go +++ b/components/selectChat.go @@ -21,7 +21,7 @@ var SelectChatComponent *commands.Component = &commands.Component{ return false } - userId := utils.GetSelectChatUserId(customId) + userId := utils.GetChatUserId(customId) if i.User.ID != userId { i.Reply(&discordgo.InteractionResponseData{ Flags: discordgo.MessageFlagsEphemeral | discordgo.MessageFlagsIsComponentsV2, diff --git a/utils/customIds.go b/utils/customIds.go index ccb718e..c95b5b9 100644 --- a/utils/customIds.go +++ b/utils/customIds.go @@ -9,7 +9,7 @@ import ( ) const ( - DeleteLearnedData = "#muffin/deleteLearnedData@" + DeleteLearnedData = "#muffin/deleteLearnedData$" PaginationEmbedPrev = "#muffin-pages/prev$" PaginationEmbedPages = "#muffin-pages/pages$" @@ -23,7 +23,9 @@ const ( DeregisterAgree = "#muffin/deregister/agree@" DeregisterDisagree = "#muffin/deregister/disagree@" - SelectChat = "#muffin/chat/select@" + SelectChat = "#muffin/chat/select$" + DeleteChat = "#muffin/chat/delete$" + DeleteChatCancel = "#muffin/chat/delete/cancel@" ) func MakeDeleteLearnedData(id string, number int, userId string) string { @@ -131,6 +133,29 @@ func GetSelectChatId(customId string) (id bson.ObjectID, itemId int) { return } -func GetSelectChatUserId(customId string) string { - return strings.ReplaceAll(RegexpDLDUserId.FindAllString(customId, 1)[0], "user_id=", "") +func GetChatUserId(customId string) string { + switch { + case strings.HasPrefix(customId, SelectChat), + strings.HasPrefix(customId, DeleteChat): + return strings.ReplaceAll(RegexpDLDUserId.FindAllString(customId, 1)[0], "user_id=", "") + case strings.HasPrefix(customId, DeleteChatCancel): + return customId[len(DeleteChatCancel):] + default: + return "" + } +} + +func MakeDeleteChat(id string, number int, userId string) string { + return fmt.Sprintf("%sid=%s&no=%d&user_id=%s", DeleteLearnedData, id, number, userId) +} + +func GetDeleteChatId(customId string) (id bson.ObjectID, itemId int) { + id, _ = bson.ObjectIDFromHex(strings.ReplaceAll(RegexpDLDId.FindAllString(customId, 1)[0], "id=", "")) + stringItemId := strings.ReplaceAll(RegexpDLDItemId.FindAllString(customId, 1)[0], "no=", "") + itemId, _ = strconv.Atoi(stringItemId) + return +} + +func MakeDeleteChatCancel(userId string) string { + return fmt.Sprintf("%s%s", DeleteChatCancel, userId) }