fix: customId

This commit is contained in:
Siwoo Jeon 2025-07-14 21:34:28 +09:00
parent ff32a29bc4
commit d83823ffa6
Signed by: migan
GPG key ID: 036E9A8C5E8E48DA
2 changed files with 30 additions and 5 deletions

View file

@ -21,7 +21,7 @@ var SelectChatComponent *commands.Component = &commands.Component{
return false return false
} }
userId := utils.GetSelectChatUserId(customId) userId := utils.GetChatUserId(customId)
if i.User.ID != userId { if i.User.ID != userId {
i.Reply(&discordgo.InteractionResponseData{ i.Reply(&discordgo.InteractionResponseData{
Flags: discordgo.MessageFlagsEphemeral | discordgo.MessageFlagsIsComponentsV2, Flags: discordgo.MessageFlagsEphemeral | discordgo.MessageFlagsIsComponentsV2,

View file

@ -9,7 +9,7 @@ import (
) )
const ( const (
DeleteLearnedData = "#muffin/deleteLearnedData@" DeleteLearnedData = "#muffin/deleteLearnedData$"
PaginationEmbedPrev = "#muffin-pages/prev$" PaginationEmbedPrev = "#muffin-pages/prev$"
PaginationEmbedPages = "#muffin-pages/pages$" PaginationEmbedPages = "#muffin-pages/pages$"
@ -23,7 +23,9 @@ const (
DeregisterAgree = "#muffin/deregister/agree@" DeregisterAgree = "#muffin/deregister/agree@"
DeregisterDisagree = "#muffin/deregister/disagree@" 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 { func MakeDeleteLearnedData(id string, number int, userId string) string {
@ -131,6 +133,29 @@ func GetSelectChatId(customId string) (id bson.ObjectID, itemId int) {
return return
} }
func GetSelectChatUserId(customId string) string { func GetChatUserId(customId string) string {
return strings.ReplaceAll(RegexpDLDUserId.FindAllString(customId, 1)[0], "user_id=", "") 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)
} }