Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
shigma committed Mar 15, 2021
2 parents 90128ec + 942a648 commit c3885b1
Show file tree
Hide file tree
Showing 75 changed files with 1,673 additions and 632 deletions.
2 changes: 1 addition & 1 deletion build/compile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ const KOISHI_VERSION = JSON.stringify(version)
entryPoints.push(base + '/src/worker.ts')
} else if (name === 'koishi-test-utils') {
await tasks[chai]
} else if (name === 'plugin-webui') {
} else if (name === 'plugin-status') {
entryPoints.splice(0, 1, base + '/server/index.ts')
}

Expand Down
4 changes: 2 additions & 2 deletions packages/adapter-discord/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "koishi-adapter-discord",
"description": "Discord adapter for Koishi",
"version": "1.0.2",
"version": "1.0.3",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
"files": [
Expand All @@ -28,7 +28,7 @@
"koishi"
],
"peerDependencies": {
"koishi-core": "^3.1.1"
"koishi-core": "^3.2.0"
},
"devDependencies": {
"@types/ws": "^7.4.0",
Expand Down
6 changes: 6 additions & 0 deletions packages/adapter-discord/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,12 @@ export interface Embed {
name?: string;
url?: string;
}

fields?: {
name: string
value: string
inline?: boolean
}[]
}

export interface Attachment {
Expand Down
1 change: 1 addition & 0 deletions packages/adapter-discord/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ export async function adaptMessage(bot: DiscordBot, meta: DC.DiscordMessage, ses
session.content += segment('video', { url: embed.video.url, proxy_url: embed.video.proxy_url })
}
}
session.content = meta.embeds.map(v => segment('embed', { data: JSON.stringify(v) })).join('') + session.content
return session
}

Expand Down
2 changes: 1 addition & 1 deletion packages/adapter-kaiheila/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"koishi"
],
"peerDependencies": {
"koishi-core": "^3.1.1"
"koishi-core": "^3.2.0"
},
"devDependencies": {
"koishi-test-utils": "^6.0.0-beta.10"
Expand Down
2 changes: 1 addition & 1 deletion 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.1.1"
"koishi-core": "^3.2.0"
},
"devDependencies": {
"@types/ws": "^7.4.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/adapter-telegram/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"koishi"
],
"peerDependencies": {
"koishi-core": "^3.1.1"
"koishi-core": "^3.2.0"
},
"devDependencies": {
"koishi-test-utils": "^6.0.0-beta.10"
Expand Down
2 changes: 1 addition & 1 deletion packages/adapter-tomon/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"koishi"
],
"peerDependencies": {
"koishi-core": "^3.1.1"
"koishi-core": "^3.2.0"
},
"devDependencies": {
"@types/pako": "^1.0.1",
Expand Down
2 changes: 1 addition & 1 deletion 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.1.1",
"version": "3.2.0",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
"engines": {
Expand Down
13 changes: 7 additions & 6 deletions packages/koishi-core/src/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,14 +203,15 @@ export class Context {
const state = this.app.registry.get(plugin)
if (!state) return
if (state.sideEffect) throw new Error('plugins with side effect cannot be disposed')
await Promise.all([
await Promise.allSettled([
...state.children.slice().map(plugin => this.dispose(plugin)),
...state.disposables.map(dispose => dispose()),
])
this.app.registry.delete(plugin)
const index = state.parent.children.indexOf(plugin)
if (index >= 0) state.parent.children.splice(index, 1)
this.emit('registry', this.app.registry)
]).finally(() => {
this.app.registry.delete(plugin)
const index = state.parent.children.indexOf(plugin)
if (index >= 0) state.parent.children.splice(index, 1)
this.emit('registry', this.app.registry)
})
}

async parallel<K extends EventName>(name: K, ...args: Parameters<EventMap[K]>): Promise<Await<ReturnType<EventMap[K]>>[]>
Expand Down
2 changes: 1 addition & 1 deletion packages/koishi-core/src/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ export interface Database {
}

type Methods<S, T> = {
[K in keyof S]?: S[K] extends (...args: infer R) => infer S ? (this: T, ...args: R) => S : never
[K in keyof S]?: S[K] extends (...args: infer R) => infer U ? (this: T, ...args: R) => U : S[K]
}

export namespace Database {
Expand Down
2 changes: 2 additions & 0 deletions packages/koishi-core/src/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ export class Session<
readonly sid: string
uid: string
cid: string
gid: string

id?: string
argv?: Argv<U, G>
Expand All @@ -119,6 +120,7 @@ export class Session<
defineProperty(this, 'sid', `${this.platform}:${this.selfId}`)
defineProperty(this, 'uid', `${this.platform}:${this.userId}`)
defineProperty(this, 'cid', `${this.platform}:${this.channelId}`)
defineProperty(this, 'gid', `${this.platform}:${this.groupId}`)
defineProperty(this, 'bot', app.bots[this.sid])
defineProperty(this, 'id', Random.uuid())
defineProperty(this, '_queued', Promise.resolve())
Expand Down
2 changes: 1 addition & 1 deletion packages/koishi-test-utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"dependencies": {
"chai": "^4.3.3",
"chai-as-promised": "^7.1.1",
"koishi-core": "^3.1.1",
"koishi-core": "^3.2.0",
"koishi-utils": "^4.0.1"
},
"devDependencies": {
Expand Down
18 changes: 7 additions & 11 deletions packages/koishi/ecosystem.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"koishi-adapter-discord": {
"version": "1.0.2",
"version": "1.0.3",
"description": "Discord adapter for Koishi"
},
"koishi-adapter-kaiheila": {
Expand All @@ -20,15 +20,15 @@
"description": "Tomon adapter for Koishi"
},
"koishi-plugin-adventure": {
"version": "0.1.14",
"version": "0.1.15",
"description": "Adventure Game for Koishi"
},
"koishi-plugin-chess": {
"version": "3.0.0-beta.11",
"version": "3.0.0",
"description": "Chess Plugin for Koishi"
},
"koishi-plugin-common": {
"version": "4.1.1",
"version": "4.1.2",
"description": "Common plugins for Koishi"
},
"koishi-plugin-dice": {
Expand All @@ -44,7 +44,7 @@
"description": "GitHub webhook plugin for Koishi"
},
"koishi-plugin-image-search": {
"version": "3.0.0",
"version": "3.0.1",
"description": "Image searching plugin for Koishi"
},
"koishi-plugin-mongo": {
Expand All @@ -71,19 +71,15 @@
"description": "Schedule plugin for Koishi"
},
"koishi-plugin-status": {
"version": "3.0.1",
"version": "4.0.0-alpha.0",
"description": "Show Status of Koishi"
},
"koishi-plugin-teach": {
"version": "2.0.0",
"description": "Teach plugin for Koishi"
},
"koishi-plugin-tools": {
"version": "2.0.0",
"version": "2.1.0",
"description": "Some simple tools for Koishi"
},
"koishi-plugin-webui": {
"version": "0.1.3",
"description": "Web UI for Koishi"
}
}
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": "3.1.1",
"version": "3.2.0",
"main": "index.js",
"typings": "index.d.ts",
"engines": {
Expand Down Expand Up @@ -38,7 +38,7 @@
"cac": "^6.7.2",
"chokidar": "^3.5.1",
"kleur": "^4.1.4",
"koishi-core": "^3.1.1",
"koishi-core": "^3.2.0",
"koishi-utils": "^4.0.1",
"prompts": "^2.4.0"
}
Expand Down
6 changes: 3 additions & 3 deletions packages/plugin-adventure/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "koishi-plugin-adventure",
"version": "0.1.14",
"version": "0.1.15",
"description": "Adventure Game for Koishi",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
Expand Down Expand Up @@ -28,8 +28,8 @@
"adventure"
],
"peerDependencies": {
"koishi-core": "^3.1.1",
"koishi-plugin-common": "^4.1.1",
"koishi-core": "^3.2.0",
"koishi-plugin-common": "^4.1.2",
"koishi-plugin-mysql": "^3.0.0",
"koishi-plugin-teach": "^2.0.0",
"koishi-utils": "^4.0.1"
Expand Down
8 changes: 4 additions & 4 deletions packages/plugin-adventure/src/affinity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,13 @@ export namespace Affinity {
}
for (const field of fields || []) {
Affinity.fields.add(field)
// profile also needs affinity data
Profile.fields.add(field)
}
}

Profile.add(user => `好感度:${Affinity.get(user)}`, [], 20)

export function hint<T extends User.Field = never>(callback: HintCallback<T>, fields: Iterable<T> = []) {
hintList.push(callback)
for (const field of fields) {
Expand All @@ -59,10 +63,6 @@ export namespace Affinity {
}

export function apply(ctx: Context) {
ctx.before('connect', () => {
Profile.add(user => `好感度:${Affinity.get(user)}`, fields, 20)
})

ctx.command('adventure/affinity', '查看好感度', { maxUsage: 100, usageName: 'show' })
.alias('aff')
.userFields(fields)
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-adventure/src/item.ts
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ namespace Item {
await session.send(hints.join('\n'))
})

ctx.command('adventure/before-sell [item] [count]', '售出物品', { maxUsage: 100 })
ctx.command('adventure/sell [item] [count]', '售出物品', { maxUsage: 100 })
.checkTimer('$system')
.checkTimer('$shop')
.userFields(['id', 'authority', 'warehouse', 'money', 'wealth', 'achievement', 'timers', 'progress', 'name', 'usage', 'gains'])
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-adventure/src/rank.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ namespace Rank {
return Rank.show(rank, session, options)
})

ctx.on('before-parse', (message, session) => {
ctx.before('parse', (message, session) => {
if (session.quote || session.parsed.prefix) return
const capture = /^(|)?(.+)(|)?[]?$/.exec(message)
if (!capture) return
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": "3.0.0-beta.11",
"version": "3.0.0",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
"files": [
Expand Down Expand Up @@ -29,7 +29,7 @@
"game"
],
"peerDependencies": {
"koishi-core": "^3.1.1",
"koishi-core": "^3.2.0",
"koishi-plugin-puppeteer": "^2.0.0",
"koishi-utils": "^4.0.1"
}
Expand Down
6 changes: 4 additions & 2 deletions packages/plugin-chess/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,10 @@ export function apply(ctx: Context) {
channel.chess = null
break
case undefined:
state.next = userId === state.p1 ? state.p2 : state.p1
message += `下一手轮到 ${segment.at(state.next)}。`
// eslint-disable-next-line no-cond-assign
if (state.next = userId === state.p1 ? state.p2 : state.p1) {
message += `下一手轮到 ${segment.at(state.next)}。`
}
break
default:
state.next = userId
Expand Down
4 changes: 2 additions & 2 deletions packages/plugin-common/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "koishi-plugin-common",
"description": "Common plugins for Koishi",
"version": "4.1.1",
"version": "4.1.2",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
"files": [
Expand Down Expand Up @@ -30,7 +30,7 @@
"plugin"
],
"peerDependencies": {
"koishi-core": "^3.1.1",
"koishi-core": "^3.2.0",
"koishi-utils": "^4.0.1"
},
"devDependencies": {
Expand Down
Loading

0 comments on commit c3885b1

Please sign in to comment.