Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
shigma committed Nov 17, 2020
2 parents 5602fa2 + 254b20a commit 6bfcf40
Show file tree
Hide file tree
Showing 43 changed files with 995 additions and 131 deletions.
3 changes: 3 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
atri
dist

/packages/*/*.js
/packages/*/*.d.ts
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
dist
temp

/packages/*/*.js
/packages/*/*.d.ts

/addons
/atri
/coverage
Expand Down
18 changes: 9 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@
"version": "1.0.0",
"license": "MIT",
"devDependencies": {
"@octokit/rest": "^18.0.7",
"@octokit/rest": "^18.0.9",
"@sinonjs/fake-timers": "^6.0.1",
"@types/chai": "^4.2.14",
"@types/chai-as-promised": "^7.1.3",
"@types/cross-spawn": "^6.0.2",
"@types/fs-extra": "^9.0.2",
"@types/mocha": "^8.0.3",
"@types/node": "^14.14.6",
"@types/fs-extra": "^9.0.4",
"@types/mocha": "^8.0.4",
"@types/node": "^14.14.7",
"@types/semver": "^7.3.4",
"@types/sinonjs__fake-timers": "^6.0.2",
"@typescript-eslint/eslint-plugin": "^3.10.1",
Expand All @@ -54,21 +54,21 @@
"cross-env": "^7.0.2",
"cross-spawn": "^7.0.3",
"del": "^6.0.0",
"eslint": "^7.12.1",
"eslint": "^7.13.0",
"eslint-config-standard": "^16.0.1",
"eslint-import-resolver-typescript": "^2.3.0",
"eslint-plugin-import": "^2.22.1",
"eslint-plugin-mocha": "^8.0.0",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-promise": "^4.2.1",
"eslint-plugin-standard": "^4.0.2",
"eslint-plugin-standard": "^4.1.0",
"fs-extra": "^9.0.1",
"globby": "^11.0.1",
"jest-mock": "^26.6.1",
"jest-mock": "^26.6.2",
"kleur": "^4.1.3",
"latest-version": "^5.1.0",
"mocha": "^8.2.0",
"nock": "^13.0.4",
"mocha": "^8.2.1",
"nock": "^13.0.5",
"open": "^7.3.0",
"ora": "^5.1.0",
"p-map": "^4.0.0",
Expand Down
8 changes: 4 additions & 4 deletions packages/adapter-cqhttp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,18 @@
"koishi"
],
"peerDependencies": {
"koishi-core": "^2.4.1"
"koishi-core": "^2.4.2"
},
"devDependencies": {
"@types/ms": "^0.7.31",
"@types/ws": "^7.2.9",
"@types/ws": "^7.4.0",
"get-port": "^5.1.1",
"koishi-test-utils": "^5.0.2"
"koishi-test-utils": "^5.0.3"
},
"dependencies": {
"axios": "^0.21.0",
"ms": "^2.1.2",
"ws": "^7.3.1",
"ws": "^7.4.0",
"koishi-utils": "^3.1.5"
}
}
4 changes: 2 additions & 2 deletions packages/adapter-tomon/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@
"koishi"
],
"peerDependencies": {
"koishi-core": "^2.4.1"
"koishi-core": "^2.4.2"
},
"devDependencies": {
"koishi-test-utils": "^5.0.2"
"koishi-test-utils": "^5.0.3"
},
"dependencies": {
"koishi-utils": "^3.1.5",
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": "2.4.1",
"version": "2.4.2",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
"engines": {
Expand Down Expand Up @@ -36,15 +36,15 @@
"devDependencies": {
"@types/koa": "^2.11.6",
"@types/lru-cache": "^5.1.0",
"koishi-test-utils": "^5.0.2"
"koishi-test-utils": "^5.0.3"
},
"dependencies": {
"@types/koa-bodyparser": "^4.3.0",
"@types/koa-router": "^7.4.1",
"fastest-levenshtein": "^1.0.12",
"koa": "^2.13.0",
"koa-bodyparser": "^4.3.0",
"koa-router": "^9.4.0",
"koa-router": "^10.0.0",
"koishi-utils": "^3.1.5",
"lru-cache": "^6.0.0"
}
Expand Down
5 changes: 3 additions & 2 deletions packages/koishi-test-utils/package.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
{
"name": "koishi-test-utils",
"description": "Test utilities for Koishi",
"version": "5.0.2",
"version": "5.0.3",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
"engines": {
"node": ">=12.0.0"
},
"files": [
"dist",
"chai/dist",
"chai/index.d.ts",
"chai/package.json"
],
Expand Down Expand Up @@ -40,7 +41,7 @@
"dependencies": {
"chai": "^4.2.0",
"chai-as-promised": "^7.1.1",
"koishi-core": "^2.4.1",
"koishi-core": "^2.4.2",
"koishi-utils": "^3.1.5"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/koishi-utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
],
"devDependencies": {
"@types/supports-color": "^7.2.0",
"koishi-test-utils": "^5.0.2"
"koishi-test-utils": "^5.0.3"
},
"dependencies": {
"supports-color": "^7.2.0"
Expand Down
9 changes: 9 additions & 0 deletions packages/koishi-utils/src/string.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,15 @@ export function capitalize(source: string) {
return source.charAt(0).toUpperCase() + source.slice(1)
}

// eslint-disable-next-line no-new-func
export const interpolate = new Function('template', 'context', `
with (context) {
return template.replace(/\\{\\{[\\s\\S]+?\\}\\}/g, (sub) => {
const expr = sub.substring(2, sub.length - 2)
return eval(expr)
})
}`)

export function escapeRegExp(source: string) {
return source
.replace(/[|\\{}()[\]^$+*?.]/g, '\\$&')
Expand Down
6 changes: 5 additions & 1 deletion packages/koishi-utils/tests/string.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { capitalize, camelCase, paramCase, snakeCase, simplify, traditionalize, escapeRegExp } from 'koishi-utils'
import { capitalize, camelCase, paramCase, snakeCase, simplify, traditionalize, interpolate, escapeRegExp } from 'koishi-utils'
import { expect } from 'chai'

describe('String Manipulations', () => {
Expand Down Expand Up @@ -29,6 +29,10 @@ describe('String Manipulations', () => {
expect(snakeCase({ 'a-b': [{ cD: 'e-f' }] })).to.deep.equal({ a_b: [{ c_d: 'e-f' }] })
})

it('interpolate', () => {
expect(interpolate('foo{{ bar }}foo', { bar: 'baz' })).to.equal('foobazfoo')
})

it('escape regexp', () => {
expect(escapeRegExp('\\^$*+?.()|{}[]-')).to.equal('\\\\\\^\\$\\*\\+\\?\\.\\(\\)\\|\\{\\}\\[\\]\\x2d')
})
Expand Down
12 changes: 6 additions & 6 deletions packages/koishi/ecosystem.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"description": "Tomon adapter for Koishi"
},
"koishi-plugin-chess": {
"version": "2.0.0-beta.13",
"version": "2.0.0",
"description": "Chess Plugin for Koishi"
},
"koishi-plugin-common": {
Expand All @@ -28,11 +28,11 @@
"description": "Execute JavaScript in Koishi"
},
"koishi-plugin-github": {
"version": "2.2.1",
"version": "2.2.2",
"description": "GitHub webhook plugin for Koishi"
},
"koishi-plugin-image-search": {
"version": "2.0.1",
"version": "2.0.2",
"description": "Image searching plugin for Koishi"
},
"koishi-plugin-mongo": {
Expand All @@ -43,7 +43,7 @@
"version": "1.0.0-beta.16"
},
"koishi-plugin-mysql": {
"version": "2.0.2",
"version": "2.1.0",
"description": "MySQL support for Koishi"
},
"koishi-plugin-puppeteer": {
Expand All @@ -59,11 +59,11 @@
"description": "Schedule plugin for Koishi"
},
"koishi-plugin-status": {
"version": "2.0.0-beta.17",
"version": "2.0.0",
"description": "Show Status of Koishi"
},
"koishi-plugin-teach": {
"version": "1.2.1",
"version": "1.2.2",
"description": "Teach plugin for Koishi"
},
"koishi-plugin-tools": {
Expand Down
4 changes: 2 additions & 2 deletions packages/koishi/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": "2.4.1",
"version": "2.4.2",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
"engines": {
Expand Down Expand Up @@ -40,7 +40,7 @@
"dependencies": {
"cac": "^6.6.1",
"kleur": "^4.1.3",
"koishi-core": "^2.4.1",
"koishi-core": "^2.4.2",
"koishi-plugin-common": "^3.0.3",
"prompts": "^2.4.0"
}
Expand Down
12 changes: 6 additions & 6 deletions packages/koishi/src/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,12 @@ process.on('message', (data: Message) => {
}
})

// load adapter
try {
const [name] = config.type.split('.', 1)
loadEcosystem('adapter', name)
} catch {}

const app = new App(config)

app.command('exit', '停止机器人运行', { authority: 4 })
Expand All @@ -123,12 +129,6 @@ app.command('exit', '停止机器人运行', { authority: 4 })
process.exit(514)
})

// load adapter
try {
const [name] = config.type.split('.', 1)
loadEcosystem('adapter', name)
} catch {}

// load plugins
if (Array.isArray(config.plugins)) {
for (const item of config.plugins) {
Expand Down
4 changes: 2 additions & 2 deletions packages/plugin-chess/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "koishi-plugin-chess",
"description": "Chess Plugin for Koishi",
"version": "2.0.0-beta.13",
"version": "2.0.0",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
"files": [
Expand Down Expand Up @@ -33,7 +33,7 @@
"game"
],
"peerDependencies": {
"koishi-core": "^2.4.1",
"koishi-core": "^2.4.2",
"koishi-plugin-puppeteer": "^1.0.1",
"koishi-utils": "^3.1.5"
}
Expand Down
10 changes: 3 additions & 7 deletions packages/plugin-chess/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,11 +157,7 @@ export function apply(ctx: Context) {
return '请输入由字母+数字构成的坐标。'
}

if (!state.p2) {
if (session.userId === state.p1) return '当前不是你的回合。'
} else {
if (session.userId !== state.next) return '当前不是你的回合。'
}
if (state.p2 && session.userId !== state.next) return '当前不是你的回合。'

const [x, y] = isLetterFirst ? [
position.charCodeAt(0) % 32 - 1,
Expand All @@ -178,14 +174,14 @@ export function apply(ctx: Context) {
if (state.get(x, y)) return '此处已有落子。'

let message = ''
if (!state.p2) {
if (!state.p2 && session.userId !== state.p1) {
state.p2 = session.userId
message = `${session.$username} 加入了游戏并落子于 ${position.toUpperCase()},`
} else {
message = `${session.$username} 落子于 ${position.toUpperCase()},`
}

const value = session.userId === state.p1 ? -1 : 1
const value = state.history.length % 2 ? -1 : 1
const result = state.update(x, y, value)

switch (result) {
Expand Down
4 changes: 2 additions & 2 deletions packages/plugin-common/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@
"plugin"
],
"peerDependencies": {
"koishi-core": "^2.4.1",
"koishi-core": "^2.4.2",
"koishi-utils": "^3.1.5"
},
"devDependencies": {
"koishi-test-utils": "^5.0.2"
"koishi-test-utils": "^5.0.3"
}
}
4 changes: 2 additions & 2 deletions packages/plugin-dice/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@
"dice"
],
"peerDependencies": {
"koishi-core": "^2.4.1",
"koishi-core": "^2.4.2",
"koishi-utils": "^3.1.5"
},
"devDependencies": {
"koishi-test-utils": "^5.0.2"
"koishi-test-utils": "^5.0.3"
}
}
4 changes: 2 additions & 2 deletions packages/plugin-eval-addons/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@
"code"
],
"peerDependencies": {
"koishi-core": "^2.4.1",
"koishi-core": "^2.4.2",
"koishi-plugin-eval": "^2.0.3",
"koishi-utils": "^3.1.5"
},
"dependencies": {
"js-yaml": "^3.14.0",
"json5": "^2.1.3",
"simple-git": "^2.21.0",
"simple-git": "^2.22.0",
"typescript": "^4.0.5"
},
"devDependencies": {
Expand Down
4 changes: 2 additions & 2 deletions packages/plugin-eval/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@
"code"
],
"peerDependencies": {
"koishi-core": "^2.4.1",
"koishi-core": "^2.4.2",
"koishi-utils": "^3.1.5"
},
"devDependencies": {
"koishi-test-utils": "^5.0.2"
"koishi-test-utils": "^5.0.3"
}
}
Loading

0 comments on commit 6bfcf40

Please sign in to comment.