Skip to content

Commit

Permalink
feat(core): $stripped -> $parsed
Browse files Browse the repository at this point in the history
  • Loading branch information
shigma committed Jan 22, 2020
1 parent c677df4 commit c3b0b50
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 7 deletions.
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -9,6 +9,7 @@
"scripts": {
"build": "tsc -b",
"build:extend": "tsc -b tsconfig.extend.json",
"build:dict": "ts-node bots/shiki/build/dict",
"bump": "ts-node build/bump",
"dep": "ts-node build/dep",
"docs": "cd docs & yarn dev",
Expand Down
2 changes: 1 addition & 1 deletion packages/koishi-core/src/app.ts
Expand Up @@ -297,7 +297,7 @@ export class App extends Context {
}

// store parsed message
meta.$stripped = { atMe, nickname, prefix, message }
meta.$parsed = { atMe, nickname, prefix, message }

// parse as command
if (prefix !== null || nickname || meta.messageType === 'private') {
Expand Down
4 changes: 2 additions & 2 deletions packages/koishi-core/src/meta.ts
Expand Up @@ -41,7 +41,7 @@ export interface ResponsePayload {
reason?: string
}

export interface StrippedMessage {
export interface ParsedMessage {
atMe?: boolean
nickname?: string
prefix?: string
Expand All @@ -59,7 +59,7 @@ export interface Meta <T extends PostType = PostType> {
$ctxType?: ContextType

// other properties
$stripped?: StrippedMessage
$parsed?: ParsedMessage

// quick operations
$response?: (payload: ResponsePayload) => void
Expand Down
9 changes: 5 additions & 4 deletions packages/plugin-nlp/src/index.ts
@@ -1,5 +1,5 @@
import { Command, Meta, Context, ParsedLine, ParsedCommandLine } from 'koishi-core'
import { tag } from 'nodejieba'
import { tag, load } from 'nodejieba'
import { resolve } from 'path'

declare module 'koishi-core/dist/command' {
Expand All @@ -10,8 +10,8 @@ declare module 'koishi-core/dist/command' {
}

declare module 'koishi-core/dist/meta' {
interface Meta {
$tags?: TagResult[]
interface ParsedMessage {
tags?: TagResult[]
}
}

Expand Down Expand Up @@ -65,6 +65,7 @@ export function apply (ctx: Context, options: NlpConfig = {}) {
options.idfDict = resolvePathConfig(options.idfDict)
options.userDict = resolvePathConfig(options.userDict)
options.stopWordDict = resolvePathConfig(options.stopWordDict)
load(options)

ctx.middleware((meta, next) => {
let max = options.threshold
Expand All @@ -76,7 +77,7 @@ export function apply (ctx: Context, options: NlpConfig = {}) {
if (!keyword) continue

// attach word tags
if (!meta.$tags) meta.$tags = tag(meta.message)
if (!meta.$parsed.tags) meta.$parsed.tags = tag(meta.message)

// generate intension
const intension = callback(meta, keyword)
Expand Down

0 comments on commit c3b0b50

Please sign in to comment.