diff --git a/chatbot/memory.go b/chatbot/memory.go index e5e36c5..ecc5cdd 100644 --- a/chatbot/memory.go +++ b/chatbot/memory.go @@ -4,7 +4,6 @@ import ( "context" "git.wh64.net/muffin/goMuffin/databases" - "go.mongodb.org/mongo-driver/v2/bson" "google.golang.org/genai" ) @@ -18,7 +17,7 @@ func GetMemory(userId string) ([]*genai.Content, error) { memory := []*genai.Content{} - cur, err := databases.Database.Memory.Find(context.TODO(), bson.D{{Key: "user_id", Value: userId}}) + cur, err := databases.Database.Memory.Find(context.TODO(), databases.User{UserId: userId}) if err != nil { return memory, err } diff --git a/commands/dataLength.go b/commands/dataLength.go index b7941ae..2ecfae0 100644 --- a/commands/dataLength.go +++ b/commands/dataLength.go @@ -57,7 +57,7 @@ var DataLengthCommand *Command = &Command{ }, } -func getLength(ch chan chStruct, dType dataType, coll *mongo.Collection, filter bson.D) { +func getLength(ch chan chStruct, dType dataType, coll *mongo.Collection, filter any) { defer dataLengthWg.Done() var err error var cur *mongo.Cursor @@ -84,7 +84,7 @@ func dataLengthRun(s *discordgo.Session, m any, username, userId string) error { dataLengthWg.Add(5) go getLength(ch, text, databases.Database.Texts, bson.D{{}}) - go getLength(ch, muffin, databases.Database.Texts, bson.D{{Key: "persona", Value: "muffin"}}) + go getLength(ch, muffin, databases.Database.Texts, databases.Text{Persona: "muffin"}) go getLength(ch, nsfw, databases.Database.Texts, bson.D{ { Key: "persona", @@ -94,7 +94,7 @@ func dataLengthRun(s *discordgo.Session, m any, username, userId string) error { }, }) go getLength(ch, learn, databases.Database.Learns, bson.D{{}}) - go getLength(ch, userLearn, databases.Database.Learns, bson.D{{Key: "user_id", Value: userId}}) + go getLength(ch, userLearn, databases.Database.Learns, databases.Learn{UserId: userId}) go func() { dataLengthWg.Wait() diff --git a/commands/deleteLearnedData.go b/commands/deleteLearnedData.go index 9fb2b5e..1dddc2b 100644 --- a/commands/deleteLearnedData.go +++ b/commands/deleteLearnedData.go @@ -9,7 +9,6 @@ import ( "git.wh64.net/muffin/goMuffin/databases" "git.wh64.net/muffin/goMuffin/utils" "github.com/bwmarrin/discordgo" - "go.mongodb.org/mongo-driver/v2/bson" ) var DeleteLearnedDataCommand *Command = &Command{ @@ -78,7 +77,7 @@ func deleteLearnedDataRun(m any, command, userId string) error { var sections []discordgo.Section var containers []*discordgo.Container - cur, err := databases.Database.Learns.Find(context.TODO(), bson.M{"user_id": userId, "command": command}) + cur, err := databases.Database.Learns.Find(context.TODO(), databases.Learn{UserId: userId, Command: command}) if err != nil { return err } diff --git a/commands/devBlock.go b/commands/devBlock.go index 060a56b..f807173 100644 --- a/commands/devBlock.go +++ b/commands/devBlock.go @@ -48,19 +48,10 @@ var BlockCommand *Command = &Command{ } _, err = databases.Database.Users.UpdateOne(context.TODO(), - bson.D{{Key: "user_id", Value: userId}}, + databases.User{UserId: userId}, bson.D{{ - Key: "$set", - Value: bson.D{ - { - Key: "blocked", - Value: true, - }, - { - Key: "blocked_reason", - Value: reason, - }, - }, + Key: "$set", + Value: databases.User{Blocked: true, BlockedReason: reason}, }}) if err != nil { return err diff --git a/commands/devUnblock.go b/commands/devUnblock.go index dd6f019..132028c 100644 --- a/commands/devUnblock.go +++ b/commands/devUnblock.go @@ -40,19 +40,10 @@ var UnblockCommand *Command = &Command{ } _, err = databases.Database.Users.UpdateOne(context.TODO(), - bson.D{{Key: "user_id", Value: userId}}, + databases.User{UserId: userId}, bson.D{{ - Key: "$set", - Value: bson.D{ - { - Key: "blocked", - Value: false, - }, - { - Key: "blocked_reason", - Value: "", - }, - }, + Key: "$set", + Value: databases.User{Blocked: false, BlockedReason: ""}, }}) if err != nil { return err diff --git a/components/deleteLearnedData.go b/components/deleteLearnedData.go index 6217b52..5a8baf6 100644 --- a/components/deleteLearnedData.go +++ b/components/deleteLearnedData.go @@ -9,7 +9,6 @@ import ( "git.wh64.net/muffin/goMuffin/databases" "git.wh64.net/muffin/goMuffin/utils" "github.com/bwmarrin/discordgo" - "go.mongodb.org/mongo-driver/v2/bson" ) var DeleteLearnedDataComponent *commands.Component = &commands.Component{ @@ -45,7 +44,7 @@ var DeleteLearnedDataComponent *commands.Component = &commands.Component{ id, itemId := utils.GetDeleteLearnedDataId(i.MessageComponentData().CustomID) fmt.Println(id, itemId) - databases.Database.Learns.DeleteOne(context.TODO(), bson.D{{Key: "_id", Value: id}}) + databases.Database.Learns.DeleteOne(context.TODO(), databases.Learn{Id: id}) flags := discordgo.MessageFlagsIsComponentsV2 return i.EditReply(&utils.InteractionEdit{ diff --git a/components/deregister.go b/components/deregister.go index 9fa12d8..bcdd06c 100644 --- a/components/deregister.go +++ b/components/deregister.go @@ -8,7 +8,6 @@ import ( "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{ @@ -34,7 +33,7 @@ var DeregisterComponent *commands.Component = &commands.Component{ switch { case strings.HasPrefix(customId, utils.DeregisterAgree): - filter := bson.D{{Key: "user_id", Value: ctx.Inter.User.ID}} + filter := databases.User{UserId: ctx.Inter.User.ID} _, err := databases.Database.Users.DeleteOne(context.TODO(), filter) if err != nil { return err diff --git a/databases/Learn.go b/databases/Learn.go index 148dbb2..1b89138 100644 --- a/databases/Learn.go +++ b/databases/Learn.go @@ -8,8 +8,8 @@ import ( type Learn struct { Id bson.ObjectID `bson:"_id,omitempty" json:"id"` - Command string `bson:"command"` - Result string `bson:"result"` - UserId string `bson:"user_id"` - CreatedAt time.Time `bson:"created_at"` + Command string `bson:"command,omitempty"` + Result string `bson:"result,omitempty"` + UserId string `bson:"user_id,omitempty"` + CreatedAt time.Time `bson:"created_at,omitempty"` } diff --git a/databases/Memory.go b/databases/Memory.go index d2e0c49..a883527 100644 --- a/databases/Memory.go +++ b/databases/Memory.go @@ -4,7 +4,8 @@ import "go.mongodb.org/mongo-driver/v2/bson" type Memory struct { Id bson.ObjectID `bson:"_id,omitempty"` - UserId string `bson:"user_id"` - Content string `bson:"content"` - Answer string `bson:"answer"` + UserId string `bson:"user_id,omitempty"` + Content string `bson:"content,omitempty"` + Answer string `bson:"answer,omitempty"` + ChatId bson.ObjectID `bson:"chat_id,omitempty"` } diff --git a/databases/Text.go b/databases/Text.go index 81e0341..b474fe9 100644 --- a/databases/Text.go +++ b/databases/Text.go @@ -8,7 +8,7 @@ import ( type Text struct { Id bson.ObjectID `bson:"_id,omitempty" json:"id"` - Text string `bson:"text" json:"text"` - Persona string `bson:"persona" json:"persona"` - CreatedAt time.Time `bson:"created_at"` + Text string `bson:"text,omitempty" json:"text"` + Persona string `bson:"persona,omitempty" json:"persona"` + CreatedAt time.Time `bson:"created_at,omitempty"` } diff --git a/databases/User.go b/databases/User.go index c5318dc..855cb9a 100644 --- a/databases/User.go +++ b/databases/User.go @@ -9,10 +9,10 @@ import ( type User struct { 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"` + UserId string `bson:"user_id,omitempty"` + Blocked bool `bson:"blocked,omitempty"` + BlockedReason string `bson:"blocked_reason,omitempty"` + CreatedAt time.Time `bson:"created_at,omitempty"` } func (d *MuffinDatabase) IsUser(userId string) bool {