feat: blocked user
This commit is contained in:
parent
3dbc32ee7b
commit
48c9d643c7
13 changed files with 56 additions and 6 deletions
|
@ -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{})
|
||||
|
|
|
@ -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)
|
||||
},
|
||||
|
|
|
@ -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 == "" {
|
||||
|
|
|
@ -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)
|
||||
},
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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, " "))
|
||||
},
|
||||
|
|
|
@ -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)
|
||||
},
|
||||
|
|
|
@ -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).
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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)
|
||||
},
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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, "대화 "))
|
||||
|
|
|
@ -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),
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue