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 15, 2020
2 parents ff65e7e + 88beade commit 4af70d1
Show file tree
Hide file tree
Showing 19 changed files with 93 additions and 64 deletions.
7 changes: 5 additions & 2 deletions build/bump.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ function each <T> (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<Package>()
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
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.5",
"version": "1.1.6",
"main": "dist/index.js",
"files": [
"dist"
Expand Down Expand Up @@ -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",
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.5",
"version": "1.1.6",
"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.11.0"
"koishi-core": "^1.11.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.5",
"version": "1.1.6",
"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.11.0"
"koishi-core": "^1.11.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.11",
"version": "1.0.0-alpha.12",
"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.4"
"koishi-test-utils": "^3.2.1"
},
"peerDependencies": {
"koishi-core": "^1.11.0"
"koishi-core": "^1.11.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.11.0",
"version": "1.11.1",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
"files": [
Expand Down Expand Up @@ -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"
}
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.11.0",
"version": "1.11.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.5",
"koishi-test-utils": "^3.1.4"
"koishi-database-memory": "^1.1.6",
"koishi-test-utils": "^3.2.1"
},
"dependencies": {
"axios": "^0.19.2",
Expand Down
58 changes: 40 additions & 18 deletions packages/koishi-core/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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),
})
}
Expand All @@ -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
Expand All @@ -349,7 +350,7 @@ export class App extends Context {

if (!meta.$argv) {
Object.defineProperty(meta, '$argv', {
configurable: true,
writable: true,
value: { meta },
})
}
Expand All @@ -358,10 +359,7 @@ export class App extends Context {
if (this.database) {
if (meta.messageType === 'group') {
// attach group data
const groupFields = new Set<GroupField>(['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)
Expand All @@ -377,13 +375,7 @@ export class App extends Context {
}

// attach user data
const userFields = new Set<UserField>(['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)
Expand Down Expand Up @@ -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<GroupField> = []) {
const groupFields = new Set<GroupField>(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<UserField> = []) {
const userFields = new Set<UserField>(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'>) => {
Expand Down
2 changes: 1 addition & 1 deletion packages/koishi-core/src/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ class DatabaseManager {

injectMethods <S extends SubdatabaseType, T extends TableType> (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
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.6",
"version": "2.1.7",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
"author": "Shigma <[email protected]>",
Expand All @@ -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"
}
}
2 changes: 1 addition & 1 deletion packages/plugin-common/src/contextify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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') {
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-common/tests/contextify.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', '权限不足。')
Expand Down
4 changes: 4 additions & 0 deletions packages/plugin-common/tests/welcome.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down
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.6",
"version": "1.0.7",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
"author": "Shigma <[email protected]>",
Expand Down Expand Up @@ -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"
}
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.9",
"version": "1.0.0-alpha.10",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
"author": "Shigma <[email protected]>",
Expand Down Expand Up @@ -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"
}
}
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.11",
"version": "1.0.12",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
"author": "Shigma <[email protected]>",
Expand Down Expand Up @@ -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"
}
Expand Down
Loading

0 comments on commit 4af70d1

Please sign in to comment.