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 20, 2021
2 parents c78a66c + 6fd01f7 commit 21b7d22
Show file tree
Hide file tree
Showing 63 changed files with 534 additions and 336 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
lib
dist
temp
.koishi
Expand Down
51 changes: 28 additions & 23 deletions .mocharc.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,43 +3,48 @@ const { readdirSync } = require('fs')
process.env.TS_NODE_PROJECT = 'tsconfig.test.json'

const prefixes = ['koishi-', 'adapter-', 'plugin-', '']
const packageMap = {}
const libraries = {}

for (const name of readdirSync(__dirname + '/packages')) {
for (const prefix of prefixes) {
if (name.startsWith(prefix)) {
packageMap[name.slice(prefix.length)] = name
libraries[name.slice(prefix.length)] = name
break
}
}
}

const specs = [
// 'packages/koishi-core/tests/*.spec.ts',
'packages/koishi-core/tests/command.spec.ts',
'packages/koishi-core/tests/context.spec.ts',
'packages/koishi-core/tests/help.spec.ts',
'packages/koishi-core/tests/hook.spec.ts',
'packages/koishi-core/tests/session.spec.ts',
'packages/koishi-core/tests/parser.spec.ts',
'packages/koishi-utils/tests/*.spec.ts',
'packages/koishi-test-utils/tests/*.spec.ts',
'packages/plugin-common/tests/*.spec.ts',
'packages/plugin-eval/tests/*.spec.ts',
'packages/plugin-github/tests/*.spec.ts',
'packages/plugin-teach/tests/*.spec.ts',
]

function getSpecFromArgv() {
if (!process.env.npm_config_argv) return
if (!process.env.npm_config_argv) return specs
const { original } = JSON.parse(process.env.npm_config_argv)
if (original.length === 1) return
if (original.length === 1) return specs
process.argv.splice(1 - original.length, Infinity)
return original.slice(1).map((path) => {
const [name] = path.split('/')
return `packages/${packageMap[name]}/tests/${path.slice(name.length) || '*'}.spec.ts`
})
return original.slice(1).flatMap((path) => {
const [lib] = path.split('/')
const target = path.slice(lib.length)
const prefix = `packages/${libraries[lib]}/tests/`
if (target) return prefix + target + `.spec.ts`
return specs.filter(name => name.startsWith(prefix))
}, 1)
}

module.exports = {
exit: true,
spec: getSpecFromArgv() || [
// 'packages/koishi-core/tests/*.spec.ts',
'packages/koishi-core/tests/command.spec.ts',
'packages/koishi-core/tests/context.spec.ts',
'packages/koishi-core/tests/help.spec.ts',
'packages/koishi-core/tests/hook.spec.ts',
'packages/koishi-core/tests/session.spec.ts',
'packages/koishi-core/tests/parser.spec.ts',
'packages/koishi-utils/tests/*.spec.ts',
'packages/koishi-test-utils/tests/*.spec.ts',
'packages/plugin-common/tests/*.spec.ts',
'packages/plugin-eval/tests/*.spec.ts',
'packages/plugin-github/tests/*.spec.ts',
'packages/plugin-teach/tests/*.spec.ts',
],
spec: getSpecFromArgv(),
}
4 changes: 3 additions & 1 deletion build/compile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ const KOISHI_VERSION = JSON.stringify(version)
await Promise.all(workspaces.map(async (name) => {
if (name.startsWith('.')) return

let outdir = 'dist'
const base = `${root}/${name}`
const entryPoints = [base + '/src/index.ts']

Expand All @@ -60,6 +61,7 @@ const KOISHI_VERSION = JSON.stringify(version)
} else if (name === 'koishi-test-utils') {
await tasks[chai]
} else if (name === 'plugin-status') {
outdir = 'lib'
entryPoints.splice(0, 1, base + '/server/index.ts')
}

Expand All @@ -70,7 +72,7 @@ const KOISHI_VERSION = JSON.stringify(version)
platform: 'node',
target: 'node12.19',
charset: 'utf8',
outdir: `${root}/${name}/dist`,
outdir: `${root}/${name}/${outdir}`,
logLevel: 'silent',
sourcemap: true,
define: {
Expand Down
17 changes: 9 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@
"addons": "yarn workspace addons",
"cli": "yarn workspace test koishi",
"build": "yarn compile && yarn dtsc",
"build:ci": "yarn build:reg && yarn build --listEmittedFiles",
"build:ci": "yarn build:reg && yarn build --listEmittedFiles && yarn build:web",
"build:reg": "esbuild build/register.ts --outdir=build --format=cjs --log-level=error",
"build:web": "node -r ./build/register packages/plugin-status/build",
"dtsc": "node -r ./build/register build/dtsc",
"bump": "node -r ./build/register build/bump",
"compile": "node -r ./build/register build/compile",
Expand All @@ -28,7 +29,7 @@
"test:text": "c8 -r text yarn test",
"test:reg": "yarn build:reg && yarn test:html",
"lint": "eslint packages/*/src/**/*.ts --fix --cache",
"pub": "yarn build && node -r ./build/register build/publish",
"pub": "yarn build && yarn build:web && node -r ./build/register build/publish",
"webui": "yarn workspace koishi-plugin-webui",
"shiki": "yarn workspace bot-shiki",
"utsuho": "yarn workspace bot-utsuho"
Expand All @@ -43,7 +44,7 @@
"@types/cross-spawn": "^6.0.2",
"@types/fs-extra": "^9.0.8",
"@types/mocha": "^8.2.1",
"@types/node": "^14.14.34",
"@types/node": "^14.14.35",
"@types/rimraf": "^3.0.0",
"@types/semver": "^7.3.4",
"@types/sinonjs__fake-timers": "^6.0.2",
Expand All @@ -52,13 +53,13 @@
"@typescript-eslint/parser": "^3.10.1",
"c8": "^7.6.0",
"cac": "^6.7.2",
"chai": "^4.3.3",
"chai": "^4.3.4",
"chai-as-promised": "^7.1.1",
"cross-env": "^7.0.3",
"cross-spawn": "^7.0.3",
"del": "^6.0.0",
"esbuild": "^0.9.1",
"eslint": "^7.21.0",
"esbuild": "^0.9.4",
"eslint": "^7.22.0",
"eslint-config-standard": "^16.0.2",
"eslint-import-resolver-typescript": "^2.4.0",
"eslint-plugin-import": "^2.22.1",
Expand All @@ -74,8 +75,8 @@
"latest-version": "^5.1.0",
"mocha": "^8.3.2",
"nock": "^13.0.11",
"open": "^8.0.2",
"ora": "^5.3.0",
"open": "^8.0.3",
"ora": "^5.4.0",
"p-map": "^4.0.0",
"prompts": "^2.4.0",
"rimraf": "^3.0.2",
Expand Down
2 changes: 1 addition & 1 deletion packages/adapter-discord/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"koishi"
],
"peerDependencies": {
"koishi-core": "^3.2.1"
"koishi-core": "^3.3.0"
},
"devDependencies": {
"@types/ws": "^7.4.0",
Expand Down
4 changes: 2 additions & 2 deletions packages/adapter-kaiheila/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@
"koishi"
],
"peerDependencies": {
"koishi-core": "^3.2.1"
"koishi-core": "^3.3.0"
},
"devDependencies": {
"koishi-test-utils": "^6.0.0-beta.10"
},
"dependencies": {
"axios": "^0.21.1",
"koishi-utils": "^4.0.2",
"koishi-utils": "^4.0.3",
"ws": "^7.4.4"
}
}
4 changes: 2 additions & 2 deletions packages/adapter-onebot/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"koishi"
],
"peerDependencies": {
"koishi-core": "^3.2.1"
"koishi-core": "^3.3.0"
},
"devDependencies": {
"@types/ws": "^7.4.0",
Expand All @@ -36,7 +36,7 @@
},
"dependencies": {
"axios": "^0.21.1",
"koishi-utils": "^4.0.2",
"koishi-utils": "^4.0.3",
"ws": "^7.4.4"
}
}
6 changes: 3 additions & 3 deletions packages/adapter-telegram/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "koishi-adapter-telegram",
"description": "Telegram adapter for Koishi",
"version": "1.0.0",
"version": "1.0.1",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
"files": [
Expand All @@ -28,14 +28,14 @@
"koishi"
],
"peerDependencies": {
"koishi-core": "^3.2.1"
"koishi-core": "^3.3.0"
},
"devDependencies": {
"koishi-test-utils": "^6.0.0-beta.10"
},
"dependencies": {
"axios": "^0.21.1",
"form-data": "^4.0.0",
"koishi-utils": "^4.0.2"
"koishi-utils": "^4.0.3"
}
}
5 changes: 5 additions & 0 deletions packages/adapter-telegram/src/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ export default class HttpServer extends Adapter<'telegram'> {
const { data } = await axios.get(endpoint + '/bot' + token + `/getFile?file_id=${fid}`)
msg += ` [CQ:image,file=${fid},url=${endpoint}/file/bot${token}/${data.result.file_path}]`
}
if (message.sticker) {
const fid = message.sticker.fileId
const { data } = await axios.get(endpoint + '/bot' + token + `/getFile?file_id=${fid}`)
msg += ` [CQ:image,file=${fid},url=${endpoint}/file/bot${token}/${data.result.file_path}]`
}
for (const entity of message.entities || []) {
if (entity.type === 'mention') {
const name = msg.substr(entity.offset, entity.length)
Expand Down
4 changes: 2 additions & 2 deletions packages/adapter-tomon/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@
"koishi"
],
"peerDependencies": {
"koishi-core": "^3.2.1"
"koishi-core": "^3.3.0"
},
"devDependencies": {
"@types/pako": "^1.0.1",
"koishi-test-utils": "^6.0.0-beta.10"
},
"dependencies": {
"axios": "^0.21.1",
"koishi-utils": "^4.0.2",
"koishi-utils": "^4.0.3",
"pako": "^2.0.3",
"ws": "^7.4.4"
}
Expand Down
4 changes: 2 additions & 2 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": "3.2.1",
"version": "3.3.0",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
"engines": {
Expand Down Expand Up @@ -42,7 +42,7 @@
"fastest-levenshtein": "^1.0.12",
"koa": "^2.13.1",
"koa-bodyparser": "^4.3.0",
"koishi-utils": "^4.0.2",
"koishi-utils": "^4.0.3",
"lru-cache": "^6.0.0"
}
}
14 changes: 4 additions & 10 deletions packages/koishi-core/src/adapter.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Logger, paramCase, remove, sleep, Time } from 'koishi-utils'
import { Logger, paramCase, sleep, Time } from 'koishi-utils'
import { Session } from './session'
import { App } from './app'
import WebSocket from 'ws'
Expand Down Expand Up @@ -28,10 +28,10 @@ export abstract class Adapter<P extends Platform = Platform> {
abstract start(): Promise<void>
abstract stop?(): void

constructor(public app: App, private Bot: Bot.Constructor<P>) {}
constructor(public app: App, private Bot?: Bot.Constructor<P>) {}

create(options: BotOptions) {
const bot = new this.Bot(this, options)
create(options: BotOptions, constructor = this.Bot) {
const bot = new constructor(this, options)
this.bots.push(bot)
this.app.bots.push(bot)
return bot
Expand Down Expand Up @@ -255,12 +255,6 @@ export class Bot<P extends Platform> {
}
return messageIds
}

dispose() {
const bot = this as Bot.Instance<P>
remove(this.adapter.bots, bot)
remove(this.app.bots, bot)
}
}

export namespace Bot {
Expand Down
Loading

0 comments on commit 21b7d22

Please sign in to comment.