feat: Add deregister command
This commit is contained in:
parent
eb991797d7
commit
c98dcce7b2
6 changed files with 161 additions and 5 deletions
55
commands/deregister.go
Normal file
55
commands/deregister.go
Normal file
|
@ -0,0 +1,55 @@
|
||||||
|
package commands
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"git.wh64.net/muffin/goMuffin/configs"
|
||||||
|
"git.wh64.net/muffin/goMuffin/utils"
|
||||||
|
"github.com/bwmarrin/discordgo"
|
||||||
|
)
|
||||||
|
|
||||||
|
var DeregisterCommand *Command = &Command{
|
||||||
|
ApplicationCommand: &discordgo.ApplicationCommand{
|
||||||
|
Name: "탈퇴",
|
||||||
|
Description: "이 봇에서 탈퇴해요.",
|
||||||
|
},
|
||||||
|
DetailedDescription: &DetailedDescription{
|
||||||
|
Usage: fmt.Sprintf("%s탈퇴", configs.Config.Bot.Prefix),
|
||||||
|
},
|
||||||
|
Category: General,
|
||||||
|
RegisterMessageCommand: true,
|
||||||
|
RegisterApplicationCommand: true,
|
||||||
|
Flags: CommandFlagsIsRegistered,
|
||||||
|
MessageRun: func(ctx *MsgContext) {
|
||||||
|
deregisterRun(ctx.Msg, ctx.Msg.Author.ID, ctx.Msg.Session.State.User.Username)
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
func deregisterRun(m any, userId, botName string) {
|
||||||
|
utils.NewMessageSender(m).
|
||||||
|
AddComponents(discordgo.Container{
|
||||||
|
Components: []discordgo.MessageComponent{
|
||||||
|
discordgo.TextDisplay{
|
||||||
|
Content: fmt.Sprintf("### %s 탈퇴\n- 정말로 해당 서비스에서 탈퇴하시겠어요?\n> 주의: **모든 데이터는 삭제되어요.**", botName),
|
||||||
|
},
|
||||||
|
discordgo.ActionsRow{
|
||||||
|
Components: []discordgo.MessageComponent{
|
||||||
|
discordgo.Button{
|
||||||
|
CustomID: utils.MakeDeregisterAgree(userId),
|
||||||
|
Label: "탈퇴",
|
||||||
|
Style: discordgo.SuccessButton,
|
||||||
|
},
|
||||||
|
discordgo.Button{
|
||||||
|
CustomID: utils.MakeDeregisterDisagree(userId),
|
||||||
|
Label: "취소",
|
||||||
|
Style: discordgo.DangerButton,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}).
|
||||||
|
SetComponentsV2(true).
|
||||||
|
SetEphemeral(true).
|
||||||
|
SetReply(true).
|
||||||
|
Send()
|
||||||
|
}
|
77
components/deregister.go
Normal file
77
components/deregister.go
Normal file
|
@ -0,0 +1,77 @@
|
||||||
|
package components
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"log"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"git.wh64.net/muffin/goMuffin/commands"
|
||||||
|
"git.wh64.net/muffin/goMuffin/databases"
|
||||||
|
"git.wh64.net/muffin/goMuffin/utils"
|
||||||
|
"github.com/bwmarrin/discordgo"
|
||||||
|
"go.mongodb.org/mongo-driver/v2/bson"
|
||||||
|
)
|
||||||
|
|
||||||
|
var DeregisterComponent *commands.Component = &commands.Component{
|
||||||
|
Parse: func(ctx *commands.ComponentContext) bool {
|
||||||
|
customId := ctx.Inter.MessageComponentData().CustomID
|
||||||
|
if !strings.HasPrefix(customId, utils.DeregisterAgree) && !strings.HasPrefix(customId, utils.DeregisterDisagree) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
if ctx.Inter.User.ID != utils.GetDeregisterUserId(customId) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
},
|
||||||
|
Run: func(ctx *commands.ComponentContext) {
|
||||||
|
ctx.Inter.DeferUpdate()
|
||||||
|
customId := ctx.Inter.MessageComponentData().CustomID
|
||||||
|
flags := discordgo.MessageFlagsIsComponentsV2
|
||||||
|
|
||||||
|
switch {
|
||||||
|
case strings.HasPrefix(customId, utils.DeregisterAgree):
|
||||||
|
filter := bson.D{{Key: "user_id", Value: ctx.Inter.User.ID}}
|
||||||
|
_, err := databases.Database.Users.DeleteOne(context.TODO(), filter)
|
||||||
|
if err != nil {
|
||||||
|
log.Println(err)
|
||||||
|
// 나중에 에러처리 바꿔야지 :(
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = databases.Database.Learns.DeleteMany(context.TODO(), filter)
|
||||||
|
if err != nil {
|
||||||
|
log.Println(err)
|
||||||
|
// 나중에 에러처리 바꿔야지 :(
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = databases.Database.Memory.DeleteMany(context.TODO(), filter)
|
||||||
|
if err != nil {
|
||||||
|
log.Println(err)
|
||||||
|
// 나중에 에러처리 바꿔야지 :(
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx.Inter.EditReply(&utils.InteractionEdit{
|
||||||
|
Flags: &flags,
|
||||||
|
Components: &[]discordgo.MessageComponent{
|
||||||
|
utils.GetSuccessContainer(discordgo.TextDisplay{
|
||||||
|
Content: "탈퇴를 했어요.",
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
})
|
||||||
|
return
|
||||||
|
case strings.HasPrefix(customId, utils.DeregisterDisagree):
|
||||||
|
ctx.Inter.EditReply(&utils.InteractionEdit{
|
||||||
|
Flags: &flags,
|
||||||
|
Components: &[]discordgo.MessageComponent{
|
||||||
|
utils.GetDeclineContainer(discordgo.TextDisplay{
|
||||||
|
Content: "탈퇴를 거부했어요.",
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}
|
|
@ -20,7 +20,7 @@ var RegisterComponent *commands.Component = &commands.Component{
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
if ctx.Inter.User.ID != utils.GetServicesUserId(customId) {
|
if ctx.Inter.User.ID != utils.GetServiceUserId(customId) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
|
|
|
@ -7,7 +7,7 @@ import (
|
||||||
"git.wh64.net/muffin/goMuffin/utils"
|
"git.wh64.net/muffin/goMuffin/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
const MUFFIN_VERSION = "0.0.0-madeleine_canary.250606a"
|
const MUFFIN_VERSION = "0.0.0-madeleine_canary.250620a"
|
||||||
|
|
||||||
var updatedString string = utils.RegexpDecimals.FindAllStringSubmatch(MUFFIN_VERSION, -1)[3][0]
|
var updatedString string = utils.RegexpDecimals.FindAllStringSubmatch(MUFFIN_VERSION, -1)[3][0]
|
||||||
|
|
||||||
|
|
2
main.go
2
main.go
|
@ -33,10 +33,12 @@ func init() {
|
||||||
go commands.Discommand.LoadCommand(commands.SwitchModeCommand)
|
go commands.Discommand.LoadCommand(commands.SwitchModeCommand)
|
||||||
go commands.Discommand.LoadCommand(commands.ChatCommand)
|
go commands.Discommand.LoadCommand(commands.ChatCommand)
|
||||||
go commands.Discommand.LoadCommand(commands.RegisterCommand)
|
go commands.Discommand.LoadCommand(commands.RegisterCommand)
|
||||||
|
go commands.Discommand.LoadCommand(commands.DeregisterCommand)
|
||||||
|
|
||||||
go commands.Discommand.LoadComponent(components.DeleteLearnedDataComponent)
|
go commands.Discommand.LoadComponent(components.DeleteLearnedDataComponent)
|
||||||
go commands.Discommand.LoadComponent(components.PaginationEmbedComponent)
|
go commands.Discommand.LoadComponent(components.PaginationEmbedComponent)
|
||||||
go commands.Discommand.LoadComponent(components.RegisterComponent)
|
go commands.Discommand.LoadComponent(components.RegisterComponent)
|
||||||
|
go commands.Discommand.LoadComponent(components.DeregisterComponent)
|
||||||
|
|
||||||
go commands.Discommand.LoadModal(modals.PaginationEmbedModal)
|
go commands.Discommand.LoadModal(modals.PaginationEmbedModal)
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,8 +17,11 @@ const (
|
||||||
PaginationEmbedModal = "#muffin-pages/modal$"
|
PaginationEmbedModal = "#muffin-pages/modal$"
|
||||||
PaginationEmbedSetPage = "#muffin-pages/modal/set$"
|
PaginationEmbedSetPage = "#muffin-pages/modal/set$"
|
||||||
|
|
||||||
ServiceAgree = "#muffin/serviceAgree@"
|
ServiceAgree = "#muffin/service/agree@"
|
||||||
ServiceDisagree = "#muffin/serviceDisagree@"
|
ServiceDisagree = "#muffin/service/disagree@"
|
||||||
|
|
||||||
|
DeregisterAgree = "#muffin/deregister/agree@"
|
||||||
|
DeregisterDisagree = "#muffin/deregister/disagree@"
|
||||||
)
|
)
|
||||||
|
|
||||||
func MakeDeleteLearnedData(id string, number int, userId string) string {
|
func MakeDeleteLearnedData(id string, number int, userId string) string {
|
||||||
|
@ -85,7 +88,7 @@ func MakeServiceDisagree(userId string) string {
|
||||||
return fmt.Sprintf("%s%s", ServiceDisagree, userId)
|
return fmt.Sprintf("%s%s", ServiceDisagree, userId)
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetServicesUserId(customId string) string {
|
func GetServiceUserId(customId string) string {
|
||||||
switch {
|
switch {
|
||||||
case strings.HasPrefix(customId, ServiceAgree):
|
case strings.HasPrefix(customId, ServiceAgree):
|
||||||
return customId[len(ServiceAgree):]
|
return customId[len(ServiceAgree):]
|
||||||
|
@ -95,3 +98,22 @@ func GetServicesUserId(customId string) string {
|
||||||
return customId
|
return customId
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func MakeDeregisterAgree(userId string) string {
|
||||||
|
return fmt.Sprintf("%s%s", DeregisterAgree, userId)
|
||||||
|
}
|
||||||
|
|
||||||
|
func MakeDeregisterDisagree(userId string) string {
|
||||||
|
return fmt.Sprintf("%s%s", DeregisterDisagree, userId)
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetDeregisterUserId(customId string) string {
|
||||||
|
switch {
|
||||||
|
case strings.HasPrefix(customId, DeregisterAgree):
|
||||||
|
return customId[len(DeregisterAgree):]
|
||||||
|
case strings.HasPrefix(customId, DeregisterDisagree):
|
||||||
|
return customId[len(DeregisterDisagree):]
|
||||||
|
default:
|
||||||
|
return customId
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue