diff --git a/src/handler/events/interactionCreate.ts b/src/handler/events/interactionCreate.ts index 6443e2d..ca70d3b 100644 --- a/src/handler/events/interactionCreate.ts +++ b/src/handler/events/interactionCreate.ts @@ -1,5 +1,5 @@ -import type { Awaitable, ChatInputCommandInteraction, Interaction } from "discord.js"; -import { map, filter, fromEvent, Observable, of, mergeMap, tap, concatMap} from "rxjs"; +import type { Interaction } from "discord.js"; +import { map, filter, fromEvent, Observable, of, tap, concatMap} from "rxjs"; import { None, Some } from "ts-results"; import { CommandType } from "../sern"; import Context from "../structures/context"; @@ -26,7 +26,6 @@ export const onInteractionCreate = ( wrapper : Wrapper ) => { } if (interaction.isContextMenuCommand()) { return of() - } else { return of() } }) diff --git a/src/handler/events/readyEvent.ts b/src/handler/events/readyEvent.ts index 20ac940..2369444 100644 --- a/src/handler/events/readyEvent.ts +++ b/src/handler/events/readyEvent.ts @@ -21,7 +21,6 @@ export const onReady = ( wrapper : Wrapper ) => { ) .subscribe({ complete() { - console.log(Files.Commands); // on ready event, complete! // log stuff? } diff --git a/src/handler/sern.ts b/src/handler/sern.ts index 6b183d2..54d3b69 100644 --- a/src/handler/sern.ts +++ b/src/handler/sern.ts @@ -13,7 +13,7 @@ import { onReady } from './events/readyEvent'; import { onMessageCreate } from './events/messageEvent'; import { onInteractionCreate } from './events/interactionCreate'; -export function init( wrapper : Wrapper) { +export function init( wrapper : Wrapper ) { const { events, client } = wrapper; if (events !== undefined) eventObserver(client, events); onReady( wrapper ); diff --git a/src/handler/structures/commands/module.ts b/src/handler/structures/commands/module.ts index bc1c4e7..7fdbc13 100644 --- a/src/handler/structures/commands/module.ts +++ b/src/handler/structures/commands/module.ts @@ -1,4 +1,4 @@ -import type { ApplicationCommandOptionData, Awaitable } from "discord.js"; +import type { ApplicationCommandOptionData, Awaitable, Interaction } from "discord.js"; import type { Args } from "../../../types/handler"; import type { CommandType } from "../../sern"; import type Context from "../context"; @@ -8,7 +8,7 @@ import type Context from "../context"; export interface BaseModule { name? : string; description : string; - execute: (ctx: Context, args: Args) => Awaitable; + execute: (ctx: Context, args: Args) => Awaitable; } export type Text = { type : CommandType.TEXT; diff --git a/src/handler/structures/context.ts b/src/handler/structures/context.ts index 3de364d..c15e4e0 100644 --- a/src/handler/structures/context.ts +++ b/src/handler/structures/context.ts @@ -2,28 +2,48 @@ import type { Interaction, Message } from 'discord.js'; -import { None, Option } from 'ts-results'; +import { None, Option, Some } from 'ts-results'; -export default class Context { +function firstSome(...args : Option[]) : T | null { + for ( const op of args ) { + if (op.some) return op.val; + } + return null; +} + +export default class Context { private msg: Option = None; - private interac: Option = None; + private interac: Option = None; - constructor(message : Option, interaction: Option ) { + constructor(message : Option, interaction: Option ) { this.msg = message; this.interac = interaction; } - get messageUnchecked() { + private get messageUnchecked() { return this.msg.unwrap(); } - get interactionUnchecked() { + private get interactionUnchecked() { return this.interac.unwrap(); } - get message() { + private get message() { return this.msg; } - get interaction() { + private get interaction() { return this.interac; } + + public get channel() { + return firstSome( + this.message.andThen(m => Some(m.channel)), + this.interaction.andThen(i => Some(i.channel)) + ) + } + public get user() { + return firstSome( + this.message.andThen(m => Some(m.author)), + this.interaction.andThen(i => Some(i.user)) + ) + } } diff --git a/tsconfig.json b/tsconfig.json index f35ae23..0e7b542 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -18,4 +18,4 @@ }, "exclude": ["node_modules", "tests", "dist"], "include": ["src"], -} \ No newline at end of file +}