Skip to content

Commit

Permalink
fix(core): only add quote content if present
Browse files Browse the repository at this point in the history
  • Loading branch information
shigma committed Nov 9, 2023
1 parent 08cf837 commit a43ea1f
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 12 deletions.
10 changes: 3 additions & 7 deletions packages/core/src/command/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export class Commander extends Map<string, Command> {

ctx.before('parse', (content, session) => {
const argv = Argv.parse(content)
if (session.quote) {
if (session.quote?.content) {
argv.tokens.push({
content: session.quote.content,
quoted: true,
Expand Down Expand Up @@ -111,7 +111,7 @@ export class Commander extends Map<string, Command> {
},
})
if (!name) return next()
const message = name + content.slice(actual.length) + (quote ? ' ' + quote.content : '')
const message = name + content.slice(actual.length) + (quote?.content ? ' ' + quote.content : '')
return session.execute(message, next)
})
})
Expand Down Expand Up @@ -150,10 +150,6 @@ export class Commander extends Map<string, Command> {
.flatMap(cmd => Object.keys(cmd._aliases))
}

protected get caller(): Context {
return this[Context.current]
}

resolve(key: string) {
return this._resolve(key).command
}
Expand Down Expand Up @@ -207,7 +203,7 @@ export class Commander extends Map<string, Command> {
const path = def.split(' ', 1)[0].toLowerCase()
const decl = def.slice(path.length)
const segments = path.split(/(?=[./])/g)
const caller = this.caller
const caller: Context = this[Context.current]

/** parent command in the chain */
let parent: Command
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export type ForkScope = cordis.ForkScope<Context>
export type MainScope = cordis.MainScope<Context>

export class Service extends cordis.Service<Context> {
protected logger: Logger
public logger: Logger

constructor(ctx: Context, name: string, immediate?: boolean) {
super(ctx, name, immediate)
Expand Down
6 changes: 3 additions & 3 deletions packages/core/src/filter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,19 +66,19 @@ export class FilterService {
union(arg: Filter | Context) {
const caller = this.caller
const filter = typeof arg === 'function' ? arg : arg.filter
return this.caller.extend({ filter: s => caller.filter(s) || filter(s) })
return caller.extend({ filter: s => caller.filter(s) || filter(s) })
}

intersect(arg: Filter | Context) {
const caller = this.caller
const filter = typeof arg === 'function' ? arg : arg.filter
return this.caller.extend({ filter: s => caller.filter(s) && filter(s) })
return caller.extend({ filter: s => caller.filter(s) && filter(s) })
}

exclude(arg: Filter | Context) {
const caller = this.caller
const filter = typeof arg === 'function' ? arg : arg.filter
return this.caller.extend({ filter: s => caller.filter(s) && !filter(s) })
return caller.extend({ filter: s => caller.filter(s) && !filter(s) })
}

user(...values: string[]) {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ export class Processor {
if ((appel || stripped.hasAt) && !stripped.appel) return
if (!context.filter(session)) return
let content = stripped.content
if (quote) content += ' ' + quote.content
if (quote?.content) content += ' ' + quote.content

let params: [string, ...string[]] = null
const match = (pattern: any) => {
Expand Down

0 comments on commit a43ea1f

Please sign in to comment.