import { Result as Either } from 'ts-results-es'; import { SernError } from './errors'; import * as assert from 'node:assert' /** * @since 3.0.0 */ export abstract class CoreContext { protected constructor(protected ctx: Either) { assert.ok(typeof ctx.val === 'object' && ctx.val != null) } get message(): M { return this.ctx.expect(SernError.MismatchEvent); } get interaction(): I { return this.ctx.expectErr(SernError.MismatchEvent); } public isMessage(): this is CoreContext { return this.ctx.map(() => true).unwrapOr(false); } public isSlash(): this is CoreContext { return !this.isMessage(); } //todo: add agnostic options resolver for Context abstract get options() : unknown abstract get id() : string static wrap(_: unknown): unknown { throw Error("You need to override this method; cannot wrap an abstract class") } }