Repository: koishijs/novelai-bot
File: src/index.ts (TypeScript)

Code before:
        result.children.push(segment('message', attrs, `prompt = ${prompt}`))
        if (config.output === 'verbose') {
          result.children.push(segment('message', attrs, `undesired = ${uc}`))
        }
        result.children.push(segment('message', attrs, segment.image('base64://' + base64)))
        return result
      }

      const ids = await session.send(getContent())

      if (config.recallTimeout) {
        ctx.setTimeout(() => {
          for (const id of ids) {
            session.bot.deleteMessage(session.channelId, id)
          }
        }, config.recallTimeout)
      }
    })

  ctx.accept(['model', 'orient', 'sampler'], (config) => {
    cmd._options.model.fallback = config.model
    cmd._options.sampler.fallback = config.sampler
    cmd._options.sampler.type = Object.keys(config.type === 'sd-webui' ? sampler.sd : sampler.nai)
  }, { immediate: true })

  if (config.type === 'sd-webui' && config.enableUpscale) {
    const subcmd = cmd
      .subcommand('.upscale')
      .shortcut('放大', { fuzzy: true })
      .option('scale', '-s <scale:number>', { fallback: 2 })
      .option('resolution', '-r <resolution>', { type: resolution })
      .option('upscaler', '-u <upscaler>')
      .action(async ({ session, options }, input) => {
        let imgUrl: string
        segment.transform(input, {
          image(attrs) {
            imgUrl = attrs.url
            return ''
          },
        })

        if (!imgUrl) return session.text('.expect-image')
        let image: ImageData
        try {
          image = await download(ctx, imgUrl)
        } catch (err) {
          if (err instanceof NetworkError) {
            return session.text(err.message, err.params)
          }
          logger.error(err)
          return session.text('.download-error')

Review comment (suggestion):
change to
```
ctx.intersect(() => config.type === 'sd-webui')
  .command('novelai.upscale')
```

Code after:
        result.children.push(segment('message', attrs, `prompt = ${prompt}`))
        if (config.output === 'verbose') {
          result.children.push(segment('message', attrs, `undesired = ${uc}`))
        }
        result.children.push(segment('message', attrs, segment.image('base64://' + base64)))
        return result
      }

      const ids = await session.send(getContent())

      if (config.recallTimeout) {
        ctx.setTimeout(() => {
          for (const id of ids) {
            session.bot.deleteMessage(session.channelId, id)
          }
        }, config.recallTimeout)
      }
    })

  ctx.accept(['model', 'orient', 'sampler'], (config) => {
    cmd._options.model.fallback = config.model
    cmd._options.sampler.fallback = config.sampler
    cmd._options.sampler.type = Object.keys(config.type === 'sd-webui' ? sampler.sd : sampler.nai)
  }, { immediate: true })

  const subcmd = ctx.intersect(() => config.type === 'sd-webui')
    .command('novelai.upscale')
    .shortcut('放大', { fuzzy: true })
    .option('scale', '-s <scale:number>', { fallback: 2 })
    .option('resolution', '-r <resolution>', { type: resolution })
    .option('crop', '-C, --no-crop', { value: false, fallback: true })
    .option('upscaler', '-1 <upscaler>', { type: upscalers })
    .option('upscaler2', '-2 <upscaler2>', { type: upscalers })
    .option('visibility', '-v <visibility:number>')
    .option('upscaleFirst', '-f', { fallback: false })
    .action(async ({ session, options }, input) => {
      let imgUrl: string
      segment.transform(input, {
        image(attrs) {
          imgUrl = attrs.url
          return ''
        },
      })

      if (!imgUrl) return session.text('.expect-image')
      let image: ImageData
      try {
        image = await download(ctx, imgUrl)
      } catch (err) {
        if (err instanceof NetworkError) {
          return session.text(err.message, err.params)