diff --git a/.eslintignore b/.eslintignore index a061388bee..6a33609668 100644 --- a/.eslintignore +++ b/.eslintignore @@ -1,2 +1,5 @@ atri dist + +/packages/*/*.js +/packages/*/*.d.ts diff --git a/.gitignore b/.gitignore index d61e28d396..fb10b10fc3 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,9 @@ dist temp +/packages/*/*.js +/packages/*/*.d.ts + /addons /atri /coverage diff --git a/package.json b/package.json index c05f24c129..a183109cae 100644 --- a/package.json +++ b/package.json @@ -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", @@ -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", diff --git a/packages/adapter-cqhttp/package.json b/packages/adapter-cqhttp/package.json index 9485e28063..4cea3c3112 100644 --- a/packages/adapter-cqhttp/package.json +++ b/packages/adapter-cqhttp/package.json @@ -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" } } diff --git a/packages/adapter-tomon/package.json b/packages/adapter-tomon/package.json index 0e0a2494e7..bfbbafc810 100644 --- a/packages/adapter-tomon/package.json +++ b/packages/adapter-tomon/package.json @@ -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", diff --git a/packages/koishi-core/package.json b/packages/koishi-core/package.json index 6f40e56757..6eddf31b6a 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": "2.4.1", + "version": "2.4.2", "main": "dist/index.js", "typings": "dist/index.d.ts", "engines": { @@ -36,7 +36,7 @@ "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", @@ -44,7 +44,7 @@ "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" } diff --git a/packages/koishi-test-utils/package.json b/packages/koishi-test-utils/package.json index 76a9c7704a..3047ade6a0 100644 --- a/packages/koishi-test-utils/package.json +++ b/packages/koishi-test-utils/package.json @@ -1,7 +1,7 @@ { "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": { @@ -9,6 +9,7 @@ }, "files": [ "dist", + "chai/dist", "chai/index.d.ts", "chai/package.json" ], @@ -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": { diff --git a/packages/koishi-utils/package.json b/packages/koishi-utils/package.json index fafa8b93c4..d256862591 100644 --- a/packages/koishi-utils/package.json +++ b/packages/koishi-utils/package.json @@ -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" diff --git a/packages/koishi-utils/src/string.ts b/packages/koishi-utils/src/string.ts index b6869ca759..3b8f4a74b2 100644 --- a/packages/koishi-utils/src/string.ts +++ b/packages/koishi-utils/src/string.ts @@ -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, '\\$&') diff --git a/packages/koishi-utils/tests/string.spec.ts b/packages/koishi-utils/tests/string.spec.ts index eb01c24b8d..4877e83d01 100644 --- a/packages/koishi-utils/tests/string.spec.ts +++ b/packages/koishi-utils/tests/string.spec.ts @@ -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', () => { @@ -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') }) diff --git a/packages/koishi/ecosystem.json b/packages/koishi/ecosystem.json index cb61ce7d6a..db05719eed 100644 --- a/packages/koishi/ecosystem.json +++ b/packages/koishi/ecosystem.json @@ -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": { @@ -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": { @@ -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": { @@ -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": { diff --git a/packages/koishi/package.json b/packages/koishi/package.json index 49aa8a38e0..79627b3aef 100644 --- a/packages/koishi/package.json +++ b/packages/koishi/package.json @@ -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": { @@ -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" } diff --git a/packages/koishi/src/worker.ts b/packages/koishi/src/worker.ts index 05699bfdd4..1469474425 100644 --- a/packages/koishi/src/worker.ts +++ b/packages/koishi/src/worker.ts @@ -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 }) @@ -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) { diff --git a/packages/plugin-chess/package.json b/packages/plugin-chess/package.json index 6716befc0a..5fdd6c4aa3 100644 --- a/packages/plugin-chess/package.json +++ b/packages/plugin-chess/package.json @@ -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": [ @@ -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" } diff --git a/packages/plugin-chess/src/index.ts b/packages/plugin-chess/src/index.ts index c9b6af7d01..28320051b4 100644 --- a/packages/plugin-chess/src/index.ts +++ b/packages/plugin-chess/src/index.ts @@ -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, @@ -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) { diff --git a/packages/plugin-common/package.json b/packages/plugin-common/package.json index 7afa583524..1cabfbd658 100644 --- a/packages/plugin-common/package.json +++ b/packages/plugin-common/package.json @@ -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" } } diff --git a/packages/plugin-dice/package.json b/packages/plugin-dice/package.json index 6734c057b8..bd7c513614 100644 --- a/packages/plugin-dice/package.json +++ b/packages/plugin-dice/package.json @@ -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" } } diff --git a/packages/plugin-eval-addons/package.json b/packages/plugin-eval-addons/package.json index 069439d01a..6a75b96ca9 100644 --- a/packages/plugin-eval-addons/package.json +++ b/packages/plugin-eval-addons/package.json @@ -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": { diff --git a/packages/plugin-eval/package.json b/packages/plugin-eval/package.json index 1b55a4640f..ce6562b70d 100644 --- a/packages/plugin-eval/package.json +++ b/packages/plugin-eval/package.json @@ -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" } } diff --git a/packages/plugin-github/package.json b/packages/plugin-github/package.json index be8cb3ab85..79b79826c1 100644 --- a/packages/plugin-github/package.json +++ b/packages/plugin-github/package.json @@ -1,7 +1,7 @@ { "name": "koishi-plugin-github", "description": "GitHub webhook plugin for Koishi", - "version": "2.2.1", + "version": "2.2.2", "main": "dist/index.js", "typings": "dist/index.d.ts", "files": [ @@ -33,10 +33,10 @@ "webhook" ], "devDependencies": { - "koishi-test-utils": "^5.0.2" + "koishi-test-utils": "^5.0.3" }, "peerDependencies": { - "koishi-core": "^2.4.1", + "koishi-core": "^2.4.2", "koishi-plugin-puppeteer": "^1.0.1", "koishi-utils": "^3.1.5" }, diff --git a/packages/plugin-github/src/events.ts b/packages/plugin-github/src/events.ts index f946ee1e17..76f66e6945 100644 --- a/packages/plugin-github/src/events.ts +++ b/packages/plugin-github/src/events.ts @@ -39,6 +39,13 @@ export interface EventConfig { unlocked?: boolean unpinned?: boolean } + milestone?: boolean | { + closed?: boolean + created?: boolean + deleted?: boolean + edited?: boolean + opened?: boolean + } pullRequest?: boolean | { assigned?: boolean closed?: boolean @@ -80,6 +87,9 @@ export const defaultEvents: EventConfig = { closed: true, opened: true, }, + milestone: { + created: true, + }, pullRequest: { closed: true, opened: true, @@ -216,6 +226,12 @@ export function addListeners(on: (event: T, handler: Eve }] }) + on('milestone.created', ({ repository, milestone, sender }) => { + const { full_name } = repository + const { title, description } = milestone + return [`${sender.login} created milestone ${title} for ${full_name}\n${description}`] + }) + on('pull_request_review.submitted', ({ repository, review, pull_request }) => { if (!review.body) return const { full_name } = repository diff --git a/packages/plugin-github/tests/fixtures/issues.milestoned.json b/packages/plugin-github/tests/fixtures/issues.milestoned.json new file mode 100644 index 0000000000..3ba8f03720 --- /dev/null +++ b/packages/plugin-github/tests/fixtures/issues.milestoned.json @@ -0,0 +1,286 @@ +{ + "action": "milestoned", + "issue": { + "url": "https://api.github.com/repos/koishijs/koishi/issues/121", + "repository_url": "https://api.github.com/repos/koishijs/koishi", + "labels_url": "https://api.github.com/repos/koishijs/koishi/issues/121/labels{/name}", + "comments_url": "https://api.github.com/repos/koishijs/koishi/issues/121/comments", + "events_url": "https://api.github.com/repos/koishijs/koishi/issues/121/events", + "html_url": "https://github.com/koishijs/koishi/issues/121", + "id": 730092466, + "node_id": "MDU6SXNzdWU3MzAwOTI0NjY=", + "number": 121, + "title": "feature: validator api based on template literal types", + "user": { + "login": "undefined-moe", + "id": 29992205, + "node_id": "MDQ6VXNlcjI5OTkyMjA1", + "avatar_url": "https://avatars3.githubusercontent.com/u/29992205?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/undefined-moe", + "html_url": "https://github.com/undefined-moe", + "followers_url": "https://api.github.com/users/undefined-moe/followers", + "following_url": "https://api.github.com/users/undefined-moe/following{/other_user}", + "gists_url": "https://api.github.com/users/undefined-moe/gists{/gist_id}", + "starred_url": "https://api.github.com/users/undefined-moe/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/undefined-moe/subscriptions", + "organizations_url": "https://api.github.com/users/undefined-moe/orgs", + "repos_url": "https://api.github.com/users/undefined-moe/repos", + "events_url": "https://api.github.com/users/undefined-moe/events{/privacy}", + "received_events_url": "https://api.github.com/users/undefined-moe/received_events", + "type": "User", + "site_admin": false + }, + "labels": [ + { + "id": 1729355915, + "node_id": "MDU6TGFiZWwxNzI5MzU1OTE1", + "url": "https://api.github.com/repos/koishijs/koishi/labels/core", + "name": "core", + "color": "801fc1", + "default": false, + "description": "Related to koishi-core / koishi-utils" + }, + { + "id": 1711721898, + "node_id": "MDU6TGFiZWwxNzExNzIxODk4", + "url": "https://api.github.com/repos/koishijs/koishi/labels/feature", + "name": "feature", + "color": "0052cc", + "default": false, + "description": "New feature or request" + }, + { + "id": 1781343121, + "node_id": "MDU6TGFiZWwxNzgxMzQzMTIx", + "url": "https://api.github.com/repos/koishijs/koishi/labels/next", + "name": "next", + "color": "04d2f2", + "default": false, + "description": "Features for the next major version" + } + ], + "state": "open", + "locked": false, + "assignee": null, + "assignees": [ + + ], + "milestone": { + "url": "https://api.github.com/repos/koishijs/koishi/milestones/3", + "html_url": "https://github.com/koishijs/koishi/milestone/3", + "labels_url": "https://api.github.com/repos/koishijs/koishi/milestones/3/labels", + "id": 6037479, + "node_id": "MDk6TWlsZXN0b25lNjAzNzQ3OQ==", + "number": 3, + "title": "3.0", + "description": "", + "creator": { + "login": "Shigma", + "id": 33423008, + "node_id": "MDQ6VXNlcjMzNDIzMDA4", + "avatar_url": "https://avatars3.githubusercontent.com/u/33423008?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/Shigma", + "html_url": "https://github.com/Shigma", + "followers_url": "https://api.github.com/users/Shigma/followers", + "following_url": "https://api.github.com/users/Shigma/following{/other_user}", + "gists_url": "https://api.github.com/users/Shigma/gists{/gist_id}", + "starred_url": "https://api.github.com/users/Shigma/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/Shigma/subscriptions", + "organizations_url": "https://api.github.com/users/Shigma/orgs", + "repos_url": "https://api.github.com/users/Shigma/repos", + "events_url": "https://api.github.com/users/Shigma/events{/privacy}", + "received_events_url": "https://api.github.com/users/Shigma/received_events", + "type": "User", + "site_admin": false + }, + "open_issues": 1, + "closed_issues": 0, + "state": "open", + "created_at": "2020-10-27T11:55:28Z", + "updated_at": "2020-10-27T12:02:20Z", + "due_on": null, + "closed_at": null + }, + "comments": 1, + "created_at": "2020-10-27T04:22:26Z", + "updated_at": "2020-10-27T12:02:20Z", + "closed_at": null, + "author_association": "MEMBER", + "active_lock_reason": null, + "body": "类似如下设计:\r\n\r\n```ts\r\nctx.validator.create('positiveInt', val => {\r\n if (Number.isSafeInteger(val) && val > 0) return +val\r\n // return undefined means validation fail\r\n})\r\n```\r\n\r\nts4.0支持了对字符串进行处理提取出类型字串,可实现\r\n\r\n```ts\r\nctx.command('foo ')\r\n .action(async ({ session }, bar, baz, extra) => {\r\n // typeof bar -> string\r\n // typeof baz -> number\r\n })\r\n```", + "performed_via_github_app": null + }, + "milestone": { + "url": "https://api.github.com/repos/koishijs/koishi/milestones/3", + "html_url": "https://github.com/koishijs/koishi/milestone/3", + "labels_url": "https://api.github.com/repos/koishijs/koishi/milestones/3/labels", + "id": 6037479, + "node_id": "MDk6TWlsZXN0b25lNjAzNzQ3OQ==", + "number": 3, + "title": "3.0", + "description": "", + "creator": { + "login": "Shigma", + "id": 33423008, + "node_id": "MDQ6VXNlcjMzNDIzMDA4", + "avatar_url": "https://avatars3.githubusercontent.com/u/33423008?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/Shigma", + "html_url": "https://github.com/Shigma", + "followers_url": "https://api.github.com/users/Shigma/followers", + "following_url": "https://api.github.com/users/Shigma/following{/other_user}", + "gists_url": "https://api.github.com/users/Shigma/gists{/gist_id}", + "starred_url": "https://api.github.com/users/Shigma/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/Shigma/subscriptions", + "organizations_url": "https://api.github.com/users/Shigma/orgs", + "repos_url": "https://api.github.com/users/Shigma/repos", + "events_url": "https://api.github.com/users/Shigma/events{/privacy}", + "received_events_url": "https://api.github.com/users/Shigma/received_events", + "type": "User", + "site_admin": false + }, + "open_issues": 1, + "closed_issues": 0, + "state": "open", + "created_at": "2020-10-27T11:55:28Z", + "updated_at": "2020-10-27T12:02:20Z", + "due_on": null, + "closed_at": null + }, + "repository": { + "id": 225572038, + "node_id": "MDEwOlJlcG9zaXRvcnkyMjU1NzIwMzg=", + "name": "koishi", + "full_name": "koishijs/koishi", + "private": false, + "owner": { + "login": "koishijs", + "id": 58179220, + "node_id": "MDEyOk9yZ2FuaXphdGlvbjU4MTc5MjIw", + "avatar_url": "https://avatars3.githubusercontent.com/u/58179220?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/koishijs", + "html_url": "https://github.com/koishijs", + "followers_url": "https://api.github.com/users/koishijs/followers", + "following_url": "https://api.github.com/users/koishijs/following{/other_user}", + "gists_url": "https://api.github.com/users/koishijs/gists{/gist_id}", + "starred_url": "https://api.github.com/users/koishijs/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/koishijs/subscriptions", + "organizations_url": "https://api.github.com/users/koishijs/orgs", + "repos_url": "https://api.github.com/users/koishijs/repos", + "events_url": "https://api.github.com/users/koishijs/events{/privacy}", + "received_events_url": "https://api.github.com/users/koishijs/received_events", + "type": "Organization", + "site_admin": false + }, + "html_url": "https://github.com/koishijs/koishi", + "description": "QQ bot out of the box", + "fork": false, + "url": "https://api.github.com/repos/koishijs/koishi", + "forks_url": "https://api.github.com/repos/koishijs/koishi/forks", + "keys_url": "https://api.github.com/repos/koishijs/koishi/keys{/key_id}", + "collaborators_url": "https://api.github.com/repos/koishijs/koishi/collaborators{/collaborator}", + "teams_url": "https://api.github.com/repos/koishijs/koishi/teams", + "hooks_url": "https://api.github.com/repos/koishijs/koishi/hooks", + "issue_events_url": "https://api.github.com/repos/koishijs/koishi/issues/events{/number}", + "events_url": "https://api.github.com/repos/koishijs/koishi/events", + "assignees_url": "https://api.github.com/repos/koishijs/koishi/assignees{/user}", + "branches_url": "https://api.github.com/repos/koishijs/koishi/branches{/branch}", + "tags_url": "https://api.github.com/repos/koishijs/koishi/tags", + "blobs_url": "https://api.github.com/repos/koishijs/koishi/git/blobs{/sha}", + "git_tags_url": "https://api.github.com/repos/koishijs/koishi/git/tags{/sha}", + "git_refs_url": "https://api.github.com/repos/koishijs/koishi/git/refs{/sha}", + "trees_url": "https://api.github.com/repos/koishijs/koishi/git/trees{/sha}", + "statuses_url": "https://api.github.com/repos/koishijs/koishi/statuses/{sha}", + "languages_url": "https://api.github.com/repos/koishijs/koishi/languages", + "stargazers_url": "https://api.github.com/repos/koishijs/koishi/stargazers", + "contributors_url": "https://api.github.com/repos/koishijs/koishi/contributors", + "subscribers_url": "https://api.github.com/repos/koishijs/koishi/subscribers", + "subscription_url": "https://api.github.com/repos/koishijs/koishi/subscription", + "commits_url": "https://api.github.com/repos/koishijs/koishi/commits{/sha}", + "git_commits_url": "https://api.github.com/repos/koishijs/koishi/git/commits{/sha}", + "comments_url": "https://api.github.com/repos/koishijs/koishi/comments{/number}", + "issue_comment_url": "https://api.github.com/repos/koishijs/koishi/issues/comments{/number}", + "contents_url": "https://api.github.com/repos/koishijs/koishi/contents/{+path}", + "compare_url": "https://api.github.com/repos/koishijs/koishi/compare/{base}...{head}", + "merges_url": "https://api.github.com/repos/koishijs/koishi/merges", + "archive_url": "https://api.github.com/repos/koishijs/koishi/{archive_format}{/ref}", + "downloads_url": "https://api.github.com/repos/koishijs/koishi/downloads", + "issues_url": "https://api.github.com/repos/koishijs/koishi/issues{/number}", + "pulls_url": "https://api.github.com/repos/koishijs/koishi/pulls{/number}", + "milestones_url": "https://api.github.com/repos/koishijs/koishi/milestones{/number}", + "notifications_url": "https://api.github.com/repos/koishijs/koishi/notifications{?since,all,participating}", + "labels_url": "https://api.github.com/repos/koishijs/koishi/labels{/name}", + "releases_url": "https://api.github.com/repos/koishijs/koishi/releases{/id}", + "deployments_url": "https://api.github.com/repos/koishijs/koishi/deployments", + "created_at": "2019-12-03T08:47:29Z", + "updated_at": "2020-10-26T18:34:05Z", + "pushed_at": "2020-10-27T11:03:36Z", + "git_url": "git://github.com/koishijs/koishi.git", + "ssh_url": "git@github.com:koishijs/koishi.git", + "clone_url": "https://github.com/koishijs/koishi.git", + "svn_url": "https://github.com/koishijs/koishi", + "homepage": "https://koishi.js.org", + "size": 2938, + "stargazers_count": 217, + "watchers_count": 217, + "language": "TypeScript", + "has_issues": true, + "has_projects": true, + "has_downloads": true, + "has_wiki": false, + "has_pages": false, + "forks_count": 16, + "mirror_url": null, + "archived": false, + "disabled": false, + "open_issues_count": 7, + "license": { + "key": "mit", + "name": "MIT License", + "spdx_id": "MIT", + "url": "https://api.github.com/licenses/mit", + "node_id": "MDc6TGljZW5zZTEz" + }, + "forks": 16, + "open_issues": 7, + "watchers": 217, + "default_branch": "master" + }, + "organization": { + "login": "koishijs", + "id": 58179220, + "node_id": "MDEyOk9yZ2FuaXphdGlvbjU4MTc5MjIw", + "url": "https://api.github.com/orgs/koishijs", + "repos_url": "https://api.github.com/orgs/koishijs/repos", + "events_url": "https://api.github.com/orgs/koishijs/events", + "hooks_url": "https://api.github.com/orgs/koishijs/hooks", + "issues_url": "https://api.github.com/orgs/koishijs/issues", + "members_url": "https://api.github.com/orgs/koishijs/members{/member}", + "public_members_url": "https://api.github.com/orgs/koishijs/public_members{/member}", + "avatar_url": "https://avatars3.githubusercontent.com/u/58179220?v=4", + "description": "" + }, + "sender": { + "login": "Shigma", + "id": 33423008, + "node_id": "MDQ6VXNlcjMzNDIzMDA4", + "avatar_url": "https://avatars3.githubusercontent.com/u/33423008?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/Shigma", + "html_url": "https://github.com/Shigma", + "followers_url": "https://api.github.com/users/Shigma/followers", + "following_url": "https://api.github.com/users/Shigma/following{/other_user}", + "gists_url": "https://api.github.com/users/Shigma/gists{/gist_id}", + "starred_url": "https://api.github.com/users/Shigma/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/Shigma/subscriptions", + "organizations_url": "https://api.github.com/users/Shigma/orgs", + "repos_url": "https://api.github.com/users/Shigma/repos", + "events_url": "https://api.github.com/users/Shigma/events{/privacy}", + "received_events_url": "https://api.github.com/users/Shigma/received_events", + "type": "User", + "site_admin": false + } +} \ No newline at end of file diff --git a/packages/plugin-github/tests/fixtures/milestone.closed.json b/packages/plugin-github/tests/fixtures/milestone.closed.json new file mode 100644 index 0000000000..958a1db124 --- /dev/null +++ b/packages/plugin-github/tests/fixtures/milestone.closed.json @@ -0,0 +1,174 @@ +{ + "action": "closed", + "milestone": { + "url": "https://api.github.com/repos/koishijs/koishi/milestones/1", + "html_url": "https://github.com/koishijs/koishi/milestone/1", + "labels_url": "https://api.github.com/repos/koishijs/koishi/milestones/1/labels", + "id": 4996425, + "node_id": "MDk6TWlsZXN0b25lNDk5NjQyNQ==", + "number": 1, + "title": "1.3", + "description": null, + "creator": { + "login": "Shigma", + "id": 33423008, + "node_id": "MDQ6VXNlcjMzNDIzMDA4", + "avatar_url": "https://avatars3.githubusercontent.com/u/33423008?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/Shigma", + "html_url": "https://github.com/Shigma", + "followers_url": "https://api.github.com/users/Shigma/followers", + "following_url": "https://api.github.com/users/Shigma/following{/other_user}", + "gists_url": "https://api.github.com/users/Shigma/gists{/gist_id}", + "starred_url": "https://api.github.com/users/Shigma/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/Shigma/subscriptions", + "organizations_url": "https://api.github.com/users/Shigma/orgs", + "repos_url": "https://api.github.com/users/Shigma/repos", + "events_url": "https://api.github.com/users/Shigma/events{/privacy}", + "received_events_url": "https://api.github.com/users/Shigma/received_events", + "type": "User", + "site_admin": false + }, + "open_issues": 0, + "closed_issues": 1, + "state": "closed", + "created_at": "2020-01-11T15:08:33Z", + "updated_at": "2020-10-27T11:51:11Z", + "due_on": null, + "closed_at": "2020-10-27T11:51:11Z" + }, + "repository": { + "id": 225572038, + "node_id": "MDEwOlJlcG9zaXRvcnkyMjU1NzIwMzg=", + "name": "koishi", + "full_name": "koishijs/koishi", + "private": false, + "owner": { + "login": "koishijs", + "id": 58179220, + "node_id": "MDEyOk9yZ2FuaXphdGlvbjU4MTc5MjIw", + "avatar_url": "https://avatars3.githubusercontent.com/u/58179220?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/koishijs", + "html_url": "https://github.com/koishijs", + "followers_url": "https://api.github.com/users/koishijs/followers", + "following_url": "https://api.github.com/users/koishijs/following{/other_user}", + "gists_url": "https://api.github.com/users/koishijs/gists{/gist_id}", + "starred_url": "https://api.github.com/users/koishijs/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/koishijs/subscriptions", + "organizations_url": "https://api.github.com/users/koishijs/orgs", + "repos_url": "https://api.github.com/users/koishijs/repos", + "events_url": "https://api.github.com/users/koishijs/events{/privacy}", + "received_events_url": "https://api.github.com/users/koishijs/received_events", + "type": "Organization", + "site_admin": false + }, + "html_url": "https://github.com/koishijs/koishi", + "description": "QQ bot out of the box", + "fork": false, + "url": "https://api.github.com/repos/koishijs/koishi", + "forks_url": "https://api.github.com/repos/koishijs/koishi/forks", + "keys_url": "https://api.github.com/repos/koishijs/koishi/keys{/key_id}", + "collaborators_url": "https://api.github.com/repos/koishijs/koishi/collaborators{/collaborator}", + "teams_url": "https://api.github.com/repos/koishijs/koishi/teams", + "hooks_url": "https://api.github.com/repos/koishijs/koishi/hooks", + "issue_events_url": "https://api.github.com/repos/koishijs/koishi/issues/events{/number}", + "events_url": "https://api.github.com/repos/koishijs/koishi/events", + "assignees_url": "https://api.github.com/repos/koishijs/koishi/assignees{/user}", + "branches_url": "https://api.github.com/repos/koishijs/koishi/branches{/branch}", + "tags_url": "https://api.github.com/repos/koishijs/koishi/tags", + "blobs_url": "https://api.github.com/repos/koishijs/koishi/git/blobs{/sha}", + "git_tags_url": "https://api.github.com/repos/koishijs/koishi/git/tags{/sha}", + "git_refs_url": "https://api.github.com/repos/koishijs/koishi/git/refs{/sha}", + "trees_url": "https://api.github.com/repos/koishijs/koishi/git/trees{/sha}", + "statuses_url": "https://api.github.com/repos/koishijs/koishi/statuses/{sha}", + "languages_url": "https://api.github.com/repos/koishijs/koishi/languages", + "stargazers_url": "https://api.github.com/repos/koishijs/koishi/stargazers", + "contributors_url": "https://api.github.com/repos/koishijs/koishi/contributors", + "subscribers_url": "https://api.github.com/repos/koishijs/koishi/subscribers", + "subscription_url": "https://api.github.com/repos/koishijs/koishi/subscription", + "commits_url": "https://api.github.com/repos/koishijs/koishi/commits{/sha}", + "git_commits_url": "https://api.github.com/repos/koishijs/koishi/git/commits{/sha}", + "comments_url": "https://api.github.com/repos/koishijs/koishi/comments{/number}", + "issue_comment_url": "https://api.github.com/repos/koishijs/koishi/issues/comments{/number}", + "contents_url": "https://api.github.com/repos/koishijs/koishi/contents/{+path}", + "compare_url": "https://api.github.com/repos/koishijs/koishi/compare/{base}...{head}", + "merges_url": "https://api.github.com/repos/koishijs/koishi/merges", + "archive_url": "https://api.github.com/repos/koishijs/koishi/{archive_format}{/ref}", + "downloads_url": "https://api.github.com/repos/koishijs/koishi/downloads", + "issues_url": "https://api.github.com/repos/koishijs/koishi/issues{/number}", + "pulls_url": "https://api.github.com/repos/koishijs/koishi/pulls{/number}", + "milestones_url": "https://api.github.com/repos/koishijs/koishi/milestones{/number}", + "notifications_url": "https://api.github.com/repos/koishijs/koishi/notifications{?since,all,participating}", + "labels_url": "https://api.github.com/repos/koishijs/koishi/labels{/name}", + "releases_url": "https://api.github.com/repos/koishijs/koishi/releases{/id}", + "deployments_url": "https://api.github.com/repos/koishijs/koishi/deployments", + "created_at": "2019-12-03T08:47:29Z", + "updated_at": "2020-10-26T18:34:05Z", + "pushed_at": "2020-10-27T11:03:36Z", + "git_url": "git://github.com/koishijs/koishi.git", + "ssh_url": "git@github.com:koishijs/koishi.git", + "clone_url": "https://github.com/koishijs/koishi.git", + "svn_url": "https://github.com/koishijs/koishi", + "homepage": "https://koishi.js.org", + "size": 2938, + "stargazers_count": 217, + "watchers_count": 217, + "language": "TypeScript", + "has_issues": true, + "has_projects": true, + "has_downloads": true, + "has_wiki": false, + "has_pages": false, + "forks_count": 16, + "mirror_url": null, + "archived": false, + "disabled": false, + "open_issues_count": 7, + "license": { + "key": "mit", + "name": "MIT License", + "spdx_id": "MIT", + "url": "https://api.github.com/licenses/mit", + "node_id": "MDc6TGljZW5zZTEz" + }, + "forks": 16, + "open_issues": 7, + "watchers": 217, + "default_branch": "master" + }, + "organization": { + "login": "koishijs", + "id": 58179220, + "node_id": "MDEyOk9yZ2FuaXphdGlvbjU4MTc5MjIw", + "url": "https://api.github.com/orgs/koishijs", + "repos_url": "https://api.github.com/orgs/koishijs/repos", + "events_url": "https://api.github.com/orgs/koishijs/events", + "hooks_url": "https://api.github.com/orgs/koishijs/hooks", + "issues_url": "https://api.github.com/orgs/koishijs/issues", + "members_url": "https://api.github.com/orgs/koishijs/members{/member}", + "public_members_url": "https://api.github.com/orgs/koishijs/public_members{/member}", + "avatar_url": "https://avatars3.githubusercontent.com/u/58179220?v=4", + "description": "" + }, + "sender": { + "login": "Shigma", + "id": 33423008, + "node_id": "MDQ6VXNlcjMzNDIzMDA4", + "avatar_url": "https://avatars3.githubusercontent.com/u/33423008?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/Shigma", + "html_url": "https://github.com/Shigma", + "followers_url": "https://api.github.com/users/Shigma/followers", + "following_url": "https://api.github.com/users/Shigma/following{/other_user}", + "gists_url": "https://api.github.com/users/Shigma/gists{/gist_id}", + "starred_url": "https://api.github.com/users/Shigma/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/Shigma/subscriptions", + "organizations_url": "https://api.github.com/users/Shigma/orgs", + "repos_url": "https://api.github.com/users/Shigma/repos", + "events_url": "https://api.github.com/users/Shigma/events{/privacy}", + "received_events_url": "https://api.github.com/users/Shigma/received_events", + "type": "User", + "site_admin": false + } +} \ No newline at end of file diff --git a/packages/plugin-github/tests/fixtures/milestone.created.json b/packages/plugin-github/tests/fixtures/milestone.created.json new file mode 100644 index 0000000000..59a231a542 --- /dev/null +++ b/packages/plugin-github/tests/fixtures/milestone.created.json @@ -0,0 +1,174 @@ +{ + "action": "created", + "milestone": { + "url": "https://api.github.com/repos/koishijs/koishi/milestones/3", + "html_url": "https://github.com/koishijs/koishi/milestone/3", + "labels_url": "https://api.github.com/repos/koishijs/koishi/milestones/3/labels", + "id": 6037479, + "node_id": "MDk6TWlsZXN0b25lNjAzNzQ3OQ==", + "number": 3, + "title": "3.0", + "description": "koishi v3", + "creator": { + "login": "Shigma", + "id": 33423008, + "node_id": "MDQ6VXNlcjMzNDIzMDA4", + "avatar_url": "https://avatars3.githubusercontent.com/u/33423008?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/Shigma", + "html_url": "https://github.com/Shigma", + "followers_url": "https://api.github.com/users/Shigma/followers", + "following_url": "https://api.github.com/users/Shigma/following{/other_user}", + "gists_url": "https://api.github.com/users/Shigma/gists{/gist_id}", + "starred_url": "https://api.github.com/users/Shigma/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/Shigma/subscriptions", + "organizations_url": "https://api.github.com/users/Shigma/orgs", + "repos_url": "https://api.github.com/users/Shigma/repos", + "events_url": "https://api.github.com/users/Shigma/events{/privacy}", + "received_events_url": "https://api.github.com/users/Shigma/received_events", + "type": "User", + "site_admin": false + }, + "open_issues": 0, + "closed_issues": 0, + "state": "open", + "created_at": "2020-10-27T11:55:28Z", + "updated_at": "2020-10-27T11:55:28Z", + "due_on": null, + "closed_at": null + }, + "repository": { + "id": 225572038, + "node_id": "MDEwOlJlcG9zaXRvcnkyMjU1NzIwMzg=", + "name": "koishi", + "full_name": "koishijs/koishi", + "private": false, + "owner": { + "login": "koishijs", + "id": 58179220, + "node_id": "MDEyOk9yZ2FuaXphdGlvbjU4MTc5MjIw", + "avatar_url": "https://avatars3.githubusercontent.com/u/58179220?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/koishijs", + "html_url": "https://github.com/koishijs", + "followers_url": "https://api.github.com/users/koishijs/followers", + "following_url": "https://api.github.com/users/koishijs/following{/other_user}", + "gists_url": "https://api.github.com/users/koishijs/gists{/gist_id}", + "starred_url": "https://api.github.com/users/koishijs/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/koishijs/subscriptions", + "organizations_url": "https://api.github.com/users/koishijs/orgs", + "repos_url": "https://api.github.com/users/koishijs/repos", + "events_url": "https://api.github.com/users/koishijs/events{/privacy}", + "received_events_url": "https://api.github.com/users/koishijs/received_events", + "type": "Organization", + "site_admin": false + }, + "html_url": "https://github.com/koishijs/koishi", + "description": "QQ bot out of the box", + "fork": false, + "url": "https://api.github.com/repos/koishijs/koishi", + "forks_url": "https://api.github.com/repos/koishijs/koishi/forks", + "keys_url": "https://api.github.com/repos/koishijs/koishi/keys{/key_id}", + "collaborators_url": "https://api.github.com/repos/koishijs/koishi/collaborators{/collaborator}", + "teams_url": "https://api.github.com/repos/koishijs/koishi/teams", + "hooks_url": "https://api.github.com/repos/koishijs/koishi/hooks", + "issue_events_url": "https://api.github.com/repos/koishijs/koishi/issues/events{/number}", + "events_url": "https://api.github.com/repos/koishijs/koishi/events", + "assignees_url": "https://api.github.com/repos/koishijs/koishi/assignees{/user}", + "branches_url": "https://api.github.com/repos/koishijs/koishi/branches{/branch}", + "tags_url": "https://api.github.com/repos/koishijs/koishi/tags", + "blobs_url": "https://api.github.com/repos/koishijs/koishi/git/blobs{/sha}", + "git_tags_url": "https://api.github.com/repos/koishijs/koishi/git/tags{/sha}", + "git_refs_url": "https://api.github.com/repos/koishijs/koishi/git/refs{/sha}", + "trees_url": "https://api.github.com/repos/koishijs/koishi/git/trees{/sha}", + "statuses_url": "https://api.github.com/repos/koishijs/koishi/statuses/{sha}", + "languages_url": "https://api.github.com/repos/koishijs/koishi/languages", + "stargazers_url": "https://api.github.com/repos/koishijs/koishi/stargazers", + "contributors_url": "https://api.github.com/repos/koishijs/koishi/contributors", + "subscribers_url": "https://api.github.com/repos/koishijs/koishi/subscribers", + "subscription_url": "https://api.github.com/repos/koishijs/koishi/subscription", + "commits_url": "https://api.github.com/repos/koishijs/koishi/commits{/sha}", + "git_commits_url": "https://api.github.com/repos/koishijs/koishi/git/commits{/sha}", + "comments_url": "https://api.github.com/repos/koishijs/koishi/comments{/number}", + "issue_comment_url": "https://api.github.com/repos/koishijs/koishi/issues/comments{/number}", + "contents_url": "https://api.github.com/repos/koishijs/koishi/contents/{+path}", + "compare_url": "https://api.github.com/repos/koishijs/koishi/compare/{base}...{head}", + "merges_url": "https://api.github.com/repos/koishijs/koishi/merges", + "archive_url": "https://api.github.com/repos/koishijs/koishi/{archive_format}{/ref}", + "downloads_url": "https://api.github.com/repos/koishijs/koishi/downloads", + "issues_url": "https://api.github.com/repos/koishijs/koishi/issues{/number}", + "pulls_url": "https://api.github.com/repos/koishijs/koishi/pulls{/number}", + "milestones_url": "https://api.github.com/repos/koishijs/koishi/milestones{/number}", + "notifications_url": "https://api.github.com/repos/koishijs/koishi/notifications{?since,all,participating}", + "labels_url": "https://api.github.com/repos/koishijs/koishi/labels{/name}", + "releases_url": "https://api.github.com/repos/koishijs/koishi/releases{/id}", + "deployments_url": "https://api.github.com/repos/koishijs/koishi/deployments", + "created_at": "2019-12-03T08:47:29Z", + "updated_at": "2020-10-26T18:34:05Z", + "pushed_at": "2020-10-27T11:03:36Z", + "git_url": "git://github.com/koishijs/koishi.git", + "ssh_url": "git@github.com:koishijs/koishi.git", + "clone_url": "https://github.com/koishijs/koishi.git", + "svn_url": "https://github.com/koishijs/koishi", + "homepage": "https://koishi.js.org", + "size": 2938, + "stargazers_count": 217, + "watchers_count": 217, + "language": "TypeScript", + "has_issues": true, + "has_projects": true, + "has_downloads": true, + "has_wiki": false, + "has_pages": false, + "forks_count": 16, + "mirror_url": null, + "archived": false, + "disabled": false, + "open_issues_count": 7, + "license": { + "key": "mit", + "name": "MIT License", + "spdx_id": "MIT", + "url": "https://api.github.com/licenses/mit", + "node_id": "MDc6TGljZW5zZTEz" + }, + "forks": 16, + "open_issues": 7, + "watchers": 217, + "default_branch": "master" + }, + "organization": { + "login": "koishijs", + "id": 58179220, + "node_id": "MDEyOk9yZ2FuaXphdGlvbjU4MTc5MjIw", + "url": "https://api.github.com/orgs/koishijs", + "repos_url": "https://api.github.com/orgs/koishijs/repos", + "events_url": "https://api.github.com/orgs/koishijs/events", + "hooks_url": "https://api.github.com/orgs/koishijs/hooks", + "issues_url": "https://api.github.com/orgs/koishijs/issues", + "members_url": "https://api.github.com/orgs/koishijs/members{/member}", + "public_members_url": "https://api.github.com/orgs/koishijs/public_members{/member}", + "avatar_url": "https://avatars3.githubusercontent.com/u/58179220?v=4", + "description": "" + }, + "sender": { + "login": "Shigma", + "id": 33423008, + "node_id": "MDQ6VXNlcjMzNDIzMDA4", + "avatar_url": "https://avatars3.githubusercontent.com/u/33423008?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/Shigma", + "html_url": "https://github.com/Shigma", + "followers_url": "https://api.github.com/users/Shigma/followers", + "following_url": "https://api.github.com/users/Shigma/following{/other_user}", + "gists_url": "https://api.github.com/users/Shigma/gists{/gist_id}", + "starred_url": "https://api.github.com/users/Shigma/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/Shigma/subscriptions", + "organizations_url": "https://api.github.com/users/Shigma/orgs", + "repos_url": "https://api.github.com/users/Shigma/repos", + "events_url": "https://api.github.com/users/Shigma/events{/privacy}", + "received_events_url": "https://api.github.com/users/Shigma/received_events", + "type": "User", + "site_admin": false + } +} \ No newline at end of file diff --git a/packages/plugin-github/tests/fixtures/milestone.edited.json b/packages/plugin-github/tests/fixtures/milestone.edited.json new file mode 100644 index 0000000000..3e1de8fa89 --- /dev/null +++ b/packages/plugin-github/tests/fixtures/milestone.edited.json @@ -0,0 +1,179 @@ +{ + "action": "edited", + "milestone": { + "url": "https://api.github.com/repos/koishijs/koishi/milestones/3", + "html_url": "https://github.com/koishijs/koishi/milestone/3", + "labels_url": "https://api.github.com/repos/koishijs/koishi/milestones/3/labels", + "id": 6037479, + "node_id": "MDk6TWlsZXN0b25lNjAzNzQ3OQ==", + "number": 3, + "title": "3.0", + "description": "koishi v3", + "creator": { + "login": "Shigma", + "id": 33423008, + "node_id": "MDQ6VXNlcjMzNDIzMDA4", + "avatar_url": "https://avatars3.githubusercontent.com/u/33423008?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/Shigma", + "html_url": "https://github.com/Shigma", + "followers_url": "https://api.github.com/users/Shigma/followers", + "following_url": "https://api.github.com/users/Shigma/following{/other_user}", + "gists_url": "https://api.github.com/users/Shigma/gists{/gist_id}", + "starred_url": "https://api.github.com/users/Shigma/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/Shigma/subscriptions", + "organizations_url": "https://api.github.com/users/Shigma/orgs", + "repos_url": "https://api.github.com/users/Shigma/repos", + "events_url": "https://api.github.com/users/Shigma/events{/privacy}", + "received_events_url": "https://api.github.com/users/Shigma/received_events", + "type": "User", + "site_admin": false + }, + "open_issues": 1, + "closed_issues": 0, + "state": "open", + "created_at": "2020-10-27T11:55:28Z", + "updated_at": "2020-10-27T14:42:30Z", + "due_on": null, + "closed_at": null + }, + "changes": { + "description": { + "from": "" + } + }, + "repository": { + "id": 225572038, + "node_id": "MDEwOlJlcG9zaXRvcnkyMjU1NzIwMzg=", + "name": "koishi", + "full_name": "koishijs/koishi", + "private": false, + "owner": { + "login": "koishijs", + "id": 58179220, + "node_id": "MDEyOk9yZ2FuaXphdGlvbjU4MTc5MjIw", + "avatar_url": "https://avatars3.githubusercontent.com/u/58179220?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/koishijs", + "html_url": "https://github.com/koishijs", + "followers_url": "https://api.github.com/users/koishijs/followers", + "following_url": "https://api.github.com/users/koishijs/following{/other_user}", + "gists_url": "https://api.github.com/users/koishijs/gists{/gist_id}", + "starred_url": "https://api.github.com/users/koishijs/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/koishijs/subscriptions", + "organizations_url": "https://api.github.com/users/koishijs/orgs", + "repos_url": "https://api.github.com/users/koishijs/repos", + "events_url": "https://api.github.com/users/koishijs/events{/privacy}", + "received_events_url": "https://api.github.com/users/koishijs/received_events", + "type": "Organization", + "site_admin": false + }, + "html_url": "https://github.com/koishijs/koishi", + "description": "QQ bot out of the box", + "fork": false, + "url": "https://api.github.com/repos/koishijs/koishi", + "forks_url": "https://api.github.com/repos/koishijs/koishi/forks", + "keys_url": "https://api.github.com/repos/koishijs/koishi/keys{/key_id}", + "collaborators_url": "https://api.github.com/repos/koishijs/koishi/collaborators{/collaborator}", + "teams_url": "https://api.github.com/repos/koishijs/koishi/teams", + "hooks_url": "https://api.github.com/repos/koishijs/koishi/hooks", + "issue_events_url": "https://api.github.com/repos/koishijs/koishi/issues/events{/number}", + "events_url": "https://api.github.com/repos/koishijs/koishi/events", + "assignees_url": "https://api.github.com/repos/koishijs/koishi/assignees{/user}", + "branches_url": "https://api.github.com/repos/koishijs/koishi/branches{/branch}", + "tags_url": "https://api.github.com/repos/koishijs/koishi/tags", + "blobs_url": "https://api.github.com/repos/koishijs/koishi/git/blobs{/sha}", + "git_tags_url": "https://api.github.com/repos/koishijs/koishi/git/tags{/sha}", + "git_refs_url": "https://api.github.com/repos/koishijs/koishi/git/refs{/sha}", + "trees_url": "https://api.github.com/repos/koishijs/koishi/git/trees{/sha}", + "statuses_url": "https://api.github.com/repos/koishijs/koishi/statuses/{sha}", + "languages_url": "https://api.github.com/repos/koishijs/koishi/languages", + "stargazers_url": "https://api.github.com/repos/koishijs/koishi/stargazers", + "contributors_url": "https://api.github.com/repos/koishijs/koishi/contributors", + "subscribers_url": "https://api.github.com/repos/koishijs/koishi/subscribers", + "subscription_url": "https://api.github.com/repos/koishijs/koishi/subscription", + "commits_url": "https://api.github.com/repos/koishijs/koishi/commits{/sha}", + "git_commits_url": "https://api.github.com/repos/koishijs/koishi/git/commits{/sha}", + "comments_url": "https://api.github.com/repos/koishijs/koishi/comments{/number}", + "issue_comment_url": "https://api.github.com/repos/koishijs/koishi/issues/comments{/number}", + "contents_url": "https://api.github.com/repos/koishijs/koishi/contents/{+path}", + "compare_url": "https://api.github.com/repos/koishijs/koishi/compare/{base}...{head}", + "merges_url": "https://api.github.com/repos/koishijs/koishi/merges", + "archive_url": "https://api.github.com/repos/koishijs/koishi/{archive_format}{/ref}", + "downloads_url": "https://api.github.com/repos/koishijs/koishi/downloads", + "issues_url": "https://api.github.com/repos/koishijs/koishi/issues{/number}", + "pulls_url": "https://api.github.com/repos/koishijs/koishi/pulls{/number}", + "milestones_url": "https://api.github.com/repos/koishijs/koishi/milestones{/number}", + "notifications_url": "https://api.github.com/repos/koishijs/koishi/notifications{?since,all,participating}", + "labels_url": "https://api.github.com/repos/koishijs/koishi/labels{/name}", + "releases_url": "https://api.github.com/repos/koishijs/koishi/releases{/id}", + "deployments_url": "https://api.github.com/repos/koishijs/koishi/deployments", + "created_at": "2019-12-03T08:47:29Z", + "updated_at": "2020-10-26T18:34:05Z", + "pushed_at": "2020-10-27T11:03:36Z", + "git_url": "git://github.com/koishijs/koishi.git", + "ssh_url": "git@github.com:koishijs/koishi.git", + "clone_url": "https://github.com/koishijs/koishi.git", + "svn_url": "https://github.com/koishijs/koishi", + "homepage": "https://koishi.js.org", + "size": 2943, + "stargazers_count": 217, + "watchers_count": 217, + "language": "TypeScript", + "has_issues": true, + "has_projects": true, + "has_downloads": true, + "has_wiki": false, + "has_pages": false, + "forks_count": 16, + "mirror_url": null, + "archived": false, + "disabled": false, + "open_issues_count": 7, + "license": { + "key": "mit", + "name": "MIT License", + "spdx_id": "MIT", + "url": "https://api.github.com/licenses/mit", + "node_id": "MDc6TGljZW5zZTEz" + }, + "forks": 16, + "open_issues": 7, + "watchers": 217, + "default_branch": "master" + }, + "organization": { + "login": "koishijs", + "id": 58179220, + "node_id": "MDEyOk9yZ2FuaXphdGlvbjU4MTc5MjIw", + "url": "https://api.github.com/orgs/koishijs", + "repos_url": "https://api.github.com/orgs/koishijs/repos", + "events_url": "https://api.github.com/orgs/koishijs/events", + "hooks_url": "https://api.github.com/orgs/koishijs/hooks", + "issues_url": "https://api.github.com/orgs/koishijs/issues", + "members_url": "https://api.github.com/orgs/koishijs/members{/member}", + "public_members_url": "https://api.github.com/orgs/koishijs/public_members{/member}", + "avatar_url": "https://avatars3.githubusercontent.com/u/58179220?v=4", + "description": "" + }, + "sender": { + "login": "Shigma", + "id": 33423008, + "node_id": "MDQ6VXNlcjMzNDIzMDA4", + "avatar_url": "https://avatars3.githubusercontent.com/u/33423008?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/Shigma", + "html_url": "https://github.com/Shigma", + "followers_url": "https://api.github.com/users/Shigma/followers", + "following_url": "https://api.github.com/users/Shigma/following{/other_user}", + "gists_url": "https://api.github.com/users/Shigma/gists{/gist_id}", + "starred_url": "https://api.github.com/users/Shigma/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/Shigma/subscriptions", + "organizations_url": "https://api.github.com/users/Shigma/orgs", + "repos_url": "https://api.github.com/users/Shigma/repos", + "events_url": "https://api.github.com/users/Shigma/events{/privacy}", + "received_events_url": "https://api.github.com/users/Shigma/received_events", + "type": "User", + "site_admin": false + } +} \ No newline at end of file diff --git a/packages/plugin-github/tests/index.snap.js b/packages/plugin-github/tests/index.snap.js index 1ee20a62dd..f764950118 100644 --- a/packages/plugin-github/tests/index.snap.js +++ b/packages/plugin-github/tests/index.snap.js @@ -39,6 +39,10 @@ module.exports[`issues.opened`] = ` Title: Wie kann man um das Koishi zu installieren? Ich verstecke Englisch und Chinesisch nicht! Gab es Personen, die mir helfen kann?` +module.exports['milestone.created'] = ` +[GitHub] Shigma created milestone 3.0 for koishijs/koishi +koishi v3` + module.exports['pull_request.closed.1'] = ` [GitHub] Shigma closed pull request koishijs/koishi#97 Storage API, fix #96` diff --git a/packages/plugin-image-search/package.json b/packages/plugin-image-search/package.json index 5e8b69070c..2b061a948d 100644 --- a/packages/plugin-image-search/package.json +++ b/packages/plugin-image-search/package.json @@ -1,7 +1,7 @@ { "name": "koishi-plugin-image-search", "description": "Image searching plugin for Koishi", - "version": "2.0.1", + "version": "2.0.2", "main": "dist/index.js", "typings": "dist/index.d.ts", "files": [ @@ -37,7 +37,7 @@ "pixiv" ], "peerDependencies": { - "koishi-core": "^2.4.1", + "koishi-core": "^2.4.2", "koishi-utils": "^3.1.5" }, "dependencies": { diff --git a/packages/plugin-image-search/src/index.ts b/packages/plugin-image-search/src/index.ts index dd920e583c..933aa5e791 100644 --- a/packages/plugin-image-search/src/index.ts +++ b/packages/plugin-image-search/src/index.ts @@ -1,4 +1,4 @@ -import { Context, Session, Group, CommandAction, getContextId } from 'koishi-core' +import { Context, Session, CommandAction, getContextId } from 'koishi-core' import ascii2d from './ascii2d' import saucenao from './saucenao' @@ -27,18 +27,12 @@ export const name = 'search' export function apply(ctx: Context, config: Config = {}) { const command = ctx.command('search <...images>', '搜图片') .alias('搜图') - .groupFields(['flag']) - .before(session => !!(session.$group.flag & Group.Flag.noImage)) .action(search(mixedSearch)) command.subcommand('saucenao <...images>', '使用 saucenao 搜图') - .groupFields(['flag']) - .before(session => !!(session.$group.flag & Group.Flag.noImage)) .action(search(saucenao)) command.subcommand('ascii2d <...images>', '使用 ascii2d 搜图') - .groupFields(['flag']) - .before(session => !!(session.$group.flag & Group.Flag.noImage)) .action(search(ascii2d)) const pending = new Set() diff --git a/packages/plugin-mongo/package.json b/packages/plugin-mongo/package.json index 95cce8c019..44d16e2c32 100644 --- a/packages/plugin-mongo/package.json +++ b/packages/plugin-mongo/package.json @@ -36,12 +36,12 @@ "mysql" ], "devDependencies": { - "@types/mongodb": "^3.5.32" + "@types/mongodb": "^3.5.33" }, "peerDependencies": { - "koishi-core": "^2.4.1" + "koishi-core": "^2.4.2" }, "dependencies": { - "mongodb": "^3.6.2" + "mongodb": "^3.6.3" } } diff --git a/packages/plugin-monitor/package.json b/packages/plugin-monitor/package.json index ad5f65450d..bc2c2a10ed 100644 --- a/packages/plugin-monitor/package.json +++ b/packages/plugin-monitor/package.json @@ -21,7 +21,7 @@ }, "homepage": "https://github.com/koishijs/koishi#readme", "peerDependencies": { - "koishi-core": "^2.4.1", + "koishi-core": "^2.4.2", "koishi-utils": "^3.1.5" } } diff --git a/packages/plugin-mysql/package.json b/packages/plugin-mysql/package.json index 2f6ff332fb..b45dc37c36 100644 --- a/packages/plugin-mysql/package.json +++ b/packages/plugin-mysql/package.json @@ -1,7 +1,7 @@ { "name": "koishi-plugin-mysql", "description": "MySQL support for Koishi", - "version": "2.0.2", + "version": "2.1.0", "main": "dist/index.js", "typings": "dist/index.d.ts", "files": [ @@ -36,7 +36,7 @@ "@types/mysql": "^2.15.15" }, "peerDependencies": { - "koishi-core": "^2.4.1", + "koishi-core": "^2.4.2", "koishi-utils": "^3.1.5" }, "dependencies": { diff --git a/packages/plugin-mysql/src/database.ts b/packages/plugin-mysql/src/database.ts index 0fdde24cb0..f63344dbb7 100644 --- a/packages/plugin-mysql/src/database.ts +++ b/packages/plugin-mysql/src/database.ts @@ -49,17 +49,30 @@ export default class MysqlDatabase { async start() { this.pool = createPool(this.config) - const tables = await this.select('information_schema.tables', ['TABLE_NAME'], 'TABLE_SCHEMA = ?', [this.config.database]) - const names = new Set(tables.map(data => data.TABLE_NAME)) - for (const name of Object.keys(MysqlDatabase.tables) as TableType[]) { - if (names.has(name)) return + const data = await this.select('information_schema.columns', ['TABLE_NAME', 'COLUMN_NAME'], 'TABLE_SCHEMA = ?', [this.config.database]) + const tables: Record = {} + for (const { TABLE_NAME, COLUMN_NAME } of data) { + if (!tables[TABLE_NAME]) tables[TABLE_NAME] = [] + tables[TABLE_NAME].push(COLUMN_NAME) + } + + for (const name in MysqlDatabase.tables) { const table = MysqlDatabase.tables[name] - const cols = Object.keys(table).map((key) => { - if (+key * 0 === 0) return table[key] - return `\`${key}\` ${table[key]}` - }) - logger.info('auto creating table %c', name) - await this.query(`CREATE TABLE ?? (${cols.join(',')}) COLLATE = ?`, [name, this.config.charset]) + if (!tables[name]) { + const cols = Object.keys(table).map((key) => { + if (+key * 0 === 0) return table[key] + return `\`${key}\` ${table[key]}` + }) + logger.info('auto creating table %c', name) + await this.query(`CREATE TABLE ?? (${cols.join(',')}) COLLATE = ?`, [name, this.config.charset]) + } else { + const cols = Object.keys(table) + .filter(key => +key * 0 !== 0 && !tables[name].includes(key)) + .map(key => `ADD \`${key}\` ${table[key]}`) + if (!cols.length) continue + logger.info('auto updating table %c', name) + await this.query(`ALTER TABLE ?? ${cols.join(',')}`, [name]) + } } } @@ -98,8 +111,8 @@ export default class MysqlDatabase { this.pool.query(sql, (err, results) => { if (!err) return resolve(results) logger.warn(sql) - error.stack = err.message + error.stack.slice(7) - reject(error) + err.stack = err.message + error.stack.slice(7) + reject(err) }) }) } diff --git a/packages/plugin-puppeteer/package.json b/packages/plugin-puppeteer/package.json index a37dfd3226..4f0ac23ad2 100644 --- a/packages/plugin-puppeteer/package.json +++ b/packages/plugin-puppeteer/package.json @@ -36,15 +36,15 @@ "devDependencies": { "@types/pngjs": "^3.4.2", "@types/puppeteer-core": "^2.0.0", - "koishi-test-utils": "^5.0.2" + "koishi-test-utils": "^5.0.3" }, "peerDependencies": { - "koishi-core": "^2.4.1", + "koishi-core": "^2.4.2", "koishi-utils": "^3.1.5" }, "dependencies": { "chrome-finder": "^1.0.7", "pngjs": "^6.0.0", - "puppeteer-core": "^5.4.1" + "puppeteer-core": "^5.5.0" } } diff --git a/packages/plugin-rss/package.json b/packages/plugin-rss/package.json index 90e56ce593..edd63cf1aa 100644 --- a/packages/plugin-rss/package.json +++ b/packages/plugin-rss/package.json @@ -36,11 +36,11 @@ "rss" ], "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" }, "dependencies": { "rss-feed-emitter": "^3.2.2" diff --git a/packages/plugin-schedule/package.json b/packages/plugin-schedule/package.json index c8731e26a6..be34d23880 100644 --- a/packages/plugin-schedule/package.json +++ b/packages/plugin-schedule/package.json @@ -35,11 +35,11 @@ ], "devDependencies": { "koishi-plugin-mongo": "^1.1.2", - "koishi-plugin-mysql": "^2.0.2", - "koishi-test-utils": "^5.0.2" + "koishi-plugin-mysql": "^2.1.0", + "koishi-test-utils": "^5.0.3" }, "peerDependencies": { - "koishi-core": "^2.4.1", + "koishi-core": "^2.4.2", "koishi-utils": "^3.1.5" } } diff --git a/packages/plugin-status/package.json b/packages/plugin-status/package.json index 2b0db8870b..2267570baf 100644 --- a/packages/plugin-status/package.json +++ b/packages/plugin-status/package.json @@ -1,7 +1,7 @@ { "name": "koishi-plugin-status", "description": "Show Status of Koishi", - "version": "2.0.0-beta.17", + "version": "2.0.0", "main": "dist/index.js", "typings": "dist/index.d.ts", "files": [ @@ -32,12 +32,12 @@ "status" ], "peerDependencies": { - "koishi-core": "^2.4.1", + "koishi-core": "^2.4.2", "koishi-utils": "^3.1.5" }, "devDependencies": { "koishi-plugin-mongo": "^1.1.2", - "koishi-plugin-mysql": "^2.0.2", - "koishi-test-utils": "^5.0.2" + "koishi-plugin-mysql": "^2.1.0", + "koishi-test-utils": "^5.0.3" } } diff --git a/packages/plugin-status/src/index.ts b/packages/plugin-status/src/index.ts index 9ee808e6e4..6bcf096d9f 100644 --- a/packages/plugin-status/src/index.ts +++ b/packages/plugin-status/src/index.ts @@ -1,6 +1,6 @@ import { Context, App, BotStatusCode } from 'koishi-core' import { cpus, totalmem, freemem } from 'os' -import { Time } from 'koishi-utils' +import { interpolate, Time } from 'koishi-utils' import { ActiveData } from './database' export * from './database' @@ -17,7 +17,8 @@ declare module 'koishi-core/dist/server' { export interface Config { refresh?: number - output?: (status: Status) => string + format?: string + formatBot?: string } let usage = getCpuUsage() @@ -90,32 +91,24 @@ const startTime = Date.now() const defaultConfig: Config = { refresh: Time.minute, - output({ bots, cpu, memory, startTime, activeUsers, activeGroups }) { - const output = bots - .filter(bot => bot.code !== BotStatusCode.BOT_IDLE) - .map(({ label, selfId, code, rate }) => { - return `${label || selfId}:${code ? '无法连接' : `工作中(${rate}/min)`}` - }) - - output.push('==========') - - output.push( - `活跃用户数量:${activeUsers}`, - `活跃群数量:${activeGroups}`, - `启动时间:${new Date(startTime).toLocaleString('zh-CN', { hour12: false })}`, - `CPU 使用率:${(cpu.app * 100).toFixed()}% / ${(cpu.total * 100).toFixed()}%`, - `内存使用率:${(memory.app * 100).toFixed()}% / ${(memory.total * 100).toFixed()}%`, - ) - - return output.join('\n') - }, + // eslint-disable-next-line no-template-curly-in-string + formatBot: '{{ label || selfId }}:{{ code ? `无法连接` : `工作中(${rate}/min)` }}', + format: [ + '{{ bots }}', + '==========', + '活跃用户数量:{{ activeUsers }}', + '活跃群数量:{{ activeGroups }}', + '启动时间:{{ new Date(startTime).toLocaleString("zh-CN", { hour12: false }) }}', + 'CPU 使用率:{{ (cpu.app * 100).toFixed() }}% / {{ (cpu.total * 100).toFixed() }}%', + '内存使用率:{{ (memory.app * 100).toFixed() }}% / {{ (memory.total * 100).toFixed() }}%', + ].join('\n'), } export const name = 'status' export function apply(ctx: Context, config: Config = {}) { const app = ctx.app - const { refresh, output } = { ...defaultConfig, ...config } + const { refresh, formatBot, format } = { ...defaultConfig, ...config } app.on('before-command', ({ session }) => { session.$user['lastCall'] = new Date() @@ -166,7 +159,11 @@ export function apply(ctx: Context, config: Config = {}) { .shortcut('运行情况', { prefix: true }) .shortcut('运行状态', { prefix: true }) .action(async () => { - return output(await getStatus()) + const status = await getStatus() + status.bots.toString = () => { + return status.bots.map(bot => interpolate(formatBot, bot)).join('\n') + } + return interpolate(format, status) }) async function _getStatus(extend: boolean) { diff --git a/packages/plugin-teach/package.json b/packages/plugin-teach/package.json index f0110e1a1f..5eb8453435 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": "1.2.1", + "version": "1.2.2", "main": "dist/index.js", "typings": "dist/index.d.ts", "engines": { @@ -38,13 +38,13 @@ "conversation" ], "peerDependencies": { - "koishi-core": "^2.4.1", + "koishi-core": "^2.4.2", "koishi-utils": "^3.1.5" }, "devDependencies": { "koishi-plugin-mongo": "^1.1.2", - "koishi-plugin-mysql": "^2.0.2", - "koishi-test-utils": "^5.0.2" + "koishi-plugin-mysql": "^2.1.0", + "koishi-test-utils": "^5.0.3" }, "dependencies": { "axios": "^0.21.0", diff --git a/packages/plugin-teach/src/internal.ts b/packages/plugin-teach/src/internal.ts index caa9ae3935..1bae30e71c 100644 --- a/packages/plugin-teach/src/internal.ts +++ b/packages/plugin-teach/src/internal.ts @@ -1,6 +1,6 @@ import { Context, Message } from 'koishi-core' import { Dialogue } from './utils' -import { update } from './update' +import { create, update } from './update' import { RegExpValidator } from 'regexpp' import { defineProperty } from 'koishi-utils' import { formatQuestionAnswers } from './search' @@ -93,6 +93,10 @@ export default function apply(ctx: Context, config: Dialogue.Config) { const { options, session, target, dialogues } = argv const { question, answer, ignoreHint, regexp } = options + function applySuggestion(argv: Dialogue.Argv) { + return argv.target ? update(argv) : create(argv) + } + // 修改问答时发现可能想改回答但是改了问题 if (target && !ignoreHint && question && !answer && maybeAnswer(question, dialogues)) { const dispose = session.$use(({ message }, next) => { @@ -101,7 +105,7 @@ export default function apply(ctx: Context, config: Dialogue.Config) { if (message && message !== '.' && message !== '。') return next() options.answer = options.original delete options.question - return update(argv) + return applySuggestion(argv) }) return Message.Teach.MayModifyAnswer } @@ -113,7 +117,7 @@ export default function apply(ctx: Context, config: Dialogue.Config) { message = message.trim() if (message && message !== '.' && message !== '。') return next() options.regexp = true - return update(argv) + return applySuggestion(argv) }) return format(Message.Teach.MaybeRegExp, target ? '修改' : '添加') } diff --git a/packages/plugin-teach/src/receiver.ts b/packages/plugin-teach/src/receiver.ts index 2cf05b4dd1..e33812de00 100644 --- a/packages/plugin-teach/src/receiver.ts +++ b/packages/plugin-teach/src/receiver.ts @@ -232,12 +232,13 @@ export async function triggerDialogue(ctx: Context, session: Session, next: Next if (char === 'n') { await buffer.flush() } else if (char === '{') { - const argv = session.$parse(state.answer, '}') + const message = unescapeAnswer(state.answer) + const argv = session.$parse(message, '}') if (argv) { state.answer = argv.rest.slice(1) await buffer.run(() => session.$execute(argv)) } else { - logger.warn('cannot parse:', state.answer) + logger.warn('cannot parse:', message) const index = state.answer.indexOf('}') state.answer = state.answer.slice(index + 1) } @@ -247,7 +248,7 @@ export async function triggerDialogue(ctx: Context, session: Session, next: Next await ctx.app.parallel(session, 'dialogue/send', state) } -export default function (ctx: Context, config: Dialogue.Config) { +export default function apply(ctx: Context, config: Dialogue.Config) { const { nickname = ctx.app.options.nickname, maxRedirections = 3 } = config const nicknames = makeArray(nickname).map(escapeRegExp) const nicknameRE = new RegExp(`^((${nicknames.join('|')})[,,]?\\s*)+`) @@ -267,6 +268,12 @@ export default function (ctx: Context, config: Dialogue.Config) { } } + ctx.prependListener('parse', (message, session) => { + if (session.$appel) return + const { activated } = ctx.getSessionState(session) + if (activated[session.userId]) session.$appel = true + }) + ctx.group().middleware(async (session, next) => { return triggerDialogue(ctx, session, next) }) diff --git a/packages/plugin-tools/package.json b/packages/plugin-tools/package.json index d4d2183d25..22247fed1c 100644 --- a/packages/plugin-tools/package.json +++ b/packages/plugin-tools/package.json @@ -25,7 +25,7 @@ "@types/qrcode": "^1.3.5" }, "peerDependencies": { - "koishi-core": "^2.4.1", + "koishi-core": "^2.4.2", "koishi-utils": "^3.1.5" }, "dependencies": { diff --git a/packages/plugin-tools/src/music/netease.ts b/packages/plugin-tools/src/music/netease.ts index 1a4f2963e3..1c02cd56e6 100644 --- a/packages/plugin-tools/src/music/netease.ts +++ b/packages/plugin-tools/src/music/netease.ts @@ -1,6 +1,6 @@ import axios from 'axios' -export default async function (keyword: string) { +export default async function search(keyword: string) { const { data } = await axios.get('http://music.163.com/api/cloudsearch/pc', { params: { s: keyword, type: 1, offset: 0, limit: 5 }, }) diff --git a/packages/plugin-tools/src/music/qq.ts b/packages/plugin-tools/src/music/qq.ts index 3fe46f1c29..007cc57135 100644 --- a/packages/plugin-tools/src/music/qq.ts +++ b/packages/plugin-tools/src/music/qq.ts @@ -1,6 +1,6 @@ import axios from 'axios' -export default async function (keyword: string) { +export default async function search(keyword: string) { const { data } = await axios.get('https://c.y.qq.com/soso/fcgi-bin/client_search_cp', { params: { p: 1, n: 5, w: keyword, format: 'json' }, })