Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix mongo support for teach #93

Merged
merged 5 commits into from
Aug 29, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 => {
undefined-moe marked this conversation as resolved.
Show resolved Hide resolved
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