Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
shigma committed Mar 4, 2020
2 parents acec596 + 92aca4b commit 5664647
Show file tree
Hide file tree
Showing 16 changed files with 76 additions and 70 deletions.
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,17 @@
"@types/cross-spawn": "^6.0.1",
"@types/fs-extra": "^8.1.0",
"@types/jest": "^25.1.3",
"@types/node": "^13.7.6",
"@types/node": "^13.7.7",
"@types/semver": "^7.1.0",
"@typescript-eslint/eslint-plugin": "^2.21.0",
"@typescript-eslint/parser": "^2.21.0",
"@typescript-eslint/eslint-plugin": "^2.22.0",
"@typescript-eslint/parser": "^2.22.0",
"cac": "^6.5.6",
"cross-spawn": "^7.0.1",
"del": "^5.1.0",
"eslint": "^6.8.0",
"eslint-config-standard": "^14.1.0",
"eslint-plugin-import": "^2.20.1",
"eslint-plugin-jest": "^23.8.0",
"eslint-plugin-jest": "^23.8.1",
"eslint-plugin-node": "^11.0.0",
"eslint-plugin-promise": "^4.2.1",
"eslint-plugin-standard": "^4.0.1",
Expand All @@ -54,6 +54,6 @@
"semver": "^7.1.3",
"ts-jest": "^25.2.1",
"ts-node": "^8.6.2",
"typescript": "^3.8.2"
"typescript": "^3.8.3"
}
}
6 changes: 3 additions & 3 deletions packages/database-level/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "koishi-database-level",
"description": "Leveldb support for Koishi",
"version": "1.1.3",
"version": "1.1.4",
"main": "dist/index.js",
"files": [
"dist"
Expand Down Expand Up @@ -33,10 +33,10 @@
"leveldb"
],
"devDependencies": {
"koishi-test-utils": "^3.1.2"
"koishi-test-utils": "^3.1.3"
},
"peerDependencies": {
"koishi-core": "^1.10.0"
"koishi-core": "^1.10.1"
},
"dependencies": {
"@types/leveldown": "^4.0.2",
Expand Down
4 changes: 2 additions & 2 deletions packages/database-memory/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "koishi-database-memory",
"description": "An in-memory database implementation for Koishi",
"version": "1.1.3",
"version": "1.1.4",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
"files": [
Expand All @@ -22,7 +22,7 @@
},
"homepage": "https://github.com/koishijs/koishi/tree/master/packages/database-memory#readme",
"peerDependencies": {
"koishi-core": "^1.10.0"
"koishi-core": "^1.10.1"
},
"dependencies": {
"koishi-utils": "^1.0.4"
Expand Down
4 changes: 2 additions & 2 deletions packages/database-mysql/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "koishi-database-mysql",
"description": "MySQL support for Koishi",
"version": "1.1.3",
"version": "1.1.4",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
"files": [
Expand Down Expand Up @@ -35,7 +35,7 @@
"@types/mysql": "^2.15.9"
},
"peerDependencies": {
"koishi-core": "^1.10.0"
"koishi-core": "^1.10.1"
},
"dependencies": {
"koishi-utils": "^1.0.4",
Expand Down
6 changes: 3 additions & 3 deletions packages/database-sqlite/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "koishi-database-sqlite",
"version": "1.0.0-alpha.9",
"version": "1.0.0-alpha.10",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
"files": [
Expand All @@ -22,10 +22,10 @@
"homepage": "https://github.com/koishijs/koishi/tree/master/packages/database-sqlite#readme",
"devDependencies": {
"@types/sqlite3": "^3.1.6",
"koishi-test-utils": "^3.1.2"
"koishi-test-utils": "^3.1.3"
},
"peerDependencies": {
"koishi-core": "^1.10.0"
"koishi-core": "^1.10.1"
},
"dependencies": {
"koishi-utils": "^1.0.4",
Expand Down
8 changes: 4 additions & 4 deletions packages/koishi-cli/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "koishi",
"description": "A QQ bot framework based on CQHTTP",
"version": "1.10.0",
"version": "1.10.1",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
"files": [
Expand Down Expand Up @@ -38,9 +38,9 @@
"cac": "^6.5.6",
"js-yaml": "^3.13.1",
"kleur": "^3.0.3",
"koishi-core": "^1.10.0",
"koishi-plugin-common": "^2.1.4",
"koishi-plugin-schedule": "^1.0.9",
"koishi-core": "^1.10.1",
"koishi-plugin-common": "^2.1.5",
"koishi-plugin-schedule": "^1.0.10",
"koishi-utils": "^1.0.4",
"prompts": "^2.3.1"
}
Expand Down
6 changes: 3 additions & 3 deletions packages/koishi-core/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "koishi-core",
"description": "Core features for Koishi",
"version": "1.10.0",
"version": "1.10.1",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
"files": [
Expand Down Expand Up @@ -35,8 +35,8 @@
"@types/debug": "^4.1.5",
"@types/ws": "^7.2.2",
"get-port": "^5.1.1",
"koishi-database-memory": "^1.1.3",
"koishi-test-utils": "^3.1.2"
"koishi-database-memory": "^1.1.4",
"koishi-test-utils": "^3.1.3"
},
"dependencies": {
"axios": "^0.19.2",
Expand Down
25 changes: 14 additions & 11 deletions packages/koishi-core/src/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -245,29 +245,32 @@ export class Command {
}

async execute (argv: ParsedCommandLine, next: NextFunction = noop) {
const { meta, options = {}, args = [], unknown = [] } = argv
this.app.emitEvent(meta, 'before-command', argv)
const options = argv.options || (argv.options = {})
const unknown = argv.unknown || (argv.unknown = [])
const args = argv.args || (argv.args = [])

this.app.emitEvent(argv.meta, 'before-command', argv)

// show help when use `-h, --help` or when there is no action
if (!this._action || options.help && !this.config.noHelpOption) {
return this.context.runCommand('help', meta, [this.name])
return this.context.runCommand('help', argv.meta, [this.name])
}

// check argument count
if (this.config.checkArgCount) {
const nextArg = this._argsDef[args.length]
if (nextArg?.required) {
return this._sendHint(CommandHint.INSUFFICIENT_ARGUMENTS, meta)
return this._sendHint(CommandHint.INSUFFICIENT_ARGUMENTS, argv.meta)
}
const finalArg = this._argsDef[this._argsDef.length - 1]
if (args.length > this._argsDef.length && !finalArg.noSegment && !finalArg.variadic) {
return this._sendHint(CommandHint.REDUNANT_ARGUMENTS, meta)
return this._sendHint(CommandHint.REDUNANT_ARGUMENTS, argv.meta)
}
}

// check unknown options
if (this.config.checkUnknown && unknown.length) {
return this._sendHint(CommandHint.UNKNOWN_OPTIONS, meta, unknown.join(', '))
return this._sendHint(CommandHint.UNKNOWN_OPTIONS, argv.meta, unknown.join(', '))
}

// check required options
Expand All @@ -276,17 +279,17 @@ export class Command {
return option.required && !(option.longest in options)
})
if (absent) {
return this._sendHint(CommandHint.REQUIRED_OPTIONS, meta, absent.rawName)
return this._sendHint(CommandHint.REQUIRED_OPTIONS, argv.meta, absent.rawName)
}
}

// check authority and usage
const code = this._checkUser(meta, options)
if (code) return this._sendHint(code, meta)
const code = this._checkUser(argv.meta, options)
if (code) return this._sendHint(code, argv.meta)

// execute command
this.context.logger('koishi:command').debug('execute %s', this.name)
this.app.emitEvent(meta, 'command', argv)
this.app.emitEvent(argv.meta, 'command', argv)

let skipped = false
argv.next = (_next) => {
Expand All @@ -296,7 +299,7 @@ export class Command {

try {
await this._action(argv, ...args)
if (!skipped) this.app.emitEvent(meta, 'after-command', argv)
if (!skipped) this.app.emitEvent(argv.meta, 'after-command', argv)
} catch (error) {
this.app.receiver.emit('error/command', error)
this.app.receiver.emit('error', error)
Expand Down
14 changes: 5 additions & 9 deletions packages/koishi-core/src/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ interface Subdatabase <T extends SubdatabaseType = SubdatabaseType, A extends Ab
identify? (config: DatabaseConfig[T]): string | number
_methods?: InjectionMap<T>
_options?: InjectConfig<T>
_manager?: DatabaseManager
_managers?: DatabaseManager[]
}

export interface AbstractDatabase {
Expand All @@ -161,6 +161,7 @@ export function registerDatabase <K extends SubdatabaseType> (name: K, subdataba
subdatabases[name] = subdatabase as any
subdatabase._methods = unknownMethods[name] ?? {}
subdatabase._options = unknownOptions[name] ?? {}
subdatabase._managers = []
}

export type DatabaseInjections <K extends SubdatabaseType, T extends TableType = TableType> = {
Expand All @@ -185,13 +186,8 @@ export function injectMethods <K extends SubdatabaseType, T extends TableType> (
optionMap = unknownOptions[name] || (unknownOptions[name] = {} as never)
} else {
optionMap = Subdatabase._options
if (Subdatabase._manager) {
// inject after application was created
Subdatabase._manager.injectMethods(name, table, methods)
methodMap = {} as any
} else {
methodMap = Subdatabase._methods
}
methodMap = Subdatabase._methods
Subdatabase._managers.forEach(manager => manager.injectMethods(name, table, methods))
}

methodMap[table] = { ...methodMap[table], ...methods }
Expand Down Expand Up @@ -228,7 +224,7 @@ class DatabaseManager {
const Subdatabase: Subdatabase<S> = subdatabases[type]
const subdatabase = this.createSubdatabase(type, config)
this.database[type] = subdatabase as never
Subdatabase._manager = this
Subdatabase._managers.push(this)
for (const table in Subdatabase._methods) {
this.injectMethods(type, table as any, Subdatabase._methods[table])
}
Expand Down
8 changes: 4 additions & 4 deletions packages/plugin-common/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "koishi-plugin-common",
"description": "Common plugins for Koishi",
"version": "2.1.4",
"version": "2.1.5",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
"author": "Shigma <1700011071@pku.edu.cn>",
Expand All @@ -28,11 +28,11 @@
"plugin"
],
"devDependencies": {
"koishi-database-memory": "^1.1.3",
"koishi-test-utils": "^3.1.2"
"koishi-database-memory": "^1.1.4",
"koishi-test-utils": "^3.1.3"
},
"dependencies": {
"koishi-core": "^1.10.0",
"koishi-core": "^1.10.1",
"koishi-utils": "^1.0.4"
}
}
19 changes: 13 additions & 6 deletions packages/plugin-common/src/contextify.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Context, getTargetId } from 'koishi-core'
import { Context, getTargetId, ContextType } from 'koishi-core'

export default function apply (ctx: Context) {
ctx.command('contextify <message...>', '在特定上下文中触发指令', { authority: 3 })
Expand Down Expand Up @@ -52,23 +52,30 @@ export default function apply (ctx: Context) {
delete newMeta.groupId
delete newMeta.discussId

let ctxType: ContextType, ctxId: number
if (options.discuss) {
newMeta.discussId = +options.discuss
newMeta.discussId = ctxId = +options.discuss
newMeta.messageType = 'discuss'
newMeta.messageType = ctxType = 'discuss'
} else if (options.group) {
const id = +options.group
newMeta.groupId = id
newMeta.messageType = 'group'
newMeta.groupId = ctxId = +options.group
newMeta.messageType = ctxType = 'group'
newMeta.subType = options.type || 'normal'
Object.defineProperty(newMeta, '$group', {
value: await ctx.database.observeGroup(id),
value: await ctx.database.observeGroup(ctxId),
writable: true,
})
} else {
ctxId = newMeta.userId
ctxType = 'user'
newMeta.messageType = 'private'
newMeta.subType = options.type || 'other'
}

// generate path
Object.defineProperty(newMeta, '$ctxId', { value: ctxId })
Object.defineProperty(newMeta, '$ctxType', { value: ctxType })

return ctx.app.executeCommandLine(message, newMeta)
})
}
6 changes: 3 additions & 3 deletions packages/plugin-nlp/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "koishi-plugin-nlp",
"description": "Natural Language Processor for Koishi",
"version": "1.0.4",
"version": "1.0.5",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
"author": "Shigma <1700011071@pku.edu.cn>",
Expand Down Expand Up @@ -30,10 +30,10 @@
"jieba"
],
"devDependencies": {
"koishi-test-utils": "^3.1.2"
"koishi-test-utils": "^3.1.3"
},
"dependencies": {
"koishi-core": "^1.10.0",
"koishi-core": "^1.10.1",
"koishi-utils": "^1.0.4",
"nodejieba": "^2.4.0"
}
Expand Down
6 changes: 3 additions & 3 deletions packages/plugin-recorder/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "koishi-plugin-recorder",
"description": "Save Chat Records for Koishi",
"version": "1.0.0-alpha.7",
"version": "1.0.0-alpha.8",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
"author": "Shigma <1700011071@pku.edu.cn>",
Expand Down Expand Up @@ -31,10 +31,10 @@
],
"devDependencies": {
"del": "^5.1.0",
"koishi-test-utils": "^3.1.2"
"koishi-test-utils": "^3.1.3"
},
"dependencies": {
"koishi-core": "^1.10.0",
"koishi-core": "^1.10.1",
"koishi-utils": "^1.0.4"
}
}
10 changes: 5 additions & 5 deletions packages/plugin-schedule/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "koishi-plugin-schedule",
"description": "Schedule plugin for Koishi",
"version": "1.0.9",
"version": "1.0.10",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
"author": "Shigma <1700011071@pku.edu.cn>",
Expand Down Expand Up @@ -31,12 +31,12 @@
],
"devDependencies": {
"@types/ms": "^0.7.31",
"koishi-database-level": "^1.1.3",
"koishi-database-mysql": "^1.1.3",
"koishi-test-utils": "^3.1.2"
"koishi-database-level": "^1.1.4",
"koishi-database-mysql": "^1.1.4",
"koishi-test-utils": "^3.1.3"
},
"dependencies": {
"koishi-core": "^1.10.0",
"koishi-core": "^1.10.1",
"koishi-utils": "^1.0.4",
"ms": "^2.1.2"
}
Expand Down
Loading

0 comments on commit 5664647

Please sign in to comment.