Skip to content

Commit

Permalink
fix: use sentense for service & fix package conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
MaikoTan committed Feb 18, 2024
1 parent e6bc346 commit 56f75b9
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 17 deletions.
8 changes: 2 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@
"build": "yarn build:tsup --minify",
"dev": "yarn build:tsup",
"build:tsup": "tsup",
"clean": "rimraf dist/*",
"test": "mocha -r esbuild-register -r yml-register --extension .spec.ts ./__tests__",
"test": "mocha -r tsx -r yml-register --extension .spec.ts ./__tests__",
"lint": "eslint src/**/*.ts && yarn prettier --check",
"format": "yarn prettier --write",
"prettier": "prettier '**/*.{js,ts,json,yml,yaml,md}' '!dist/**/*'"
Expand All @@ -54,7 +53,7 @@
"service": {
"required": [],
"optional": [
"sentences"
"database"
],
"implements": []
},
Expand Down Expand Up @@ -82,9 +81,7 @@
"@typescript-eslint/eslint-plugin": "^6.13.1",
"@typescript-eslint/parser": "^6.13.1",
"chai": "^4.3.10",
"esbuild": "^0.19.8",
"esbuild-plugin-yaml": "^0.0.1",
"esbuild-register": "^3.5.0",
"eslint": "^8.54.0",
"eslint-import-resolver-typescript": "^3.6.1",
"fs-extra": "^11.2.0",
Expand All @@ -93,7 +90,6 @@
"koishi-plugin-hitokoto-sentences": "^1.0.393",
"mocha": "^10.2.0",
"prettier": "^3.1.0",
"rimraf": "^5.0.5",
"tsup": "^8.0.1",
"tsx": "^4.7.1",
"typescript": "^5.3.3",
Expand Down
15 changes: 4 additions & 11 deletions src/api.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,14 @@
import { Context, Service } from 'koishi'
import type { SentencesParams } from 'koishi-plugin-hitokoto-sentences'

import { Config } from '.'

import type { SentencesParams } from 'koishi-plugin-hitokoto-sentences'

declare module 'koishi' {
interface Context {
hitokoto: HitokotoApi
}
}

export interface HitokotoParams {
c?: string[]
min_length?: number
max_length?: number
}

export class HitokotoApi extends Service {
private _apiUrl: string

Expand All @@ -24,11 +17,11 @@ export class HitokotoApi extends Service {
this._apiUrl = config.apiUrl ?? 'https://v1.hitokoto.cn/'
}

async getHitokoto(params: HitokotoParams): Promise<HitokotoRet> {
async getHitokoto(params: SentencesParams): Promise<HitokotoRet> {
const sentences = this.ctx.get('sentences')
let resp: HitokotoRet
if (this.config.sentences && sentences) {
resp = sentences.getSentences(params as SentencesParams)
resp = sentences.getSentence(params)
} else {
resp = await this.ctx.http.get<HitokotoRet>(this._apiUrl, {
params: this.buildSearchParams(params),
Expand All @@ -41,7 +34,7 @@ export class HitokotoApi extends Service {
}
}

buildSearchParams(params: HitokotoParams): URLSearchParams {
buildSearchParams(params: SentencesParams): URLSearchParams {
const searchParams = new URLSearchParams()
if (params.c) {
params.c.forEach((type) => searchParams.append('c', type))
Expand Down

0 comments on commit 56f75b9

Please sign in to comment.