Skip to content

Commit

Permalink
feat: get sentence from plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
SaarChaffee committed Dec 11, 2023
1 parent 98ab560 commit ec6316f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Schema } from 'koishi'

export interface Config {
sentences?: boolean
/**
* @default "https://v1.hitokoto.cn"
*/
Expand All @@ -16,6 +17,7 @@ export interface Config {
}

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('一言的最大长度'),
Expand Down
9 changes: 8 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
import { Context, Quester } from 'koishi'
import type { SentencesParams } from 'koishi-plugin-hitokoto-sentences'

Check failure on line 2 in src/index.ts

View workflow job for this annotation

GitHub Actions / test (4.11)

Cannot find module 'koishi-plugin-hitokoto-sentences' or its corresponding type declarations.

Check failure on line 2 in src/index.ts

View workflow job for this annotation

GitHub Actions / test (4.12)

Cannot find module 'koishi-plugin-hitokoto-sentences' or its corresponding type declarations.

Check failure on line 2 in src/index.ts

View workflow job for this annotation

GitHub Actions / test (4.13)

Cannot find module 'koishi-plugin-hitokoto-sentences' or its corresponding type declarations.

Check failure on line 2 in src/index.ts

View workflow job for this annotation

GitHub Actions / test (4.14)

Cannot find module 'koishi-plugin-hitokoto-sentences' or its corresponding type declarations.

Check failure on line 2 in src/index.ts

View workflow job for this annotation

GitHub Actions / test (4.15)

Cannot find module 'koishi-plugin-hitokoto-sentences' or its corresponding type declarations.

Check failure on line 2 in src/index.ts

View workflow job for this annotation

GitHub Actions / test (4.15)

Cannot find module 'koishi-plugin-hitokoto-sentences' or its corresponding type declarations.

import { HitokotoApi } from './api'
import { Config } from './config'
import i18n from './i18n'

export const inject = {
optional: ['sentences'],
}

export const name = 'hitokoto'

export { Config, HitokotoApi }
Expand Down Expand Up @@ -41,7 +46,9 @@ export async function apply(ctx: Context, config: Config = {}): Promise<void> {
}

try {
const resp = await ctx.hitokoto.getHitokoto(params)
const resp = config.sentences && ctx.sentences

Check failure on line 49 in src/index.ts

View workflow job for this annotation

GitHub Actions / test (4.11)

Property 'sentences' does not exist on type 'Context'.

Check failure on line 49 in src/index.ts

View workflow job for this annotation

GitHub Actions / test (4.12)

Property 'sentences' does not exist on type 'Context'.

Check failure on line 49 in src/index.ts

View workflow job for this annotation

GitHub Actions / test (4.13)

Property 'sentences' does not exist on type 'Context'.

Check failure on line 49 in src/index.ts

View workflow job for this annotation

GitHub Actions / test (4.14)

Property 'sentences' does not exist on type 'Context'.

Check failure on line 49 in src/index.ts

View workflow job for this annotation

GitHub Actions / test (4.15)

Property 'sentences' does not exist on type 'Context'.

Check failure on line 49 in src/index.ts

View workflow job for this annotation

GitHub Actions / test (4.15)

Property 'sentences' does not exist on type 'Context'.
? ctx.sentences.getSentence(params as SentencesParams)

Check failure on line 50 in src/index.ts

View workflow job for this annotation

GitHub Actions / test (4.11)

Property 'sentences' does not exist on type 'Context'.

Check failure on line 50 in src/index.ts

View workflow job for this annotation

GitHub Actions / test (4.12)

Property 'sentences' does not exist on type 'Context'.

Check failure on line 50 in src/index.ts

View workflow job for this annotation

GitHub Actions / test (4.13)

Property 'sentences' does not exist on type 'Context'.

Check failure on line 50 in src/index.ts

View workflow job for this annotation

GitHub Actions / test (4.14)

Property 'sentences' does not exist on type 'Context'.

Check failure on line 50 in src/index.ts

View workflow job for this annotation

GitHub Actions / test (4.15)

Property 'sentences' does not exist on type 'Context'.

Check failure on line 50 in src/index.ts

View workflow job for this annotation

GitHub Actions / test (4.15)

Property 'sentences' does not exist on type 'Context'.
: await ctx.hitokoto.getHitokoto(params)
return session?.text('.format', resp)
} catch (error) {
const err = error as Error
Expand Down

0 comments on commit ec6316f

Please sign in to comment.