diff --git a/build/bump.ts b/build/bump.ts index 1bd3f2c0df..30037ce134 100644 --- a/build/bump.ts +++ b/build/bump.ts @@ -100,7 +100,6 @@ function each (callback: (pkg: Package, name: string) => T) { } function bumpPkg (source: Package, flag: BumpType, only = false) { - if (!source) return const newVersion = source.bump(flag) if (!newVersion) return const dependents = new Set() @@ -135,7 +134,11 @@ const flag = options.major ? 'major' : options.minor ? 'minor' : options.patch ? })) spinner.succeed() - args.forEach(name => bumpPkg(getPackage(name), flag, options.only)) + args.forEach((name) => { + const pkg = getPackage(name) + if (!pkg) throw new Error(`${name} not found`) + bumpPkg(pkg, flag, options.only) + }) await Promise.all(each((pkg) => { if (!pkg.dirty) return diff --git a/package.json b/package.json index 61fca4f584..2026a9e44c 100644 --- a/package.json +++ b/package.json @@ -23,11 +23,11 @@ "version": "1.0.0", "license": "MIT", "devDependencies": { - "@octokit/rest": "^17.0.1", + "@octokit/rest": "^17.1.0", "@types/cross-spawn": "^6.0.1", "@types/fs-extra": "^8.1.0", "@types/jest": "^25.1.4", - "@types/node": "^13.9.0", + "@types/node": "^13.9.1", "@types/semver": "^7.1.0", "@typescript-eslint/eslint-plugin": "^2.23.0", "@typescript-eslint/parser": "^2.23.0", diff --git a/packages/database-level/package.json b/packages/database-level/package.json index fdf1a02a31..6969bcb148 100644 --- a/packages/database-level/package.json +++ b/packages/database-level/package.json @@ -1,7 +1,7 @@ { "name": "koishi-database-level", "description": "Leveldb support for Koishi", - "version": "1.1.5", + "version": "1.1.6", "main": "dist/index.js", "files": [ "dist" @@ -33,10 +33,10 @@ "leveldb" ], "devDependencies": { - "koishi-test-utils": "^3.1.4" + "koishi-test-utils": "^3.2.1" }, "peerDependencies": { - "koishi-core": "^1.11.0" + "koishi-core": "^1.11.1" }, "dependencies": { "@types/leveldown": "^4.0.2", diff --git a/packages/database-memory/package.json b/packages/database-memory/package.json index 73fc0424e2..e01e099146 100644 --- a/packages/database-memory/package.json +++ b/packages/database-memory/package.json @@ -1,7 +1,7 @@ { "name": "koishi-database-memory", "description": "An in-memory database implementation for Koishi", - "version": "1.1.5", + "version": "1.1.6", "main": "dist/index.js", "typings": "dist/index.d.ts", "files": [ @@ -22,7 +22,7 @@ }, "homepage": "https://github.com/koishijs/koishi/tree/master/packages/database-memory#readme", "peerDependencies": { - "koishi-core": "^1.11.0" + "koishi-core": "^1.11.1" }, "dependencies": { "koishi-utils": "^1.0.4" diff --git a/packages/database-mysql/package.json b/packages/database-mysql/package.json index 87bc779b9e..5fe40353d2 100644 --- a/packages/database-mysql/package.json +++ b/packages/database-mysql/package.json @@ -1,7 +1,7 @@ { "name": "koishi-database-mysql", "description": "MySQL support for Koishi", - "version": "1.1.5", + "version": "1.1.6", "main": "dist/index.js", "typings": "dist/index.d.ts", "files": [ @@ -35,7 +35,7 @@ "@types/mysql": "^2.15.9" }, "peerDependencies": { - "koishi-core": "^1.11.0" + "koishi-core": "^1.11.1" }, "dependencies": { "koishi-utils": "^1.0.4", diff --git a/packages/database-sqlite/package.json b/packages/database-sqlite/package.json index c10a0d4a5c..54fe50304d 100644 --- a/packages/database-sqlite/package.json +++ b/packages/database-sqlite/package.json @@ -1,6 +1,6 @@ { "name": "koishi-database-sqlite", - "version": "1.0.0-alpha.11", + "version": "1.0.0-alpha.12", "main": "dist/index.js", "typings": "dist/index.d.ts", "files": [ @@ -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.4" + "koishi-test-utils": "^3.2.1" }, "peerDependencies": { - "koishi-core": "^1.11.0" + "koishi-core": "^1.11.1" }, "dependencies": { "koishi-utils": "^1.0.4", diff --git a/packages/koishi-cli/package.json b/packages/koishi-cli/package.json index 3fb2c32fb5..f3caf0508e 100644 --- a/packages/koishi-cli/package.json +++ b/packages/koishi-cli/package.json @@ -1,7 +1,7 @@ { "name": "koishi", "description": "A QQ bot framework based on CQHTTP", - "version": "1.11.0", + "version": "1.11.1", "main": "dist/index.js", "typings": "dist/index.d.ts", "files": [ @@ -38,9 +38,9 @@ "cac": "^6.5.7", "js-yaml": "^3.13.1", "kleur": "^3.0.3", - "koishi-core": "^1.11.0", - "koishi-plugin-common": "^2.1.6", - "koishi-plugin-schedule": "^1.0.11", + "koishi-core": "^1.11.1", + "koishi-plugin-common": "^2.1.7", + "koishi-plugin-schedule": "^1.0.12", "koishi-utils": "^1.0.4", "prompts": "^2.3.1" } diff --git a/packages/koishi-core/package.json b/packages/koishi-core/package.json index 33510401ef..afc4b092d5 100644 --- a/packages/koishi-core/package.json +++ b/packages/koishi-core/package.json @@ -1,7 +1,7 @@ { "name": "koishi-core", "description": "Core features for Koishi", - "version": "1.11.0", + "version": "1.11.1", "main": "dist/index.js", "typings": "dist/index.d.ts", "files": [ @@ -35,8 +35,8 @@ "@types/debug": "^4.1.5", "@types/ws": "^7.2.2", "get-port": "^5.1.1", - "koishi-database-memory": "^1.1.5", - "koishi-test-utils": "^3.1.4" + "koishi-database-memory": "^1.1.6", + "koishi-test-utils": "^3.2.1" }, "dependencies": { "axios": "^0.19.2", diff --git a/packages/koishi-core/src/app.ts b/packages/koishi-core/src/app.ts index f5c43799dc..52facd7bc1 100644 --- a/packages/koishi-core/src/app.ts +++ b/packages/koishi-core/src/app.ts @@ -313,13 +313,14 @@ export class App extends Context { // store parsed message Object.defineProperty(meta, '$parsed', { + writable: true, value: { atMe, nickname, prefix, message }, }) // parse as command if (!meta.$argv && (prefix !== null || nickname || meta.messageType === 'private')) { Object.defineProperty(meta, '$argv', { - configurable: true, + writable: true, value: this.parseCommandLine(message, meta), }) } @@ -339,7 +340,7 @@ export class App extends Context { result.options = { ...options, ...result.options } result.args.unshift(...args) Object.defineProperty(meta, '$argv', { - configurable: true, + writable: true, value: { meta, command, ...result }, }) break @@ -349,7 +350,7 @@ export class App extends Context { if (!meta.$argv) { Object.defineProperty(meta, '$argv', { - configurable: true, + writable: true, value: { meta }, }) } @@ -358,10 +359,7 @@ export class App extends Context { if (this.database) { if (meta.messageType === 'group') { // attach group data - const groupFields = new Set(['flag', 'assignee']) - this.emitEvent(meta, 'before-group', groupFields, meta.$argv) - const group = await this.database.observeGroup(meta.groupId, Array.from(groupFields)) - Object.defineProperty(meta, '$group', { value: group, writable: true }) + const group = await this._attachGroup(meta, ['flag', 'assignee']) // emit attach event this.emitEvent(meta, 'attach-group', meta) @@ -377,13 +375,7 @@ export class App extends Context { } // attach user data - const userFields = new Set(['flag']) - this.emitEvent(meta, 'before-user', userFields, meta.$argv) - const defaultAuthority = typeof this.options.defaultAuthority === 'function' - ? this.options.defaultAuthority(meta) - : this.options.defaultAuthority || 0 - const user = await this.database.observeUser(meta.userId, defaultAuthority, Array.from(userFields)) - Object.defineProperty(meta, '$user', { value: user, writable: true }) + const user = await this._attachUser(meta, ['flag']) // emit attach event this.emitEvent(meta, 'attach', meta) @@ -438,13 +430,43 @@ export class App extends Context { } } - executeCommandLine (message: string, meta: Meta<'message'>, next: NextFunction = noop) { + private async _attachGroup (meta: Meta<'message'>, fields: Iterable = []) { + const groupFields = new Set(fields) + this.emitEvent(meta, 'before-group', groupFields, meta.$argv) + const group = await this.database.observeGroup(meta.groupId, Array.from(groupFields)) + Object.defineProperty(meta, '$group', { value: group, writable: true }) + return group + } + + private async _attachUser (meta: Meta<'message'>, fields: Iterable = []) { + const userFields = new Set(fields) + this.emitEvent(meta, 'before-user', userFields, meta.$argv) + const defaultAuthority = typeof this.options.defaultAuthority === 'function' + ? this.options.defaultAuthority(meta) + : this.options.defaultAuthority || 0 + const user = await this.database.observeUser(meta.userId, defaultAuthority, Array.from(userFields)) + Object.defineProperty(meta, '$user', { value: user, writable: true }) + return user + } + + async executeCommandLine (message: string, meta: Meta<'message'>, next: NextFunction = noop) { if (!('$ctxType' in meta)) this.server.parseMeta(meta) const argv = this.parseCommandLine(message, meta) - if (argv && !argv.command.getConfig('disable', meta)) { - return argv.command.execute(argv, next) + if (!argv) return next() + Object.defineProperty(meta, '$argv', { + writable: true, + value: argv, + }) + + if (this.database) { + if (meta.messageType === 'group') { + await this._attachGroup(meta) + } + await this._attachUser(meta) } - return next() + + if (argv.command.getConfig('disable', meta)) return next() + return argv.command.execute(argv, next) } private _applyMiddlewares = async (meta: Meta<'message'>) => { diff --git a/packages/koishi-core/src/database.ts b/packages/koishi-core/src/database.ts index e055a27092..d6a80b5874 100644 --- a/packages/koishi-core/src/database.ts +++ b/packages/koishi-core/src/database.ts @@ -232,7 +232,7 @@ class DatabaseManager { injectMethods (sub: S, table: T, methods: any) { const subdatabase = this.database[sub] as AbstractDatabase - if (!this.explicitTables[table] && this.implicitTables[table]) { + if (!this.explicitTables[table] && this.implicitTables[table] && this.implicitTables[table] !== sub) { throw new Error(`database "${this.implicitTables[table]}" and "${sub}" conflict on table "${table}"`) } else if (!this.explicitTables[table] || this.explicitTables[table] === sub) { this.implicitTables[table] = sub diff --git a/packages/plugin-common/package.json b/packages/plugin-common/package.json index 4dc8413bed..dd65969ce3 100644 --- a/packages/plugin-common/package.json +++ b/packages/plugin-common/package.json @@ -1,7 +1,7 @@ { "name": "koishi-plugin-common", "description": "Common plugins for Koishi", - "version": "2.1.6", + "version": "2.1.7", "main": "dist/index.js", "typings": "dist/index.d.ts", "author": "Shigma <1700011071@pku.edu.cn>", @@ -28,11 +28,11 @@ "plugin" ], "devDependencies": { - "koishi-database-memory": "^1.1.5", - "koishi-test-utils": "^3.1.4" + "koishi-database-memory": "^1.1.6", + "koishi-test-utils": "^3.2.1" }, "dependencies": { - "koishi-core": "^1.11.0", + "koishi-core": "^1.11.1", "koishi-utils": "^1.0.4" } } diff --git a/packages/plugin-common/src/contextify.ts b/packages/plugin-common/src/contextify.ts index 6bf8c7583b..c9e50f0b2f 100644 --- a/packages/plugin-common/src/contextify.ts +++ b/packages/plugin-common/src/contextify.ts @@ -14,7 +14,7 @@ export default function apply (ctx: Context) { '讨论组聊天没有子类型。', ].join('\n')) .action(async ({ meta, options }, message) => { - if (!message) return meta.$send('请输入要发送的文本。') + if (!message) return meta.$send('请输入要触发的指令。') if (options.member) { if (meta.messageType === 'private') { diff --git a/packages/plugin-common/tests/contextify.spec.ts b/packages/plugin-common/tests/contextify.spec.ts index cc04392b2a..a301204b5c 100644 --- a/packages/plugin-common/tests/contextify.spec.ts +++ b/packages/plugin-common/tests/contextify.spec.ts @@ -21,7 +21,7 @@ beforeAll(async () => { }) test('check input', async () => { - await session1.shouldHaveReply('ctxf -u 456', '请输入要发送的文本。') + await session1.shouldHaveReply('ctxf -u 456', '请输入要触发的指令。') await session2.shouldHaveReply('ctxf -m foo show-context', '未指定目标。') await session1.shouldHaveReply('ctxf show-context', '请提供新的上下文。') await session1.shouldHaveReply('ctxf -u 789 show-context', '权限不足。') diff --git a/packages/plugin-common/tests/welcome.spec.ts b/packages/plugin-common/tests/welcome.spec.ts index dc14717b86..7facfbdc88 100644 --- a/packages/plugin-common/tests/welcome.spec.ts +++ b/packages/plugin-common/tests/welcome.spec.ts @@ -19,6 +19,10 @@ test('basic support', async () => { app.receive(shared) await sleep(0) app.shouldHaveLastRequest('send_group_msg', { groupId: 123, message: `欢迎新大佬 [CQ:at,qq=456]!` }) + + app.receive({ ...shared, userId: app.selfId }) + await sleep(0) + app.shouldHaveNoRequests() }) test('check assignee', async () => { diff --git a/packages/plugin-nlp/package.json b/packages/plugin-nlp/package.json index 1ca26891ad..df82f0d7d6 100644 --- a/packages/plugin-nlp/package.json +++ b/packages/plugin-nlp/package.json @@ -1,7 +1,7 @@ { "name": "koishi-plugin-nlp", "description": "Natural Language Processor for Koishi", - "version": "1.0.6", + "version": "1.0.7", "main": "dist/index.js", "typings": "dist/index.d.ts", "author": "Shigma <1700011071@pku.edu.cn>", @@ -30,10 +30,10 @@ "jieba" ], "devDependencies": { - "koishi-test-utils": "^3.1.4" + "koishi-test-utils": "^3.2.1" }, "dependencies": { - "koishi-core": "^1.11.0", + "koishi-core": "^1.11.1", "koishi-utils": "^1.0.4", "nodejieba": "^2.4.1" } diff --git a/packages/plugin-recorder/package.json b/packages/plugin-recorder/package.json index 6a9f0ee605..61e37cc802 100644 --- a/packages/plugin-recorder/package.json +++ b/packages/plugin-recorder/package.json @@ -1,7 +1,7 @@ { "name": "koishi-plugin-recorder", "description": "Save Chat Records for Koishi", - "version": "1.0.0-alpha.9", + "version": "1.0.0-alpha.10", "main": "dist/index.js", "typings": "dist/index.d.ts", "author": "Shigma <1700011071@pku.edu.cn>", @@ -31,10 +31,10 @@ ], "devDependencies": { "del": "^5.1.0", - "koishi-test-utils": "^3.1.4" + "koishi-test-utils": "^3.2.1" }, "dependencies": { - "koishi-core": "^1.11.0", + "koishi-core": "^1.11.1", "koishi-utils": "^1.0.4" } } diff --git a/packages/plugin-schedule/package.json b/packages/plugin-schedule/package.json index c22d3860b4..65b6a2fd80 100644 --- a/packages/plugin-schedule/package.json +++ b/packages/plugin-schedule/package.json @@ -1,7 +1,7 @@ { "name": "koishi-plugin-schedule", "description": "Schedule plugin for Koishi", - "version": "1.0.11", + "version": "1.0.12", "main": "dist/index.js", "typings": "dist/index.d.ts", "author": "Shigma <1700011071@pku.edu.cn>", @@ -31,12 +31,12 @@ ], "devDependencies": { "@types/ms": "^0.7.31", - "koishi-database-level": "^1.1.5", - "koishi-database-mysql": "^1.1.5", - "koishi-test-utils": "^3.1.4" + "koishi-database-level": "^1.1.6", + "koishi-database-mysql": "^1.1.6", + "koishi-test-utils": "^3.2.1" }, "dependencies": { - "koishi-core": "^1.11.0", + "koishi-core": "^1.11.1", "koishi-utils": "^1.0.4", "ms": "^2.1.2" } diff --git a/packages/plugin-teach/package.json b/packages/plugin-teach/package.json index 319f001f06..4ed7492b9d 100644 --- a/packages/plugin-teach/package.json +++ b/packages/plugin-teach/package.json @@ -1,7 +1,7 @@ { "name": "koishi-plugin-teach", "description": "Teach plugin for Koishi", - "version": "0.1.20", + "version": "0.1.21", "main": "dist/index.js", "typings": "dist/index.d.ts", "author": "Shigma <1700011071@pku.edu.cn>", @@ -31,12 +31,12 @@ "conversation" ], "devDependencies": { - "koishi-database-level": "^1.1.5", - "koishi-database-mysql": "^1.1.5", - "koishi-test-utils": "^3.1.4" + "koishi-database-level": "^1.1.6", + "koishi-database-mysql": "^1.1.6", + "koishi-test-utils": "^3.2.1" }, "dependencies": { - "koishi-core": "^1.11.0", + "koishi-core": "^1.11.1", "koishi-utils": "^1.0.4" } } diff --git a/packages/test-utils/package.json b/packages/test-utils/package.json index 2c7714fc30..d9191c61aa 100644 --- a/packages/test-utils/package.json +++ b/packages/test-utils/package.json @@ -1,7 +1,7 @@ { "name": "koishi-test-utils", "description": "Test utilities for Koishi", - "version": "3.1.4", + "version": "3.2.1", "main": "dist/index.js", "typings": "dist/index.d.ts", "files": [ @@ -43,7 +43,7 @@ "axios": "^0.19.2", "debug": "^4.1.1", "get-port": "^5.1.1", - "koishi-core": "^1.11.0", + "koishi-core": "^1.11.1", "koishi-utils": "^1.0.4" } }