Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
shigma committed Feb 9, 2020
2 parents e4f4db4 + 5443b83 commit a9c6952
Show file tree
Hide file tree
Showing 25 changed files with 182 additions and 113 deletions.
4 changes: 2 additions & 2 deletions build/publish.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { PackageJson, getWorkspaces, spawnAsync, spawnSync } from './utils'
import { gt, prerelease } from 'semver'
import ora from 'ora'
import { Octokit } from '@octokit/rest'
import latest from 'latest-version'
import Octokit from '@octokit/rest'
import ora from 'ora'

const { CI, GITHUB_EVENT_NAME, GITHUB_REF, GITHUB_TOKEN } = process.env

Expand Down
20 changes: 10 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,21 @@
"version": "1.0.0",
"license": "MIT",
"devDependencies": {
"@octokit/rest": "^16.40.1",
"@octokit/rest": "^16.43.1",
"@types/cross-spawn": "^6.0.1",
"@types/fs-extra": "^8.0.1",
"@types/jest": "^25.1.1",
"@types/node": "^13.5.2",
"@types/jest": "^25.1.2",
"@types/node": "^13.7.0",
"@types/semver": "^7.1.0",
"@typescript-eslint/eslint-plugin": "^2.18.0",
"@typescript-eslint/parser": "^2.18.0",
"@typescript-eslint/eslint-plugin": "^2.19.0",
"@typescript-eslint/parser": "^2.19.0",
"cac": "^6.5.6",
"cross-spawn": "^7.0.1",
"del": "^5.1.0",
"eslint": "^6.8.0",
"eslint-config-standard": "^14.1.0",
"eslint-plugin-import": "^2.20.0",
"eslint-plugin-jest": "^23.6.0",
"eslint-plugin-import": "^2.20.1",
"eslint-plugin-jest": "^23.7.0",
"eslint-plugin-node": "^11.0.0",
"eslint-plugin-promise": "^4.2.1",
"eslint-plugin-standard": "^4.0.1",
Expand All @@ -47,12 +47,12 @@
"jest": "^25.1.0",
"kleur": "^3.0.3",
"latest-version": "^5.1.0",
"open": "^7.0.1",
"open": "^7.0.2",
"ora": "^4.0.3",
"p-map": "^3.0.0",
"prompts": "^2.3.0",
"semver": "^7.1.1",
"ts-jest": "^25.1.0",
"semver": "^7.1.2",
"ts-jest": "^25.2.0",
"ts-node": "^8.6.2",
"typescript": "^3.7.5"
}
Expand Down
8 changes: 4 additions & 4 deletions packages/database-level/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "koishi-database-level",
"description": "Leveldb support for Koishi",
"version": "1.1.0",
"version": "1.1.1",
"main": "dist/index.js",
"files": [
"dist"
Expand Down Expand Up @@ -33,15 +33,15 @@
"leveldb"
],
"devDependencies": {
"koishi-test-utils": "^3.0.1"
"koishi-test-utils": "^3.1.0"
},
"peerDependencies": {
"koishi-core": "^1.8.0"
"koishi-core": "^1.8.1"
},
"dependencies": {
"@types/leveldown": "^4.0.2",
"@types/levelup": "^4.3.0",
"koishi-utils": "^1.0.2",
"koishi-utils": "^1.0.3",
"leveldown": "^5.4.1",
"levelup": "^4.3.2",
"subleveldown": "^4.1.4"
Expand Down
6 changes: 3 additions & 3 deletions packages/database-memory/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "koishi-database-memory",
"description": "An in-memory database implementation for Koishi",
"version": "1.1.0",
"version": "1.1.1",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
"files": [
Expand All @@ -22,9 +22,9 @@
},
"homepage": "https://github.com/koishijs/koishi/tree/master/packages/database-memory#readme",
"peerDependencies": {
"koishi-core": "^1.8.0"
"koishi-core": "^1.8.1"
},
"dependencies": {
"koishi-utils": "^1.0.2"
"koishi-utils": "^1.0.3"
}
}
6 changes: 3 additions & 3 deletions packages/database-mysql/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "koishi-database-mysql",
"description": "MySQL support for Koishi",
"version": "1.1.0",
"version": "1.1.1",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
"files": [
Expand Down Expand Up @@ -35,10 +35,10 @@
"@types/mysql": "^2.15.8"
},
"peerDependencies": {
"koishi-core": "^1.8.0"
"koishi-core": "^1.8.1"
},
"dependencies": {
"koishi-utils": "^1.0.2",
"koishi-utils": "^1.0.3",
"mysql": "^2.18.1"
}
}
8 changes: 4 additions & 4 deletions packages/database-sqlite/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "koishi-database-sqlite",
"version": "1.0.0-alpha.6",
"version": "1.0.0-alpha.7",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
"files": [
Expand All @@ -22,13 +22,13 @@
"homepage": "https://github.com/koishijs/koishi/tree/master/packages/database-sqlite#readme",
"devDependencies": {
"@types/sqlite3": "^3.1.6",
"koishi-test-utils": "^3.0.1"
"koishi-test-utils": "^3.1.0"
},
"peerDependencies": {
"koishi-core": "^1.8.0"
"koishi-core": "^1.8.1"
},
"dependencies": {
"koishi-utils": "^1.0.2",
"koishi-utils": "^1.0.3",
"sqlite3": "^4.1.1"
}
}
10 changes: 5 additions & 5 deletions packages/koishi-cli/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": "1.8.0",
"version": "1.8.1",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
"files": [
Expand Down Expand Up @@ -38,10 +38,10 @@
"cac": "^6.5.6",
"js-yaml": "^3.13.1",
"kleur": "^3.0.3",
"koishi-core": "^1.8.0",
"koishi-plugin-common": "^2.1.1",
"koishi-plugin-schedule": "^1.0.6",
"koishi-utils": "^1.0.2",
"koishi-core": "^1.8.1",
"koishi-plugin-common": "^2.1.2",
"koishi-plugin-schedule": "^1.0.7",
"koishi-utils": "^1.0.3",
"prompts": "^2.3.0"
}
}
8 changes: 4 additions & 4 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": "1.8.0",
"version": "1.8.1",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
"files": [
Expand Down Expand Up @@ -35,14 +35,14 @@
"@types/debug": "^4.1.5",
"@types/ws": "^7.2.1",
"get-port": "^5.1.1",
"koishi-database-memory": "^1.1.0",
"koishi-test-utils": "^3.0.1"
"koishi-database-memory": "^1.1.1",
"koishi-test-utils": "^3.1.0"
},
"dependencies": {
"axios": "^0.19.2",
"debug": "^4.1.1",
"escape-string-regexp": "^2.0.0",
"koishi-utils": "^1.0.2",
"koishi-utils": "^1.0.3",
"leven": "^3.1.0",
"ws": "^7.2.1"
}
Expand Down
54 changes: 32 additions & 22 deletions packages/koishi-core/src/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export interface CommandConfig {
maxUsage?: UserType<number>
maxUsageText?: string
minInterval?: UserType<number>
showWarning?: boolean
showWarning?: boolean | number
noHelpOption?: boolean
}

Expand All @@ -64,6 +64,16 @@ export interface ShortcutConfig {
options?: Record<string, any>
}

export enum CommandHint {
USAGE_EXHAUSTED = 1,
TOO_FREQUENT = 2,
LOW_AUTHORITY = 4,
INSUFFICIENT_ARGUMENTS = 8,
REDUNANT_ARGUMENTS = 16,
UNKNOWN_OPTIONS = 32,
REQUIRED_OPTIONS = 64,
}

export class Command {
config: CommandConfig
children: Command[] = []
Expand Down Expand Up @@ -247,17 +257,17 @@ export class Command {
if (this.config.checkArgCount) {
const nextArg = this._argsDef[args.length]
if (nextArg?.required) {
return meta.$send(messages.INSUFFICIENT_ARGUMENTS)
return this._sendHint(CommandHint.INSUFFICIENT_ARGUMENTS, meta)
}
const finalArg = this._argsDef[this._argsDef.length - 1]
if (args.length > this._argsDef.length && !finalArg.noSegment && !finalArg.variadic) {
return meta.$send(messages.REDUNANT_ARGUMENTS)
return this._sendHint(CommandHint.REDUNANT_ARGUMENTS, meta)
}
}

// check unknown options
if (this.config.checkUnknown && unknown.length) {
return meta.$send(format(messages.UNKNOWN_OPTIONS, unknown.join(', ')))
return this._sendHint(CommandHint.UNKNOWN_OPTIONS, meta, unknown.join(', '))
}

// check required options
Expand All @@ -266,12 +276,13 @@ export class Command {
return option.required && !(option.longest in options)
})
if (absent) {
return meta.$send(format(messages.REQUIRED_OPTIONS, absent.rawName))
return this._sendHint(CommandHint.REQUIRED_OPTIONS, meta, absent.rawName)
}
}

// check authority and usage
if (!await this._checkUser(meta, options)) return
const code = this._checkUser(meta, options)
if (code) return this._sendHint(code, meta)

// execute command
this.context.logger('command').debug('execute %s', this.name)
Expand All @@ -292,23 +303,30 @@ export class Command {
}
}

private _sendHint (code: CommandHint, meta: Meta<'message'>, ...param: any[]) {
let { showWarning } = this.config
if (typeof showWarning === 'boolean') {
showWarning = -showWarning
}
if (showWarning & code) {
return meta.$send(format(messages[CommandHint[code]], ...param))
}
}

/** check authority and usage */
private async _checkUser (meta: Meta<'message'>, options: Record<string, any>) {
private _checkUser (meta: Meta<'message'>, options: Record<string, any>) {
const user = meta.$user
if (!user) return true
if (!user) return
let isUsage = true

// check authority
if (this.config.authority > user.authority) {
return meta.$send(messages.LOW_AUTHORITY)
return CommandHint.LOW_AUTHORITY
}
for (const option of this._options) {
if (option.camels[0] in options) {
if (option.authority > user.authority) {
if (this.config.showWarning) {
await meta.$send(messages.LOW_AUTHORITY)
}
return
return CommandHint.LOW_AUTHORITY
}
if (option.notUsage) isUsage = false
}
Expand All @@ -320,17 +338,9 @@ export class Command {
const maxUsage = this.getConfig('maxUsage', meta)

if (maxUsage < Infinity || minInterval > 0) {
const message = updateUsage(this.usageName, user, maxUsage, minInterval)
if (message) {
if (this.config.showWarning) {
await meta.$send(message)
}
return
}
return updateUsage(this.usageName, user, { maxUsage, minInterval })
}
}

return true
}

end () {
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 @@ -15,7 +15,7 @@ export interface UserData {
id: number
flag: number
authority: number
usage: Record<string, Usage> & { _date?: number }
usage: Record<string, Usage> & { $date?: number }
}

export type User<K extends UserField = UserField> = Observed<Pick<UserData, K | 'id'>>
Expand Down
Loading

0 comments on commit a9c6952

Please sign in to comment.