Skip to content

Commit

Permalink
refa: migrate schema text to i18n files (#244)
Browse files Browse the repository at this point in the history
* refa: migrate base schema text to i18n files

* refa: migrate danbooru schema to i18n

* refa: migrate e621 schema to i18n

* refa: migrate gelbooru schema to i18n

* refa: migrate konachan schema to i18n

* refa: migrate local schema to i18n

* refa: migrate lolibooru schema to i18n

* refa: migrate lolicon schema to i18n

* refa: migrate moehu schema to i18n

* refa: migrate pixiv schema to i18n

* refa: migrate safebooru schema to i18n

* refa: migrate sankakucomplex schema to i18n

* refa: migrate yandere schema to i18n

* fix: format
  • Loading branch information
MaikoTan authored Aug 14, 2024
1 parent 6a93dcf commit a4daebc
Show file tree
Hide file tree
Showing 29 changed files with 321 additions and 181 deletions.
4 changes: 4 additions & 0 deletions crowdin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ pull_request_labels:
files:
- source: /packages/*/src/locales/zh-CN.yml
translation: /%original_path%/%locale%.yml
- source: /packages/*/src/locales/zh-CN.schema.yml
translation: /%original_path%/%locale%.schema.yml
- source: /packages/*/src/locales/zh-CN.source.schema.yml
translation: /%original_path%/%locale%.source.schema.yml
- source: /docs/zh-CN/**/*.md
translation: /docs/%locale%/**/%file_name%.md
- source: /docs/**/zh-CN.json
Expand Down
70 changes: 27 additions & 43 deletions packages/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,63 +214,47 @@ export const Config = Schema.intersect([
Schema.intersect([
Schema.union([
Schema.object({
detectLanguage: Schema.boolean().default(false).description('自动检测输入语言并选择语言匹配的图源。'),
detectLanguage: Schema.boolean().default(false),
}),
Schema.object({
detectLanguage: Schema.const(true).description('自动检测输入语言并选择语言匹配的图源。'),
confidence: Schema.number().default(0.5).description('语言检测的置信度。'),
detectLanguage: Schema.const(true),
confidence: Schema.number().default(0.5),
}),
]),
Schema.object({
maxCount: Schema.number().default(10).description('每次搜索的最大数量。'),
nsfw: Schema.boolean().default(false).description('是否允许输出 NSFW 内容。'),
maxCount: Schema.number().default(10),
nsfw: Schema.boolean().default(false),
}),
]).description('搜索设置'),
]),
Schema.object({
output: Schema.union([
Schema.const(0).description('仅发送图片'),
Schema.const(1).description('发送图片和相关信息'),
Schema.const(2).description('发送图片、相关信息和链接'),
Schema.const(3).description('发送全部信息'),
])
.description('输出方式。')
.default(1),
output: Schema.union([Schema.const(0), Schema.const(1), Schema.const(2), Schema.const(3)]).default(1),
outputMethod: Schema.union([
Schema.const('one-by-one').description('逐条发送每张图片'),
Schema.const('merge-multiple').description('合并多条发送 (部分平台可能不支持)'),
Schema.const('forward-all').description('合并为子话题发送所有图片 (部分平台需求较高权限)'),
Schema.const('forward-multiple').description('仅当多于一张图片使用合并为子话题发送 (部分平台需求较高权限)'),
Schema.const('one-by-one'),
Schema.const('merge-multiple'),
Schema.const('forward-all'),
Schema.const('forward-multiple'),
])
.experimental()
.role('radio')
.default('merge-multiple')
.description('发送方式。'),
.default('merge-multiple'),
preferSize: Schema.union([
Schema.const('original').description('原始尺寸'),
Schema.const('large').description('较大尺寸 (通常为约 1200px)'),
Schema.const('medium').description('中等尺寸 (通常为约 600px)'),
Schema.const('small').description('较小尺寸 (通常为约 300px)'),
Schema.const('thumbnail').description('缩略图'),
])
.description('优先使用图片的最大尺寸。')
.default('large'),
autoResize: Schema.computed(Schema.boolean())
.experimental()
.default(false)
.description('根据 preferSize 自动缩小过大的图片。<br/> - 需要安装提供 canvas 服务的插件'),
asset: Schema.boolean().default(false).description('优先使用 [assets服务](https://assets.koishi.chat/) 转存图片。'),
base64: Schema.boolean().default(false).description('使用 base64 发送图片。'),
spoiler: Schema.union([
Schema.const(0).description('禁用'),
Schema.const(1).description('所有图片'),
Schema.const(2).description('仅 NSFW 图片'),
])
.description('发送为隐藏图片,单击后显示(在 QQ 平台中以「合并转发」发送)。')
Schema.const('original'),
Schema.const('large'),
Schema.const('medium'),
Schema.const('small'),
Schema.const('thumbnail'),
]).default('large'),
autoResize: Schema.computed(Schema.boolean()).experimental().default(false),
asset: Schema.boolean().default(false),
base64: Schema.boolean().default(false),
spoiler: Schema.union([Schema.const(0), Schema.const(1), Schema.const(2)])
.default(0)
.experimental(),
showTips: Schema.boolean().default(true).description('是否输出使用提示信息。'),
}).description('输出设置'),
])
showTips: Schema.boolean().default(true),
}),
]).i18n({
'zh-CN': require('./locales/zh-CN.schema'),
})

export function apply(ctx: Context, config: Config) {
// @ts-expect-error inject structure not compatible
Expand Down
41 changes: 41 additions & 0 deletions packages/core/src/locales/zh-CN.schema.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
$inner:
- $description: 搜索设置
detectLanguage: 自动检测输入语言并选择语言匹配的图源。
confidence: 语言检测的置信度。
maxCount: 每次搜索的最大数量。
nsfw: 是否允许输出 NSFW 内容。

- $description: 输出设置
output:
$description: 输出方式。
$inner:
- 仅发送图片
- 发送图片和相关信息
- 发送图片、相关信息和链接
- 发送全部信息
outputMethod:
$description: 发送方式。
$inner:
- 逐条发送每张图片
- 合并多条发送 (部分平台可能不支持)
- 合并为子话题发送所有图片 (部分平台需求较高权限)
- 仅当多于一张图片使用合并为子话题发送 (部分平台需求较高权限)
preferSize:
$description: 优先使用图片的最大尺寸。
$inner:
- 原始尺寸
- 较大尺寸 (通常为约 1200px)
- 中等尺寸 (通常为约 600px)
- 较小尺寸 (通常为约 300px)
- 缩略图
autoResize:
$description: 根据 preferSize 自动缩小过大的图片。 **需要安装提供 canvas 服务的插件**
asset: 优先使用 [assets服务](https://assets.koishi.chat/) 转存图片。
base64: 使用 base64 发送图片。
spoiler:
$description: 发送为隐藏图片,单击后显示(在 QQ 平台中以「合并转发」发送)。
$inner:
- 禁用
- 所有图片
- 仅 NSFW 图片
showTips: 是否输出使用提示信息。
7 changes: 7 additions & 0 deletions packages/core/src/locales/zh-CN.source.schema.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
$inner:
- $description: 全局设置
label: 图源标签,可用于在指令中手动指定图源。
weight: 图源权重。在多个符合标签的图源中,将按照各自的权重随机选择。

- $description: 请求设置
proxyAgent: 请求图片时使用代理服务器。
17 changes: 8 additions & 9 deletions packages/core/src/source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,15 @@ export namespace ImageSource {
export function createSchema(o: { label: string }) {
return Schema.intersect([
Schema.object({
label: Schema.string().default(o.label).description('图源标签,可用于在指令中手动指定图源。'),
weight: Schema.number()
.min(1)
.default(1)
.description('图源权重。在多个符合标签的图源中,将按照各自的权重随机选择。'),
}).description('全局设置'),
label: Schema.string().default(o.label),
weight: Schema.number().min(1).default(1),
}),
Schema.object({
proxyAgent: Schema.string().default(undefined).description('请求图片时使用代理服务器。'),
}).description('请求设置'),
])
proxyAgent: Schema.string().default(undefined),
}),
]).i18n({
'zh-CN': require('./locales/zh-CN.source.schema.yml'),
})
}

export const Config: Schema<Config> = createSchema({ label: 'default' })
Expand Down
16 changes: 7 additions & 9 deletions packages/danbooru/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,21 +53,19 @@ namespace DanbooruImageSource {
export const Config: Schema<Config> = Schema.intersect([
ImageSource.createSchema({ label: 'danbooru' }),
Schema.object({
endpoint: Schema.string().description('Danbooru 的 URL。').default('https://danbooru.donmai.us/'),
endpoint: Schema.string().default('https://danbooru.donmai.us/'),
/**
* @see https://danbooru.donmai.us/wiki_pages/help%3Aapi
*/
keyPairs: Schema.array(
Schema.object({
login: Schema.string().required().description('用户名。'),
apiKey: Schema.string().required().role('secret').description('API 密钥。'),
login: Schema.string().required(),
apiKey: Schema.string().required().role('secret'),
}),
)
.default([])
.description(
'Danbooru 的登录凭据。[点击前往获取及设置教程](https://booru.koishi.chat/zh-CN/plugins/danbooru.html#configure-credentials)',
),
}).description('搜索设置'),
).default([]),
}).i18n({
'zh-CN': require('./locales/zh-CN.schema'),
}),
])
}

Expand Down
7 changes: 7 additions & 0 deletions packages/danbooru/src/locales/zh-CN.schema.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
$description: 搜索设置
endpoint: Danbooru 的 URL。
keyPairs:
$description: Danbooru 的登录凭据。[点击前往获取及设置教程](https://booru.koishi.chat/zh-CN/plugins/danbooru.html#configure-credentials)
$inner:
login: 用户名。
apiKey: API 密钥。
18 changes: 8 additions & 10 deletions packages/e621/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,22 +68,20 @@ namespace e621ImageSource {
export const Config: Schema<Config> = Schema.intersect([
ImageSource.createSchema({ label: 'e621' }),
Schema.object({
endpoint: Schema.string().description('e621/e926 的 URL。').default('https://e621.net/'),
endpoint: Schema.string().default('https://e621.net/'),
keyPairs: Schema.array(
Schema.object({
login: Schema.string().required().description('e621/e926 的用户名。'),
apiKey: Schema.string().required().role('secret').description('e621/e926 的 API Key。'),
login: Schema.string().required(),
apiKey: Schema.string().required().role('secret'),
}),
)
.default([])
.description(
'e621/e926 的登录凭据。[点击前往获取及设置教程](https://booru.koishi.chat/zh-CN/plugins/e621.html#configure-credentials)',
),
userAgent: Schema.string().description('设置请求的 User Agent。').default(
).default([]),
userAgent: Schema.string().default(
// eslint-disable-next-line max-len
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36 Edg/114.0.1823.37',
),
}).description('搜索设置'),
}).i18n({
'zh-CN': require('./locales/zh-CN.schema'),
}),
])
}

Expand Down
8 changes: 8 additions & 0 deletions packages/e621/src/locales/zh-CN.schema.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
$description: 搜索设置
endpoint: e621/e926 的 URL。
keyPairs:
$description: e621/e926 的登录凭据。[点击前往获取及设置教程](https://booru.koishi.chat/zh-CN/plugins/e621.html#configure-credentials)
$inner:
login: e621/e926 的用户名。
apiKey: e621/e926 的 API Key。
userAgent: 设置请求的 User Agent。
12 changes: 5 additions & 7 deletions packages/gelbooru/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,11 @@ namespace GelbooruImageSource {
export const Config: Schema<Config> = Schema.intersect([
ImageSource.createSchema({ label: 'gelbooru' }),
Schema.object({
endpoint: Schema.string().description('Gelbooru 的 URL。').default('https://gelbooru.com/index.php'),
keyPairs: Schema.array(Schema.string().required().role('secret'))
.description(
'Gelbooru 的登录凭据。[点击前往获取及设置教程](https://booru.koishi.chat/zh-CN/plugins/gelbooru.html#configure-credentials)',
)
.default([]),
}).description('搜索设置'),
endpoint: Schema.string().default('https://gelbooru.com/index.php'),
keyPairs: Schema.array(Schema.string().required().role('secret')).default([]),
}).i18n({
'zh-CN': require('./locales/zh-CN.schema'),
}),
])
}

Expand Down
4 changes: 4 additions & 0 deletions packages/gelbooru/src/locales/zh-CN.schema.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
$description: 搜索设置
endpoint: Gelbooru 的 URL。
keyPairs:
$description: Gelbooru 的登录凭据。[点击前往获取及设置教程](https://booru.koishi.chat/zh-CN/plugins/gelbooru.html#configure-credentials)
21 changes: 9 additions & 12 deletions packages/konachan/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,21 +75,18 @@ namespace KonachanImageSource {
export const Config: Schema<Config> = Schema.intersect([
ImageSource.createSchema({ label: 'konachan' }),
Schema.object({
endpoint: Schema.union([
Schema.const('https://konachan.com/').description('Konachan.com (NSFW)'),
Schema.const('https://konachan.net/').description('Konachan.net (SFW)'),
])
.description('Konachan 的 URL。')
.default('https://konachan.com/'),
endpoint: Schema.union([Schema.const('https://konachan.com/'), Schema.const('https://konachan.net/')]).default(
'https://konachan.com/',
),
keyPairs: Schema.array(
Schema.object({
login: Schema.string().required().description('用户名'),
password: Schema.string().required().role('secret').description('密码'),
login: Schema.string().required(),
password: Schema.string().required().role('secret'),
}),
)
.default([])
.description('Konachan 的登录凭据。'),
}).description('搜索设置'),
).default([]),
}).i18n({
'zh-CN': require('./locales/zh-CN.schema'),
}),
])
}

Expand Down
11 changes: 11 additions & 0 deletions packages/konachan/src/locales/zh-CN.schema.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
$description: 搜索设置
endpoint:
$description: Konachan 的 URL。
$inner:
- Konachan.com (NSFW)
- Konachan.net (SFW)
keyPairs:
$description: Konachan 的登录凭据。
$inner:
login: 用户名
password: 密码
28 changes: 15 additions & 13 deletions packages/local/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,19 +184,21 @@ namespace LocalImageSource {

export const Config: Schema<Config> = Schema.intersect([
ImageSource.createSchema({ label: 'local' }),
Schema.object({
// TODO: Schema.path()?
endpoint: Schema.array(String).description('图源文件夹,支持多个不同的文件夹'),
storage: Schema.union<Mapping.Storage>(['file', 'database']).description('图源数据保存方式').default('file'),
reload: Schema.boolean().description('每次启动时重新构建图源数据').default(false),
languages: Schema.array(String).description('支持的语言').default(['zh-CN']),
}).description('图源设置'),
Schema.object({
scraper: Schema.string()
.description('文件名元信息生成格式,详见<a herf="https://booru.koishi.chat/plugins/local.html">文档</a>')
.default('{filename}-{tag}'),
extension: Schema.array(String).description('支持的扩展名').default(['.jpg', '.png', '.jpeg', '.gif']),
}).description('文件设置'),
Schema.intersect([
Schema.object({
// TODO: Schema.path()?
endpoint: Schema.array(String),
storage: Schema.union<Mapping.Storage>(['file', 'database']).default('file'),
reload: Schema.boolean().default(false),
languages: Schema.array(String).default(['zh-CN']),
}),
Schema.object({
scraper: Schema.string().default('{filename}-{tag}'),
extension: Schema.array(String).default(['.jpg', '.png', '.jpeg', '.gif']),
}),
]).i18n({
'zh-CN': require('./locales/zh-CN.schema'),
}),
])
}

Expand Down
11 changes: 11 additions & 0 deletions packages/local/src/locales/zh-CN.schema.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
$inner:
- $description: 图源设置
$inner:
endpoint: 图源文件夹,支持多个不同的文件夹
storage: 图源数据保存方式
reload: 每次启动时重新构建图源数据
languages: 支持的语言
- $description: 文件设置
$inner:
scraper: 文件名元信息生成格式,详见<a herf="https://booru.koishi.chat/plugins/local.html">文档</a>
extension: 支持的扩展名
14 changes: 7 additions & 7 deletions packages/lolibooru/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,16 +78,16 @@ namespace LolibooruImageSource {
export const Config: Schema<Config> = Schema.intersect([
ImageSource.createSchema({ label: 'lolibooru' }),
Schema.object({
endpoint: Schema.string().description('Lolibooru 的 URL。').default('https://lolibooru.moe'),
endpoint: Schema.string().default('https://lolibooru.moe'),
keyPairs: Schema.array(
Schema.object({
login: Schema.string().required().description('用户名'),
password: Schema.string().required().role('secret').description('密码'),
login: Schema.string().required(),
password: Schema.string().required().role('secret'),
}),
)
.default([])
.description('Lolibooru 的登录凭据。'),
}).description('搜索设置'),
).default([]),
}).i18n({
'zh-CN': require('./locales/zh-CN.schema'),
}),
])
}

Expand Down
7 changes: 7 additions & 0 deletions packages/lolibooru/src/locales/zh-CN.schema.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
$description: 搜索设置
endpoint: Lolibooru 的 URL。
keyPairs:
$description: Lolibooru 的登录凭据。
$inner:
login: 用户名
password: 密码
Loading

0 comments on commit a4daebc

Please sign in to comment.