mirror of
https://github.com/sern-handler/handler
synced 2026-06-06 01:16:55 +00:00
36 lines
976 B
TypeScript
36 lines
976 B
TypeScript
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<M, I> {
|
|
protected constructor(protected ctx: Either<M, I>) {
|
|
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<M, never> {
|
|
return this.ctx.map(() => true).unwrapOr(false);
|
|
}
|
|
|
|
public isSlash(): this is CoreContext<never, I> {
|
|
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") }
|
|
|
|
}
|
|
|