Skip to content

Commit

Permalink
feat(teach): migrate writer query to orm
Browse files Browse the repository at this point in the history
  • Loading branch information
shigma committed Aug 14, 2021
1 parent 6e10288 commit 6ecd10b
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 14 deletions.
4 changes: 0 additions & 4 deletions packages/plugin-teach/src/database/mongo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,4 @@ export default function apply(ctx: Context) {
conditionals.push({ $expr: { $lt: [expr, 0] } })
}
})

ctx.on('dialogue/mongo', (test, conditionals) => {
if (test.writer !== undefined) conditionals.push({ writer: test.writer })
})
}
4 changes: 0 additions & 4 deletions packages/plugin-teach/src/database/mysql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,4 @@ export default function apply(ctx: Context) {
conditionals.push(getProduct(test.matchTime) + '<0')
}
})

ctx.on('dialogue/mysql', (test, conditionals) => {
if (test.writer !== undefined) conditionals.push(`\`writer\` = ${test.writer}`)
})
}
4 changes: 4 additions & 0 deletions packages/plugin-teach/src/plugins/writer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,4 +161,8 @@ export default function apply(ctx: Context, config: Dialogue.Config) {
session.userId = userId
}
})

ctx.on('dialogue/test', (test, query) => {
if (test.writer !== undefined) query.writer = test.writer
})
}
7 changes: 1 addition & 6 deletions packages/plugin-teach/tests/environment.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Database, Context } from 'koishi-core'
import { defineProperty, Observed, clone, intersection } from 'koishi-utils'
import { defineProperty, Observed, clone } from 'koishi-utils'
import { Dialogue, DialogueTest, equal, apply } from 'koishi-plugin-teach'
import { App } from 'koishi-test-utils'

Expand Down Expand Up @@ -46,11 +46,6 @@ Database.extend('koishi-test-utils', {
export function memory(ctx: Context) {
ctx.database.memory.$store.dialogue = []

// writer
ctx.on('dialogue/memory', (data, { writer }) => {
if (writer !== undefined && data.writer !== writer) return true
})

// time
ctx.on('dialogue/memory', (data, { matchTime, mismatchTime }) => {
if (matchTime !== undefined && getProduct(data, matchTime) < 0) return true
Expand Down

0 comments on commit 6ecd10b

Please sign in to comment.