Fix: database logic
This commit is contained in:
parent
d96ae87d86
commit
25aae0c8cb
2 changed files with 16 additions and 25 deletions
|
@ -49,30 +49,12 @@ var DataLengthCommand *Command = &Command{
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
func getLength(data dataType, userId string) {
|
func getLength(data dataType, coll *mongo.Collection, filter bson.D) {
|
||||||
var err error
|
var err error
|
||||||
var cur *mongo.Cursor
|
var cur *mongo.Cursor
|
||||||
var datas []bson.M
|
var datas []bson.M
|
||||||
|
|
||||||
switch data {
|
cur, err = coll.Find(context.TODO(), filter)
|
||||||
case text:
|
|
||||||
cur, err = databases.Texts.Find(context.TODO(), bson.D{{}})
|
|
||||||
case muffin:
|
|
||||||
cur, err = databases.Texts.Find(context.TODO(), bson.D{{Key: "persona", Value: "muffin"}})
|
|
||||||
case nsfw:
|
|
||||||
cur, err = databases.Texts.Find(context.TODO(), bson.D{
|
|
||||||
{
|
|
||||||
Key: "persona",
|
|
||||||
Value: bson.M{
|
|
||||||
"$regex": "^user",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
})
|
|
||||||
case learn:
|
|
||||||
cur, err = databases.Learns.Find(context.TODO(), bson.D{{}})
|
|
||||||
case userLearn:
|
|
||||||
cur, err = databases.Learns.Find(context.TODO(), bson.D{{Key: "user_id", Value: userId}})
|
|
||||||
}
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
}
|
}
|
||||||
|
@ -113,11 +95,18 @@ func dataLengthRun(s *discordgo.Session, m any) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
go getLength(text, "")
|
go getLength(text, databases.Texts, bson.D{{}})
|
||||||
go getLength(muffin, "")
|
go getLength(muffin, databases.Texts, bson.D{{Key: "persona", Value: "muffin"}})
|
||||||
go getLength(nsfw, "")
|
go getLength(nsfw, databases.Texts, bson.D{
|
||||||
go getLength(learn, "")
|
{
|
||||||
go getLength(userLearn, userId)
|
Key: "persona",
|
||||||
|
Value: bson.M{
|
||||||
|
"$regex": "^user",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
go getLength(learn, databases.Learns, bson.D{{}})
|
||||||
|
go getLength(userLearn, databases.Learns, bson.D{{Key: "user_id", Value: userId}})
|
||||||
|
|
||||||
for range 5 {
|
for range 5 {
|
||||||
resp := <-ch
|
resp := <-ch
|
||||||
|
@ -134,6 +123,7 @@ func dataLengthRun(s *discordgo.Session, m any) {
|
||||||
userLearnLength = resp.length
|
userLearnLength = resp.length
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
close(ch)
|
||||||
|
|
||||||
sum := textLength + learnLength
|
sum := textLength + learnLength
|
||||||
|
|
||||||
|
|
|
@ -105,6 +105,7 @@ func MessageCreate(s *discordgo.Session, m *discordgo.MessageCreate) {
|
||||||
for range 2 {
|
for range 2 {
|
||||||
<-ch
|
<-ch
|
||||||
}
|
}
|
||||||
|
close(ch)
|
||||||
|
|
||||||
if x > 2 && len(learnDatas) != 0 {
|
if x > 2 && len(learnDatas) != 0 {
|
||||||
data := learnDatas[rand.Intn(len(learnDatas))]
|
data := learnDatas[rand.Intn(len(learnDatas))]
|
||||||
|
|
Loading…
Reference in a new issue