fix: --noise should only works for nai

This commit is contained in:
Shigma 2022-12-06 00:15:38 +08:00
parent 1e34334767
commit e9b28f35fb
3 changed files with 14 additions and 8 deletions

View File

@ -1,7 +1,7 @@
{
"name": "koishi-plugin-novelai",
"description": "Generate images by diffusion models",
"version": "1.15.4",
"version": "1.15.5",
"main": "lib/index.js",
"typings": "lib/index.d.ts",
"files": [

View File

@ -178,11 +178,6 @@ export const Config = Schema.intersect([
'referer': 'https://novelai.net/',
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.0.0 Safari/537.36',
}),
allowAnlas: Schema.union([
Schema.const(true).description('允许'),
Schema.const(false).description('禁止'),
Schema.natural().description('权限等级').default(1),
]).default(true).description('是否启用高级功能 (例如图片增强和手动设置某些参数)。'),
}),
]),
Schema.object({
@ -239,6 +234,11 @@ export const Config = Schema.intersect([
Schema.const('default').description('发送图片和关键信息'),
Schema.const('verbose').description('发送全部信息'),
]).description('输出方式。').default('default'),
allowAnlas: Schema.union([
Schema.const(true).description('允许'),
Schema.const(false).description('禁止'),
Schema.natural().description('权限等级').default(1),
]).default(true).description('是否启用高级功能 (例如图片增强和手动设置某些参数)。'),
maxIterations: Schema.natural().description('允许的最大绘制次数。').default(1),
maxRetryCount: Schema.natural().description('连接失败时最大的重试次数。').default(3),
requestTimeout: Schema.number().role('time').description('当请求超过这个时间时会中止并提示超时。').default(Time.minute),

View File

@ -52,9 +52,11 @@ export function apply(ctx: Context, config: Config) {
const getToken = () => tokenTask ||= login(ctx)
ctx.accept(['token', 'type', 'email', 'password'], () => tokenTask = null)
type HiddenCallback = (session: Session<'authority'>) => boolean
const thirdParty = () => !['login', 'token'].includes(config.type)
const restricted = (session: Session<'authority'>) => {
const restricted: HiddenCallback = (session) => {
if (typeof config.allowAnlas === 'boolean') {
return !config.allowAnlas
} else {
@ -62,6 +64,10 @@ export function apply(ctx: Context, config: Config) {
}
}
const some = (...args: HiddenCallback[]): HiddenCallback => (session) => {
return args.some(callback => callback(session))
}
const step = (source: string) => {
const value = +source
if (value * 0 === 0 && Math.floor(value) === value && value > 0 && value <= (config.maxSteps || Infinity)) return value
@ -98,7 +104,7 @@ export function apply(ctx: Context, config: Config) {
.option('seed', '-x <seed:number>')
.option('steps', '-t <step>', { type: step, hidden: restricted })
.option('scale', '-c <scale:number>')
.option('noise', '-n <noise:number>', { hidden: restricted })
.option('noise', '-n <noise:number>', { hidden: some(restricted, thirdParty) })
.option('strength', '-N <strength:number>', { hidden: restricted })
.option('undesired', '-u <undesired>')
.option('noTranslator', '-T', { hidden: () => !ctx.translator || !config.translator })