fix: database filter
This commit is contained in:
parent
ef7ab396b5
commit
76cacdd660
11 changed files with 28 additions and 49 deletions
|
@ -4,7 +4,6 @@ import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
"git.wh64.net/muffin/goMuffin/databases"
|
"git.wh64.net/muffin/goMuffin/databases"
|
||||||
"go.mongodb.org/mongo-driver/v2/bson"
|
|
||||||
"google.golang.org/genai"
|
"google.golang.org/genai"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -18,7 +17,7 @@ func GetMemory(userId string) ([]*genai.Content, error) {
|
||||||
|
|
||||||
memory := []*genai.Content{}
|
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 {
|
if err != nil {
|
||||||
return memory, err
|
return memory, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -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()
|
defer dataLengthWg.Done()
|
||||||
var err error
|
var err error
|
||||||
var cur *mongo.Cursor
|
var cur *mongo.Cursor
|
||||||
|
@ -84,7 +84,7 @@ func dataLengthRun(s *discordgo.Session, m any, username, userId string) error {
|
||||||
|
|
||||||
dataLengthWg.Add(5)
|
dataLengthWg.Add(5)
|
||||||
go getLength(ch, text, databases.Database.Texts, bson.D{{}})
|
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{
|
go getLength(ch, nsfw, databases.Database.Texts, bson.D{
|
||||||
{
|
{
|
||||||
Key: "persona",
|
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, 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() {
|
go func() {
|
||||||
dataLengthWg.Wait()
|
dataLengthWg.Wait()
|
||||||
|
|
|
@ -9,7 +9,6 @@ import (
|
||||||
"git.wh64.net/muffin/goMuffin/databases"
|
"git.wh64.net/muffin/goMuffin/databases"
|
||||||
"git.wh64.net/muffin/goMuffin/utils"
|
"git.wh64.net/muffin/goMuffin/utils"
|
||||||
"github.com/bwmarrin/discordgo"
|
"github.com/bwmarrin/discordgo"
|
||||||
"go.mongodb.org/mongo-driver/v2/bson"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var DeleteLearnedDataCommand *Command = &Command{
|
var DeleteLearnedDataCommand *Command = &Command{
|
||||||
|
@ -78,7 +77,7 @@ func deleteLearnedDataRun(m any, command, userId string) error {
|
||||||
var sections []discordgo.Section
|
var sections []discordgo.Section
|
||||||
var containers []*discordgo.Container
|
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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,19 +48,10 @@ var BlockCommand *Command = &Command{
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = databases.Database.Users.UpdateOne(context.TODO(),
|
_, err = databases.Database.Users.UpdateOne(context.TODO(),
|
||||||
bson.D{{Key: "user_id", Value: userId}},
|
databases.User{UserId: userId},
|
||||||
bson.D{{
|
bson.D{{
|
||||||
Key: "$set",
|
Key: "$set",
|
||||||
Value: bson.D{
|
Value: databases.User{Blocked: true, BlockedReason: reason},
|
||||||
{
|
|
||||||
Key: "blocked",
|
|
||||||
Value: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
Key: "blocked_reason",
|
|
||||||
Value: reason,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}})
|
}})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
|
@ -40,19 +40,10 @@ var UnblockCommand *Command = &Command{
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = databases.Database.Users.UpdateOne(context.TODO(),
|
_, err = databases.Database.Users.UpdateOne(context.TODO(),
|
||||||
bson.D{{Key: "user_id", Value: userId}},
|
databases.User{UserId: userId},
|
||||||
bson.D{{
|
bson.D{{
|
||||||
Key: "$set",
|
Key: "$set",
|
||||||
Value: bson.D{
|
Value: databases.User{Blocked: false, BlockedReason: ""},
|
||||||
{
|
|
||||||
Key: "blocked",
|
|
||||||
Value: false,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
Key: "blocked_reason",
|
|
||||||
Value: "",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}})
|
}})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
|
@ -9,7 +9,6 @@ import (
|
||||||
"git.wh64.net/muffin/goMuffin/databases"
|
"git.wh64.net/muffin/goMuffin/databases"
|
||||||
"git.wh64.net/muffin/goMuffin/utils"
|
"git.wh64.net/muffin/goMuffin/utils"
|
||||||
"github.com/bwmarrin/discordgo"
|
"github.com/bwmarrin/discordgo"
|
||||||
"go.mongodb.org/mongo-driver/v2/bson"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var DeleteLearnedDataComponent *commands.Component = &commands.Component{
|
var DeleteLearnedDataComponent *commands.Component = &commands.Component{
|
||||||
|
@ -45,7 +44,7 @@ var DeleteLearnedDataComponent *commands.Component = &commands.Component{
|
||||||
id, itemId := utils.GetDeleteLearnedDataId(i.MessageComponentData().CustomID)
|
id, itemId := utils.GetDeleteLearnedDataId(i.MessageComponentData().CustomID)
|
||||||
fmt.Println(id, itemId)
|
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
|
flags := discordgo.MessageFlagsIsComponentsV2
|
||||||
return i.EditReply(&utils.InteractionEdit{
|
return i.EditReply(&utils.InteractionEdit{
|
||||||
|
|
|
@ -8,7 +8,6 @@ import (
|
||||||
"git.wh64.net/muffin/goMuffin/databases"
|
"git.wh64.net/muffin/goMuffin/databases"
|
||||||
"git.wh64.net/muffin/goMuffin/utils"
|
"git.wh64.net/muffin/goMuffin/utils"
|
||||||
"github.com/bwmarrin/discordgo"
|
"github.com/bwmarrin/discordgo"
|
||||||
"go.mongodb.org/mongo-driver/v2/bson"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var DeregisterComponent *commands.Component = &commands.Component{
|
var DeregisterComponent *commands.Component = &commands.Component{
|
||||||
|
@ -34,7 +33,7 @@ var DeregisterComponent *commands.Component = &commands.Component{
|
||||||
|
|
||||||
switch {
|
switch {
|
||||||
case strings.HasPrefix(customId, utils.DeregisterAgree):
|
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)
|
_, err := databases.Database.Users.DeleteOne(context.TODO(), filter)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
|
@ -8,8 +8,8 @@ import (
|
||||||
|
|
||||||
type Learn struct {
|
type Learn struct {
|
||||||
Id bson.ObjectID `bson:"_id,omitempty" json:"id"`
|
Id bson.ObjectID `bson:"_id,omitempty" json:"id"`
|
||||||
Command string `bson:"command"`
|
Command string `bson:"command,omitempty"`
|
||||||
Result string `bson:"result"`
|
Result string `bson:"result,omitempty"`
|
||||||
UserId string `bson:"user_id"`
|
UserId string `bson:"user_id,omitempty"`
|
||||||
CreatedAt time.Time `bson:"created_at"`
|
CreatedAt time.Time `bson:"created_at,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,8 @@ import "go.mongodb.org/mongo-driver/v2/bson"
|
||||||
|
|
||||||
type Memory struct {
|
type Memory struct {
|
||||||
Id bson.ObjectID `bson:"_id,omitempty"`
|
Id bson.ObjectID `bson:"_id,omitempty"`
|
||||||
UserId string `bson:"user_id"`
|
UserId string `bson:"user_id,omitempty"`
|
||||||
Content string `bson:"content"`
|
Content string `bson:"content,omitempty"`
|
||||||
Answer string `bson:"answer"`
|
Answer string `bson:"answer,omitempty"`
|
||||||
|
ChatId bson.ObjectID `bson:"chat_id,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,7 +8,7 @@ import (
|
||||||
|
|
||||||
type Text struct {
|
type Text struct {
|
||||||
Id bson.ObjectID `bson:"_id,omitempty" json:"id"`
|
Id bson.ObjectID `bson:"_id,omitempty" json:"id"`
|
||||||
Text string `bson:"text" json:"text"`
|
Text string `bson:"text,omitempty" json:"text"`
|
||||||
Persona string `bson:"persona" json:"persona"`
|
Persona string `bson:"persona,omitempty" json:"persona"`
|
||||||
CreatedAt time.Time `bson:"created_at"`
|
CreatedAt time.Time `bson:"created_at,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,10 +9,10 @@ import (
|
||||||
|
|
||||||
type User struct {
|
type User struct {
|
||||||
Id bson.ObjectID `bson:"_id,omitempty"`
|
Id bson.ObjectID `bson:"_id,omitempty"`
|
||||||
UserId string `bson:"user_id"`
|
UserId string `bson:"user_id,omitempty"`
|
||||||
Blocked bool `bson:"blocked"`
|
Blocked bool `bson:"blocked,omitempty"`
|
||||||
BlockedReason string `bson:"blocked_reason"`
|
BlockedReason string `bson:"blocked_reason,omitempty"`
|
||||||
CreatedAt time.Time `bson:"created_at"`
|
CreatedAt time.Time `bson:"created_at,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *MuffinDatabase) IsUser(userId string) bool {
|
func (d *MuffinDatabase) IsUser(userId string) bool {
|
||||||
|
|
Loading…
Reference in a new issue