Skip to content

Commit

Permalink
feat(eval): authority settings (#110)
Browse files Browse the repository at this point in the history
  • Loading branch information
undefined-moe authored Oct 14, 2020
1 parent 9b7f3eb commit ed03ed1
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
5 changes: 3 additions & 2 deletions packages/plugin-eval/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ declare module 'koishi-core/dist/session' {

const defaultConfig: EvalConfig = {
prefix: '>',
authority: 2,
timeout: 1000,
setupFiles: {},
maxLogs: Infinity,
Expand All @@ -38,7 +39,7 @@ const logger = new Logger('eval')
export const name = 'eval'

export function apply(ctx: Context, config: Config = {}) {
const { prefix } = config = { ...defaultConfig, ...config }
const { prefix, authority } = config = { ...defaultConfig, ...config }
const { app } = ctx
const worker = new EvalWorker(app, config)
defineProperty(app, 'worker', worker)
Expand All @@ -59,7 +60,7 @@ export function apply(ctx: Context, config: Config = {}) {
.option('slient', '-s 不输出最后的结果')
.option('restart', '-r 重启子线程', { authority: 3 })
.before((session) => {
if (!session['_redirected'] && session.$user?.authority < 2) return '权限不足。'
if (!session['_redirected'] && session.$user?.authority < authority) return '权限不足。'
})

attachTraps(cmd, config, async ({ session, options, ctxOptions }, expr) => {
Expand Down
1 change: 1 addition & 0 deletions packages/plugin-eval/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const logger = new Logger('eval')

export interface MainConfig extends FieldOptions {
prefix?: string
authority?: number
timeout?: number
maxLogs?: number
resourceLimits?: ResourceLimits
Expand Down

0 comments on commit ed03ed1

Please sign in to comment.