diff --git a/src/handler/events/interactionCreate.ts b/src/handler/events/interactionCreate.ts index b297174..a11769b 100644 --- a/src/handler/events/interactionCreate.ts +++ b/src/handler/events/interactionCreate.ts @@ -22,7 +22,7 @@ export const onInteractionCreate = ( wrapper : Wrapper ) => { .pipe( filter(mod => is(mod, CommandType.SLASH)), tap ( mod => { - const ctx = new Context(None, Some(interaction)); + const ctx = Context.wrap(interaction); (mod as SlashCommand)!.execute(ctx, ['slash', interaction.options]); }), ); @@ -32,7 +32,7 @@ export const onInteractionCreate = ( wrapper : Wrapper ) => { .pipe( filter( mod => is(mod, CommandType.MENU_USER)), tap ( mod => { - const ctx = new Context(None, Some(interaction)); + const ctx = Context.wrap(interaction); (mod as ContextMenuUser)!.execute(ctx); }) ) @@ -42,7 +42,7 @@ export const onInteractionCreate = ( wrapper : Wrapper ) => { .pipe( filter( mod => is(mod, CommandType.MENU_MSG)), tap ( mod => { - const ctx = new Context(None, Some(interaction)); + const ctx = Context.wrap(interaction); (mod as ContextMenuMsg)!.execute(ctx); }) ) diff --git a/src/handler/events/messageEvent.ts b/src/handler/events/messageEvent.ts index 06e11f8..313b090 100644 --- a/src/handler/events/messageEvent.ts +++ b/src/handler/events/messageEvent.ts @@ -33,9 +33,10 @@ export const onMessageCreate = (wrapper : Wrapper) => { ) ).subscribe ({ - error() { + error(e) { //log things console.log('Failed to finished message subscription!'); + throw e; }, next(command) { //log on each command emitted diff --git a/src/handler/structures/context.ts b/src/handler/structures/context.ts index deeae55..0d99b48 100644 --- a/src/handler/structures/context.ts +++ b/src/handler/structures/context.ts @@ -15,10 +15,16 @@ export default class Context { private msg: Option = None; private interac: Option = None; - constructor(message : Option, interaction: Option ) { + private constructor(message : Option, interaction: Option ) { this.msg = message; this.interac = interaction; } + static wrap(wrappable: I | Message) : Context { + if ( "token" in wrappable) { + return new Context( None, Some(wrappable)); + } + return new Context(Some(wrappable), None) + } private get messageUnchecked() { return this.msg.unwrap();