Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
undefined-moe committed Aug 26, 2020
1 parent 72f6b7b commit 6b3bc95
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions packages/plugin-teach/src/database/mongo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,13 @@ extendDatabase<typeof MongoDatabase>('koishi-plugin-mongo', {
const dialogues = (await this.db.collection('dialogue').find(query).toArray())
.filter((dialogue) => !this.app.bail('dialogue/fetch', dialogue, test))
dialogues.forEach(d => defineProperty(d, '_backup', clone(d)))
return dialogues
return dialogues.filter(value => {
if (value.flag & Dialogue.Flag.regexp) {
const regex = new RegExp(value.question, 'i')
return regex.test(test.question) || regex.test(test.original)
}
return true
})
},

async createDialogue(dialogue: Dialogue, argv: Dialogue.Argv, revert = false) {
Expand Down Expand Up @@ -151,12 +157,12 @@ export default function apply(ctx: Context) {

ctx.on('dialogue/mongo', (test, conditionals) => {
if (!test.groups || !test.groups.length) return
const $and: FilterQuery<Dialogue>[] = test.groups.map(group => ({ $not: { groups: group } }))
$and.push({ flag: { [test.reversed ? '$bitsAllSet' : '$bitsAllClear']: Dialogue.Flag.complement } })
const $and: FilterQuery<Dialogue>[] = test.groups.map((group) => ({ groups: { $ne: group } }))
$and.push({ flag: { [test.reversed ? '$bitsAllClear' : '$bitsAllSet']: Dialogue.Flag.complement } })
conditionals.push({
$or: [
{
flag: { [test.reversed ? '$bitsAllClear' : '$bitsAllSet']: Dialogue.Flag.complement },
flag: { [test.reversed ? '$bitsAllSet' : '$bitsAllClear']: Dialogue.Flag.complement },
groups: { $all: test.groups },
},
{ $and },
Expand Down Expand Up @@ -192,7 +198,7 @@ export default function apply(ctx: Context) {
if (test.matchTime !== undefined) {
conditionals.push({ $expr: { $gte: [expr, 0] } })
}
if (test.matchTime !== undefined) {
if (test.mismatchTime !== undefined) {
conditionals.push({ $expr: { $lt: [expr, 0] } })
}
})
Expand Down

0 comments on commit 6b3bc95

Please sign in to comment.