feat: block command
This commit is contained in:
parent
2f655a1384
commit
ce6a242a24
3 changed files with 81 additions and 4 deletions
75
commands/block.go
Normal file
75
commands/block.go
Normal file
|
@ -0,0 +1,75 @@
|
|||
package commands
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"git.wh64.net/muffin/goMuffin/configs"
|
||||
"git.wh64.net/muffin/goMuffin/databases"
|
||||
"git.wh64.net/muffin/goMuffin/utils"
|
||||
"github.com/bwmarrin/discordgo"
|
||||
"go.mongodb.org/mongo-driver/v2/bson"
|
||||
)
|
||||
|
||||
var BlockCommand *Command = &Command{
|
||||
ApplicationCommand: &discordgo.ApplicationCommand{
|
||||
Name: "차단",
|
||||
Description: "유저를 차단합니다.",
|
||||
},
|
||||
DetailedDescription: &DetailedDescription{
|
||||
Usage: fmt.Sprintf("%s차단 (유저의 ID) [사유]", configs.Config.Bot.Prefix),
|
||||
},
|
||||
Category: DeveloperOnly,
|
||||
RegisterApplicationCommand: false,
|
||||
RegisterMessageCommand: true,
|
||||
Flags: CommandFlagsIsDeveloper,
|
||||
MessageRun: func(ctx *MsgContext) error {
|
||||
var reason string
|
||||
if len(*ctx.Args) < 1 {
|
||||
utils.NewMessageSender(ctx.Msg).
|
||||
AddComponents(utils.GetErrorContainer(discordgo.TextDisplay{Content: "유저 ID는 필수에요."})).
|
||||
SetComponentsV2(true).
|
||||
SetReply(true).
|
||||
Send()
|
||||
return nil
|
||||
}
|
||||
|
||||
userId := (*ctx.Args)[0]
|
||||
if len(*ctx.Args) >= 2 {
|
||||
reason = strings.Join((*ctx.Args)[1:], " ")
|
||||
} else {
|
||||
reason = "없음"
|
||||
}
|
||||
|
||||
user, err := ctx.Msg.Session.User(userId)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
_, err = databases.Database.Users.UpdateOne(context.TODO(),
|
||||
bson.D{{Key: "user_id", Value: userId}},
|
||||
bson.D{{
|
||||
Key: "$set",
|
||||
Value: bson.D{
|
||||
{
|
||||
Key: "blocked",
|
||||
Value: true,
|
||||
},
|
||||
{
|
||||
Key: "blocked_reason",
|
||||
Value: reason,
|
||||
},
|
||||
},
|
||||
}})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return utils.NewMessageSender(ctx.Msg).
|
||||
AddComponents(utils.GetSuccessContainer(discordgo.TextDisplay{Content: fmt.Sprintf("- %s를 성공적으로 차단했어요.\n> 사유: %s", user.GlobalName, reason)})).
|
||||
SetComponentsV2(true).
|
||||
SetReply(true).
|
||||
Send()
|
||||
},
|
||||
}
|
|
@ -7,7 +7,7 @@ import (
|
|||
"git.wh64.net/muffin/goMuffin/utils"
|
||||
)
|
||||
|
||||
const MUFFIN_VERSION = "0.0.0-madeleine_canary.250621b"
|
||||
const MUFFIN_VERSION = "6.0.0-madeleine_develop.250703a"
|
||||
|
||||
var updatedString string = utils.RegexpDecimals.FindAllStringSubmatch(MUFFIN_VERSION, -1)[3][0]
|
||||
|
||||
|
|
|
@ -8,9 +8,11 @@ import (
|
|||
)
|
||||
|
||||
type User struct {
|
||||
Id bson.ObjectID `bson:"_id,omitempty"`
|
||||
UserId string `bson:"user_id"`
|
||||
CreatedAt time.Time `bson:"created_at"`
|
||||
Id bson.ObjectID `bson:"_id,omitempty"`
|
||||
UserId string `bson:"user_id"`
|
||||
Blocked bool `bson:"blocked"`
|
||||
BlockedReason string `bson:"blocked_reason"`
|
||||
CreatedAt time.Time `bson:"created_at"`
|
||||
}
|
||||
|
||||
func (d *MuffinDatabase) IsUser(userId string) bool {
|
||||
|
|
Loading…
Reference in a new issue