koishi-core
Advanced tools
Comparing version 1.11.0 to 1.11.1
@@ -76,4 +76,6 @@ import { Server, ServerType } from './server'; | ||
parseCommandLine(message: string, meta: Meta<'message'>): ParsedCommandLine; | ||
executeCommandLine(message: string, meta: Meta<'message'>, next?: NextFunction): any; | ||
private _attachGroup; | ||
private _attachUser; | ||
executeCommandLine(message: string, meta: Meta<'message'>, next?: NextFunction): Promise<any>; | ||
private _applyMiddlewares; | ||
} |
@@ -106,2 +106,3 @@ "use strict"; | ||
Object.defineProperty(meta, '$parsed', { | ||
writable: true, | ||
value: { atMe, nickname, prefix, message }, | ||
@@ -112,3 +113,3 @@ }); | ||
Object.defineProperty(meta, '$argv', { | ||
configurable: true, | ||
writable: true, | ||
value: this.parseCommandLine(message, meta), | ||
@@ -135,3 +136,3 @@ }); | ||
Object.defineProperty(meta, '$argv', { | ||
configurable: true, | ||
writable: true, | ||
value: { meta, command, ...result }, | ||
@@ -145,3 +146,3 @@ }); | ||
Object.defineProperty(meta, '$argv', { | ||
configurable: true, | ||
writable: true, | ||
value: { meta }, | ||
@@ -154,6 +155,3 @@ }); | ||
// attach group data | ||
const groupFields = new Set(['flag', 'assignee']); | ||
this.emitEvent(meta, 'before-group', groupFields, meta.$argv); | ||
const group = await this.database.observeGroup(meta.groupId, Array.from(groupFields)); | ||
Object.defineProperty(meta, '$group', { value: group, writable: true }); | ||
const group = await this._attachGroup(meta, ['flag', 'assignee']); | ||
// emit attach event | ||
@@ -173,9 +171,3 @@ this.emitEvent(meta, 'attach-group', meta); | ||
// attach user data | ||
const userFields = new Set(['flag']); | ||
this.emitEvent(meta, 'before-user', userFields, meta.$argv); | ||
const defaultAuthority = typeof this.options.defaultAuthority === 'function' | ||
? this.options.defaultAuthority(meta) | ||
: this.options.defaultAuthority || 0; | ||
const user = await this.database.observeUser(meta.userId, defaultAuthority, Array.from(userFields)); | ||
Object.defineProperty(meta, '$user', { value: user, writable: true }); | ||
const user = await this._attachUser(meta, ['flag']); | ||
// emit attach event | ||
@@ -432,12 +424,40 @@ this.emitEvent(meta, 'attach', meta); | ||
} | ||
executeCommandLine(message, meta, next = koishi_utils_1.noop) { | ||
async _attachGroup(meta, fields = []) { | ||
const groupFields = new Set(fields); | ||
this.emitEvent(meta, 'before-group', groupFields, meta.$argv); | ||
const group = await this.database.observeGroup(meta.groupId, Array.from(groupFields)); | ||
Object.defineProperty(meta, '$group', { value: group, writable: true }); | ||
return group; | ||
} | ||
async _attachUser(meta, fields = []) { | ||
const userFields = new Set(fields); | ||
this.emitEvent(meta, 'before-user', userFields, meta.$argv); | ||
const defaultAuthority = typeof this.options.defaultAuthority === 'function' | ||
? this.options.defaultAuthority(meta) | ||
: this.options.defaultAuthority || 0; | ||
const user = await this.database.observeUser(meta.userId, defaultAuthority, Array.from(userFields)); | ||
Object.defineProperty(meta, '$user', { value: user, writable: true }); | ||
return user; | ||
} | ||
async executeCommandLine(message, meta, next = koishi_utils_1.noop) { | ||
if (!('$ctxType' in meta)) | ||
this.server.parseMeta(meta); | ||
const argv = this.parseCommandLine(message, meta); | ||
if (argv && !argv.command.getConfig('disable', meta)) { | ||
return argv.command.execute(argv, next); | ||
if (!argv) | ||
return next(); | ||
Object.defineProperty(meta, '$argv', { | ||
writable: true, | ||
value: argv, | ||
}); | ||
if (this.database) { | ||
if (meta.messageType === 'group') { | ||
await this._attachGroup(meta); | ||
} | ||
await this._attachUser(meta); | ||
} | ||
return next(); | ||
if (argv.command.getConfig('disable', meta)) | ||
return next(); | ||
return argv.command.execute(argv, next); | ||
} | ||
} | ||
exports.App = App; |
@@ -123,3 +123,3 @@ "use strict"; | ||
const subdatabase = this.database[sub]; | ||
if (!this.explicitTables[table] && this.implicitTables[table]) { | ||
if (!this.explicitTables[table] && this.implicitTables[table] && this.implicitTables[table] !== sub) { | ||
throw new Error(`database "${this.implicitTables[table]}" and "${sub}" conflict on table "${table}"`); | ||
@@ -126,0 +126,0 @@ } |
{ | ||
"name": "koishi-core", | ||
"description": "Core features for Koishi", | ||
"version": "1.11.0", | ||
"version": "1.11.1", | ||
"main": "dist/index.js", | ||
@@ -38,4 +38,4 @@ "typings": "dist/index.d.ts", | ||
"get-port": "^5.1.1", | ||
"koishi-database-memory": "^1.1.5", | ||
"koishi-test-utils": "^3.1.4" | ||
"koishi-database-memory": "^1.1.6", | ||
"koishi-test-utils": "^3.2.1" | ||
}, | ||
@@ -42,0 +42,0 @@ "dependencies": { |
127279
3122