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,
|
Category: Chatting,
|
||||||
RegisterApplicationCommand: true,
|
RegisterApplicationCommand: true,
|
||||||
RegisterMessageCommand: false,
|
RegisterMessageCommand: false,
|
||||||
Flags: CommandFlagsIsRegistered,
|
Flags: CommandFlagsIsRegistered | CommandFlagsIsBlocked,
|
||||||
ChatInputRun: func(ctx *ChatInputContext) error {
|
ChatInputRun: func(ctx *ChatInputContext) error {
|
||||||
i := ctx.Inter
|
i := ctx.Inter
|
||||||
i.DeferReply(&discordgo.InteractionResponseData{})
|
i.DeferReply(&discordgo.InteractionResponseData{})
|
||||||
|
|
|
@ -44,7 +44,7 @@ var DataLengthCommand *Command = &Command{
|
||||||
Category: General,
|
Category: General,
|
||||||
RegisterApplicationCommand: true,
|
RegisterApplicationCommand: true,
|
||||||
RegisterMessageCommand: true,
|
RegisterMessageCommand: true,
|
||||||
Flags: CommandFlagsIsRegistered,
|
Flags: CommandFlagsIsRegistered | CommandFlagsIsBlocked,
|
||||||
MessageRun: func(ctx *MsgContext) error {
|
MessageRun: func(ctx *MsgContext) error {
|
||||||
return dataLengthRun(ctx.Msg.Session, ctx.Msg, ctx.Msg.Author.Username, ctx.Msg.Author.ID)
|
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,
|
Category: Chatting,
|
||||||
RegisterApplicationCommand: true,
|
RegisterApplicationCommand: true,
|
||||||
RegisterMessageCommand: true,
|
RegisterMessageCommand: true,
|
||||||
Flags: CommandFlagsIsRegistered,
|
Flags: CommandFlagsIsRegistered | CommandFlagsIsBlocked,
|
||||||
MessageRun: func(ctx *MsgContext) error {
|
MessageRun: func(ctx *MsgContext) error {
|
||||||
command := strings.Join(*ctx.Args, " ")
|
command := strings.Join(*ctx.Args, " ")
|
||||||
if command == "" {
|
if command == "" {
|
||||||
|
|
|
@ -19,7 +19,7 @@ var DeregisterCommand *Command = &Command{
|
||||||
Category: General,
|
Category: General,
|
||||||
RegisterMessageCommand: true,
|
RegisterMessageCommand: true,
|
||||||
RegisterApplicationCommand: true,
|
RegisterApplicationCommand: true,
|
||||||
Flags: CommandFlagsIsRegistered,
|
Flags: CommandFlagsIsRegistered | CommandFlagsIsBlocked,
|
||||||
MessageRun: func(ctx *MsgContext) error {
|
MessageRun: func(ctx *MsgContext) error {
|
||||||
return deregisterRun(ctx.Msg, ctx.Msg.Author.ID, ctx.Msg.Session.State.User.Username)
|
return deregisterRun(ctx.Msg, ctx.Msg.Author.ID, ctx.Msg.Session.State.User.Username)
|
||||||
},
|
},
|
||||||
|
|
|
@ -84,6 +84,7 @@ const (
|
||||||
const (
|
const (
|
||||||
CommandFlagsIsDeveloper CommandFlags = 1 << iota
|
CommandFlagsIsDeveloper CommandFlags = 1 << iota
|
||||||
CommandFlagsIsRegistered
|
CommandFlagsIsRegistered
|
||||||
|
CommandFlagsIsBlocked
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@ -151,6 +152,17 @@ func (d *DiscommandStruct) MessageRun(name string, s *discordgo.Session, msg *di
|
||||||
return nil
|
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 command.MessageRun(&MsgContext{m, &args, command})
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
@ -186,6 +198,17 @@ func (d *DiscommandStruct) ChatInputRun(name string, s *discordgo.Session, inter
|
||||||
return nil
|
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 command.ChatInputRun(&ChatInputContext{i, command})
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
|
|
@ -31,6 +31,7 @@ var HelpCommand *Command = &Command{
|
||||||
Category: General,
|
Category: General,
|
||||||
RegisterApplicationCommand: true,
|
RegisterApplicationCommand: true,
|
||||||
RegisterMessageCommand: true,
|
RegisterMessageCommand: true,
|
||||||
|
Flags: CommandFlagsIsBlocked,
|
||||||
MessageRun: func(ctx *MsgContext) error {
|
MessageRun: func(ctx *MsgContext) error {
|
||||||
return helpRun(ctx.Msg.Session, ctx.Msg, strings.Join(*ctx.Args, " "))
|
return helpRun(ctx.Msg.Session, ctx.Msg, strings.Join(*ctx.Args, " "))
|
||||||
},
|
},
|
||||||
|
|
|
@ -19,6 +19,7 @@ var InformationCommand *Command = &Command{
|
||||||
Category: General,
|
Category: General,
|
||||||
RegisterApplicationCommand: true,
|
RegisterApplicationCommand: true,
|
||||||
RegisterMessageCommand: true,
|
RegisterMessageCommand: true,
|
||||||
|
Flags: CommandFlagsIsBlocked,
|
||||||
MessageRun: func(ctx *MsgContext) error {
|
MessageRun: func(ctx *MsgContext) error {
|
||||||
return informationRun(ctx.Msg.Session, ctx.Msg)
|
return informationRun(ctx.Msg.Session, ctx.Msg)
|
||||||
},
|
},
|
||||||
|
|
|
@ -58,7 +58,7 @@ var LearnCommand *Command = &Command{
|
||||||
Category: Chatting,
|
Category: Chatting,
|
||||||
RegisterApplicationCommand: true,
|
RegisterApplicationCommand: true,
|
||||||
RegisterMessageCommand: true,
|
RegisterMessageCommand: true,
|
||||||
Flags: CommandFlagsIsRegistered,
|
Flags: CommandFlagsIsRegistered | CommandFlagsIsBlocked,
|
||||||
MessageRun: func(ctx *MsgContext) error {
|
MessageRun: func(ctx *MsgContext) error {
|
||||||
if len(*ctx.Args) < 2 {
|
if len(*ctx.Args) < 2 {
|
||||||
utils.NewMessageSender(ctx.Msg).
|
utils.NewMessageSender(ctx.Msg).
|
||||||
|
|
|
@ -53,7 +53,7 @@ var LearnedDataListCommand *Command = &Command{
|
||||||
Category: Chatting,
|
Category: Chatting,
|
||||||
RegisterApplicationCommand: true,
|
RegisterApplicationCommand: true,
|
||||||
RegisterMessageCommand: true,
|
RegisterMessageCommand: true,
|
||||||
Flags: CommandFlagsIsRegistered,
|
Flags: CommandFlagsIsRegistered | CommandFlagsIsBlocked,
|
||||||
MessageRun: func(ctx *MsgContext) error {
|
MessageRun: func(ctx *MsgContext) error {
|
||||||
var length int
|
var length int
|
||||||
|
|
||||||
|
|
|
@ -20,6 +20,7 @@ var RegisterCommand *Command = &Command{
|
||||||
Category: General,
|
Category: General,
|
||||||
RegisterMessageCommand: true,
|
RegisterMessageCommand: true,
|
||||||
RegisterApplicationCommand: true,
|
RegisterApplicationCommand: true,
|
||||||
|
Flags: CommandFlagsIsBlocked,
|
||||||
MessageRun: func(ctx *MsgContext) error {
|
MessageRun: func(ctx *MsgContext) error {
|
||||||
return registerRun(ctx.Msg, ctx.Msg.Author.ID, ctx.Msg.Session.State.User.Username)
|
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)
|
d.Users.FindOne(context.TODO(), bson.D{{Key: "user_id", Value: userId}}).Decode(&user)
|
||||||
return user != nil
|
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()
|
Send()
|
||||||
return
|
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)
|
s.ChannelTyping(m.ChannelID)
|
||||||
|
|
||||||
str, err := chatbot.ChatBot.GetResponse(m.Author, strings.TrimPrefix(content, "대화 "))
|
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),
|
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