feat: blocked user

This commit is contained in:
Siwoo Jeon 2025-07-07 18:49:16 +09:00
parent 3dbc32ee7b
commit 48c9d643c7
Signed by: migan
GPG key ID: 036E9A8C5E8E48DA
13 changed files with 56 additions and 6 deletions

View file

@ -28,7 +28,7 @@ var ChatCommand *Command = &Command{
Category: Chatting,
RegisterApplicationCommand: true,
RegisterMessageCommand: false,
Flags: CommandFlagsIsRegistered,
Flags: CommandFlagsIsRegistered | CommandFlagsIsBlocked,
ChatInputRun: func(ctx *ChatInputContext) error {
i := ctx.Inter
i.DeferReply(&discordgo.InteractionResponseData{})

View file

@ -44,7 +44,7 @@ var DataLengthCommand *Command = &Command{
Category: General,
RegisterApplicationCommand: true,
RegisterMessageCommand: true,
Flags: CommandFlagsIsRegistered,
Flags: CommandFlagsIsRegistered | CommandFlagsIsBlocked,
MessageRun: func(ctx *MsgContext) error {
return dataLengthRun(ctx.Msg.Session, ctx.Msg, ctx.Msg.Author.Username, ctx.Msg.Author.ID)
},

View file

@ -32,7 +32,7 @@ var DeleteLearnedDataCommand *Command = &Command{
Category: Chatting,
RegisterApplicationCommand: true,
RegisterMessageCommand: true,
Flags: CommandFlagsIsRegistered,
Flags: CommandFlagsIsRegistered | CommandFlagsIsBlocked,
MessageRun: func(ctx *MsgContext) error {
command := strings.Join(*ctx.Args, " ")
if command == "" {

View file

@ -19,7 +19,7 @@ var DeregisterCommand *Command = &Command{
Category: General,
RegisterMessageCommand: true,
RegisterApplicationCommand: true,
Flags: CommandFlagsIsRegistered,
Flags: CommandFlagsIsRegistered | CommandFlagsIsBlocked,
MessageRun: func(ctx *MsgContext) error {
return deregisterRun(ctx.Msg, ctx.Msg.Author.ID, ctx.Msg.Session.State.User.Username)
},

View file

@ -84,6 +84,7 @@ const (
const (
CommandFlagsIsDeveloper CommandFlags = 1 << iota
CommandFlagsIsRegistered
CommandFlagsIsBlocked
)
var (
@ -151,6 +152,17 @@ func (d *DiscommandStruct) MessageRun(name string, s *discordgo.Session, msg *di
return nil
}
blocked, reason := databases.Database.IsUserBlocked(m.Author.ID)
if command.Flags&CommandFlagsIsBlocked != 0 && blocked {
user, _ := s.User(m.Author.ID)
utils.NewMessageSender(m).
AddComponents(utils.GetUserIsBlockedContainer(user.GlobalName, reason)).
SetComponentsV2(true).
SetReply(true).
Send()
return nil
}
return command.MessageRun(&MsgContext{m, &args, command})
}
return nil
@ -186,6 +198,17 @@ func (d *DiscommandStruct) ChatInputRun(name string, s *discordgo.Session, inter
return nil
}
blocked, reason := databases.Database.IsUserBlocked(i.User.ID)
if command.Flags&CommandFlagsIsBlocked != 0 && blocked {
user, _ := s.User(i.User.ID)
utils.NewMessageSender(i).
AddComponents(utils.GetUserIsBlockedContainer(user.GlobalName, reason)).
SetComponentsV2(true).
SetReply(true).
Send()
return nil
}
return command.ChatInputRun(&ChatInputContext{i, command})
}
return nil

View file

@ -31,6 +31,7 @@ var HelpCommand *Command = &Command{
Category: General,
RegisterApplicationCommand: true,
RegisterMessageCommand: true,
Flags: CommandFlagsIsBlocked,
MessageRun: func(ctx *MsgContext) error {
return helpRun(ctx.Msg.Session, ctx.Msg, strings.Join(*ctx.Args, " "))
},

View file

@ -19,6 +19,7 @@ var InformationCommand *Command = &Command{
Category: General,
RegisterApplicationCommand: true,
RegisterMessageCommand: true,
Flags: CommandFlagsIsBlocked,
MessageRun: func(ctx *MsgContext) error {
return informationRun(ctx.Msg.Session, ctx.Msg)
},

View file

@ -58,7 +58,7 @@ var LearnCommand *Command = &Command{
Category: Chatting,
RegisterApplicationCommand: true,
RegisterMessageCommand: true,
Flags: CommandFlagsIsRegistered,
Flags: CommandFlagsIsRegistered | CommandFlagsIsBlocked,
MessageRun: func(ctx *MsgContext) error {
if len(*ctx.Args) < 2 {
utils.NewMessageSender(ctx.Msg).

View file

@ -53,7 +53,7 @@ var LearnedDataListCommand *Command = &Command{
Category: Chatting,
RegisterApplicationCommand: true,
RegisterMessageCommand: true,
Flags: CommandFlagsIsRegistered,
Flags: CommandFlagsIsRegistered | CommandFlagsIsBlocked,
MessageRun: func(ctx *MsgContext) error {
var length int

View file

@ -20,6 +20,7 @@ var RegisterCommand *Command = &Command{
Category: General,
RegisterMessageCommand: true,
RegisterApplicationCommand: true,
Flags: CommandFlagsIsBlocked,
MessageRun: func(ctx *MsgContext) error {
return registerRun(ctx.Msg, ctx.Msg.Author.ID, ctx.Msg.Session.State.User.Username)
},

View file

@ -20,3 +20,9 @@ func (d *MuffinDatabase) IsUser(userId string) bool {
d.Users.FindOne(context.TODO(), bson.D{{Key: "user_id", Value: userId}}).Decode(&user)
return user != nil
}
func (d *MuffinDatabase) IsUserBlocked(userId string) (bool, string) {
var user User
d.Users.FindOne(context.TODO(), bson.D{{Key: "user_id", Value: userId}}).Decode(&user)
return user.Blocked, user.BlockedReason
}

View file

@ -49,6 +49,18 @@ func MessageCreate(s *discordgo.Session, m *discordgo.MessageCreate) {
Send()
return
}
blocked, reason := databases.Database.IsUserBlocked(m.Author.ID)
if blocked {
user, _ := s.User(m.Author.ID)
utils.NewMessageSender(m).
AddComponents(utils.GetUserIsBlockedContainer(user.GlobalName, reason)).
SetComponentsV2(true).
SetReply(true).
Send()
return
}
s.ChannelTyping(m.ChannelID)
str, err := chatbot.ChatBot.GetResponse(m.Author, strings.TrimPrefix(content, "대화 "))

View file

@ -56,3 +56,9 @@ func GetUserIsNotRegisteredErrContainer(prefix string) *discordgo.Container {
Content: fmt.Sprintf("해당 기능은 등록된 사용자만 쓸 수 있어요. `%s가입`으로 가입해주새요.", prefix),
})
}
func GetUserIsBlockedContainer(globalName, reason string) *discordgo.Container {
return GetDeclineContainer(discordgo.TextDisplay{
Content: fmt.Sprintf("- %s님은 서비스에서 차단되었어요.\n> 사유: %s", globalName, reason),
})
}