fix: customId
This commit is contained in:
parent
ff32a29bc4
commit
d83823ffa6
2 changed files with 30 additions and 5 deletions
|
@ -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,
|
||||
|
|
|
@ -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 {
|
||||
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)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue