diff --git a/packages/core/src/session.ts b/packages/core/src/session.ts index 0509f43da0..c18c02539e 100644 --- a/packages/core/src/session.ts +++ b/packages/core/src/session.ts @@ -94,10 +94,9 @@ export class Session parsed?: Parsed - private _delay?: number - private _queued: Promise - private _hooks: (() => void)[] + private _hooks: NodeJS.Timeout[] private _promise: Promise + private _queuedMessages: [string, number][] constructor(bot: Bot, session: Partial) { Object.assign(this, session) @@ -107,7 +106,7 @@ export class Session { + this._hooks.shift() + this._next() + }, message[1]), + ) } async sendQueued(content: string, delay?: number) { @@ -179,19 +191,8 @@ export class Session new Promise((resolve) => { - const hook = () => { - resolve() - clearTimeout(timer) - remove(this._hooks, hook) - } - this._hooks.push(hook) - const timer = setTimeout(async () => { - await this.send(content) - this._delay = delay - hook() - }, this._delay || 0) - })) + this._queuedMessages.push([content, delay]) + if (this._hooks.length === 0) this._next() } resolveValue(source: T | ((session: Session) => T)): T {