From bc0d1ce69e23c3e5e567080f539ee1a50bda203d Mon Sep 17 00:00:00 2001 From: Jacob Nguyen <76754747+jacoobes@users.noreply.github.com> Date: Sat, 2 Apr 2022 23:07:31 -0500 Subject: [PATCH] refactor(context.ts) name changes for easier dev usages --- src/handler/structures/context.ts | 48 ++++++++++++++----------------- 1 file changed, 22 insertions(+), 26 deletions(-) diff --git a/src/handler/structures/context.ts b/src/handler/structures/context.ts index e7870ba..fda39f3 100644 --- a/src/handler/structures/context.ts +++ b/src/handler/structures/context.ts @@ -13,12 +13,13 @@ function firstSome(...args : Option[]) : T | null { } export default class Context { - private msg: Option = None; - private interac: Option = None; - private constructor(message : Option, interaction: Option ) { - this.msg = message; - this.interac = interaction; + private constructor( + private oMsg: Option = None, + private oInterac: Option = None + ) { + this.oMsg = oMsg; + this.oInterac = oInterac; } static wrap(wrappable: I|Message) : Context { if ( "token" in wrappable ) { @@ -30,22 +31,17 @@ export default class Context { return new Context(None, None); } public isEmpty() { - return this.msg.none && this.interaction.none; + return this.oMsg.none && this.oInterac.none; } - public get messageUnchecked() { - return this.msg.unwrap(); + public get message() { + return this.oMsg.unwrap(); } - public get interactionUnchecked() { - return this.interac.unwrap(); - } - private get message() { - return this.msg; - } - private get interaction() { - return this.interac; + public get interaction() { + return this.oInterac.unwrap(); } + /** * maps a general Context to Context * if interaction is None return Context.empty() @@ -54,33 +50,33 @@ export default class Context { public map_interaction( cb : ( ctx: I ) => Context ) : Context { - if (this.interac.none) return Context.empty(); - return cb(this.interactionUnchecked); + if (this.oInterac.none) return Context.empty(); + return cb(this.oInterac.val); } public get id() : Snowflake { return firstSome( - this.interac.andThen( i => Some(i.id)), - this.msg.andThen(m => Some(m.id)) + this.oInterac.andThen( i => Some(i.id)), + this.oMsg.andThen(m => Some(m.id)) )!; } public get channel() { return firstSome( - this.message.andThen(m => Some(m.channel)), - this.interaction.andThen(i => Some(i.channel)) + this.oMsg.andThen(m => Some(m.channel)), + this.oInterac.andThen(i => Some(i.channel)) ); } public get user() { return firstSome( - this.message.andThen(m => Some(m.author)), - this.interaction.andThen(i => Some(i.user)) + this.oMsg.andThen(m => Some(m.author)), + this.oInterac.andThen(i => Some(i.user)) ); } public get createdTimestamp() : number { return firstSome( - this.message.andThen(m => Some(m.createdTimestamp)), - this.interaction.andThen(i => Some(i.createdTimestamp)) + this.oMsg.andThen(m => Some(m.createdTimestamp)), + this.oInterac.andThen(i => Some(i.createdTimestamp)) )!; } }