Skip to content

Commit

Permalink
fix: options after query not be passed (#167)
Browse files Browse the repository at this point in the history
* fix: options after query not be passed

fix #39

* fix: revert unexpected formatting changes

* fix: add back code
  • Loading branch information
MaikoTan authored Mar 21, 2024
1 parent eac92d5 commit ace755f
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions packages/core/src/command.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,22 @@ export function apply(ctx: Context, config: Config) {

query = query?.trim() ?? ''

if (query) {
// Since the type of query is text, when user append options after the query, the options
// would not be parsed correctly. So we need to manually parse the query and options here.
// https://github.com/koishijs/koishi-plugin-booru/issues/39
const countMatch = /(-c|--count)\s+(\d+)/g.exec(query)
if (countMatch) {
options.count = count(countMatch[2], session)
query = query.replace(countMatch[0], '').trim()
}
const labelMatch = /(-l|--label)\s+([^\s]+)/g.exec(query)
if (labelMatch) {
options.label = labelMatch[2]
query = query.replace(labelMatch[0], '').trim()
}
}

const images = await ctx.booru.get({
query,
count: options.count,
Expand Down

0 comments on commit ace755f

Please sign in to comment.