Skip to content

Commit

Permalink
feat(pixiv): shuffle results before return (koishijs#157)
Browse files Browse the repository at this point in the history
* feat(pixiv): shuffle results before return

So mimic the random behaviour

* refactor: use koishi's shuffle instead

* refactor: remove lodash
  • Loading branch information
MaikoTan authored Mar 15, 2024
1 parent 4bfe502 commit bd7ca8a
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions packages/pixiv/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Readable } from 'node:stream'
import { ReadableStream } from 'node:stream/web'
import {} from '@koishijs/assets'
import {} from '@koishijs/plugin-server'
import { Context, Quester, Schema, trimSlash } from 'koishi'
import { Context, Quester, Random, Schema, trimSlash } from 'koishi'
import { ImageSource } from 'koishi-plugin-booru'
import { PixivAppApi } from './types'

Expand Down Expand Up @@ -70,10 +70,12 @@ class PixivImageSource extends ImageSource<PixivImageSource.Config> {
const data = await (query.raw.length ? this.search(query.tags.join(' ')) : this.recommend())

return Promise.all(
data.illusts
.filter((illust) => illust.total_bookmarks > this.config.minBookmarks)
.filter((illust) => illust.x_restrict <= this.config.rank)
.filter((illust) => illust.illust_ai_type <= this.config.ai)
Random.shuffle(
data.illusts
.filter((illust) => illust.total_bookmarks > this.config.minBookmarks)
.filter((illust) => illust.x_restrict <= this.config.rank)
.filter((illust) => illust.illust_ai_type <= this.config.ai),
)
.slice(0, query.count)
.map(async (illust) => {
let url = ''
Expand Down

0 comments on commit bd7ca8a

Please sign in to comment.