Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: hide api url when using sentencts #32

Merged
merged 4 commits into from
Mar 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/api.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Context, Service } from 'koishi'

Check failure on line 1 in src/api.ts

View workflow job for this annotation

GitHub Actions / build / lint

There should be at least one empty line between import groups

Check failure on line 1 in src/api.ts

View workflow job for this annotation

GitHub Actions / build / lint

There should be at least one empty line between import groups
import type { SentencesParams } from 'koishi-plugin-hitokoto-sentences'

import { Config } from '.'

Check failure on line 4 in src/api.ts

View workflow job for this annotation

GitHub Actions / build / lint

`.` import should occur before type import of `koishi-plugin-hitokoto-sentences`

Check failure on line 4 in src/api.ts

View workflow job for this annotation

GitHub Actions / build / lint

`.` import should occur before type import of `koishi-plugin-hitokoto-sentences`

declare module 'koishi' {
interface Context {
Expand All @@ -11,13 +11,15 @@

export class HitokotoApi extends Service {
private _apiUrl: string
config: Config

constructor(
ctx: Context,
private config: Config,
config: Config,
) {
super(ctx, 'hitokoto', true)
this._apiUrl = config.apiUrl ?? 'https://v1.hitokoto.cn/'
this.config = config
this._apiUrl = this.config.sentences ? '' : this.config.apiUrl ?? 'https://v1.hitokoto.cn/'
SaarChaffee marked this conversation as resolved.
Show resolved Hide resolved
}

async getHitokoto(params: SentencesParams): Promise<HitokotoRet> {
Expand Down
24 changes: 17 additions & 7 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,20 @@ export interface Config {
defaultTypes?: string[]
}

export const Config: Schema<Config> = Schema.object({
sentences: Schema.boolean().description('是否使用本地一言语料库(需要安装 sentences 服务)').default(false),
apiUrl: Schema.string().description('获取一言的 API 地址').default('https://v1.hitokoto.cn'),
minLength: Schema.number().description('一言的最小长度'),
maxLength: Schema.number().description('一言的最大长度'),
defaultTypes: Schema.array(Schema.string()).description('默认一言类别'),
})
export const Config: Schema<Config> = Schema.intersect([
Schema.object({
sentences: Schema.boolean().description('是否使用本地一言语料库(需要安装 sentences 服务)').default(false),
}),
Schema.union([
Schema.object({
sentences: Schema.const(false),
apiUrl: Schema.string().description('获取一言的 API 地址').default('https://v1.hitokoto.cn'),
}),
Schema.object({}),
]),
Schema.object({
minLength: Schema.number().description('一言的最小长度'),
maxLength: Schema.number().description('一言的最大长度'),
defaultTypes: Schema.array(Schema.string()).description('默认一言类别'),
}),
])
Loading