mirror of
https://github.com/sern-handler/handler
synced 2026-06-17 05:12:16 +00:00
refactor(context.ts) clean up context constructing
This commit is contained in:
@@ -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);
|
||||
})
|
||||
)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -15,10 +15,16 @@ export default class Context<I extends Interaction = Interaction> {
|
||||
private msg: Option<Message> = None;
|
||||
private interac: Option<I> = None;
|
||||
|
||||
constructor(message : Option<Message>, interaction: Option<I> ) {
|
||||
private constructor(message : Option<Message>, interaction: Option<I> ) {
|
||||
this.msg = message;
|
||||
this.interac = interaction;
|
||||
}
|
||||
static wrap<I extends Interaction>(wrappable: I | Message) : Context<I> {
|
||||
if ( "token" in wrappable) {
|
||||
return new Context( None, Some(wrappable));
|
||||
}
|
||||
return new Context(Some(wrappable), None)
|
||||
}
|
||||
|
||||
private get messageUnchecked() {
|
||||
return this.msg.unwrap();
|
||||
|
||||
Reference in New Issue
Block a user