feat: Add gorountine in messageCreate random Message
This commit is contained in:
parent
3768bb162e
commit
3d0ae3b8ec
2 changed files with 28 additions and 14 deletions
|
@ -7,5 +7,4 @@ import (
|
||||||
|
|
||||||
func InteractionCreate(s *discordgo.Session, i *discordgo.InteractionCreate) {
|
func InteractionCreate(s *discordgo.Session, i *discordgo.InteractionCreate) {
|
||||||
commands.Discommand.ChatInputRun(i.ApplicationCommandData().Name, s, i)
|
commands.Discommand.ChatInputRun(i.ApplicationCommandData().Name, s, i)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,6 +44,7 @@ func MessageCreate(s *discordgo.Session, m *discordgo.MessageCreate) {
|
||||||
var learnDatas []databases.Learn
|
var learnDatas []databases.Learn
|
||||||
var filter bson.D
|
var filter bson.D
|
||||||
|
|
||||||
|
ch := make(chan int)
|
||||||
x := rand.Intn(5)
|
x := rand.Intn(5)
|
||||||
|
|
||||||
channel, _ := s.Channel(m.ChannelID)
|
channel, _ := s.Channel(m.ChannelID)
|
||||||
|
@ -62,12 +63,19 @@ func MessageCreate(s *discordgo.Session, m *discordgo.MessageCreate) {
|
||||||
filter = bson.D{{Key: "persona", Value: "muffin"}}
|
filter = bson.D{{Key: "persona", Value: "muffin"}}
|
||||||
}
|
}
|
||||||
|
|
||||||
tCur, err := databases.Texts.Find(context.TODO(), filter)
|
go func() {
|
||||||
|
cur, err := databases.Texts.Find(context.TODO(), filter)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalln(err)
|
log.Fatalln(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
lCur, err := databases.Learns.Find(context.TODO(), bson.D{{Key: "command", Value: content}})
|
defer cur.Close(context.TODO())
|
||||||
|
|
||||||
|
cur.All(context.TODO(), &datas)
|
||||||
|
ch <- 1
|
||||||
|
}()
|
||||||
|
go func() {
|
||||||
|
cur, err := databases.Learns.Find(context.TODO(), bson.D{{Key: "command", Value: content}})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if err == mongo.ErrNilDocument {
|
if err == mongo.ErrNilDocument {
|
||||||
learnDatas = []databases.Learn{}
|
learnDatas = []databases.Learn{}
|
||||||
|
@ -75,8 +83,15 @@ func MessageCreate(s *discordgo.Session, m *discordgo.MessageCreate) {
|
||||||
log.Fatalln(err)
|
log.Fatalln(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
tCur.All(context.TODO(), &datas)
|
defer cur.Close(context.TODO())
|
||||||
lCur.All(context.TODO(), &learnDatas)
|
|
||||||
|
cur.All(context.TODO(), &learnDatas)
|
||||||
|
ch <- 1
|
||||||
|
}()
|
||||||
|
|
||||||
|
for i := 0; i < 2; i++ {
|
||||||
|
<-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