diff --git a/.prettierrc b/.prettierrc index f0c38cf..1b53835 100644 --- a/.prettierrc +++ b/.prettierrc @@ -2,7 +2,7 @@ "semi": true, "trailingComma": "all", "singleQuote": true, - "printWidth": 120, + "printWidth": 100, "tabWidth": 4, "arrowParens": "avoid" } diff --git a/src/handler/events/interactionCreate.ts b/src/handler/events/interactionCreate.ts index 09603ef..ddf4321 100644 --- a/src/handler/events/interactionCreate.ts +++ b/src/handler/events/interactionCreate.ts @@ -1,4 +1,9 @@ -import type { CommandInteraction, Interaction, MessageComponentInteraction, SelectMenuInteraction } from 'discord.js'; +import type { + CommandInteraction, + Interaction, + MessageComponentInteraction, + SelectMenuInteraction, +} from 'discord.js'; import { concatMap, fromEvent, map, Observable, of, throwError } from 'rxjs'; import type Wrapper from '../structures/wrapper'; import * as Files from '../utilities/readFile'; @@ -27,7 +32,11 @@ function applicationCommandHandler(mod: Module | undefined, interaction: Command const ctx = Context.wrap(i); return mod$(CommandType.Slash).pipe( concatMap(m => { - return of(m.onEvent?.map(e => e.execute([ctx, ['slash', i.options]], controller)) ?? []).pipe( + return of( + m.onEvent?.map(e => + e.execute([ctx, ['slash', i.options]], controller), + ) ?? [], + ).pipe( map(res => ({ mod, res, @@ -75,7 +84,10 @@ function applicationCommandHandler(mod: Module | undefined, interaction: Command ); } -function messageComponentInteractionHandler(mod: Module | undefined, interaction: MessageComponentInteraction) { +function messageComponentInteractionHandler( + mod: Module | undefined, + interaction: MessageComponentInteraction, +) { const mod$ = (ty: T) => of(mod).pipe(filterCorrectModule(ty)); //Todo: refactor so that we dont have to have two separate branches. They're near identical!! //Only thing that differs is type of interaction @@ -124,12 +136,15 @@ export function onInteractionCreate(wrapper: Wrapper) { concatMap(interaction => { if (interaction.isCommand()) { const modul = - Files.ApplicationCommands[interaction.commandType].get(interaction.commandName) ?? - Files.BothCommands.get(interaction.commandName); + Files.ApplicationCommands[interaction.commandType].get( + interaction.commandName, + ) ?? Files.BothCommands.get(interaction.commandName); return applicationCommandHandler(modul, interaction); } if (interaction.isMessageComponent()) { - const modul = Files.MessageCompCommands[interaction.componentType].get(interaction.customId); + const modul = Files.MessageCompCommands[interaction.componentType].get( + interaction.customId, + ); return messageComponentInteractionHandler(modul, interaction); } else return throwError(() => SernError.NotSupportedInteraction); }), diff --git a/src/handler/events/readyEvent.ts b/src/handler/events/readyEvent.ts index a058161..dbf58a3 100644 --- a/src/handler/events/readyEvent.ts +++ b/src/handler/events/readyEvent.ts @@ -52,9 +52,11 @@ export const onReady = (wrapper: Wrapper) => { ) .pipe( concatMap(pl => - from(Promise.all(pl.cmdPluginsRes.map(async e => ({ ...e, execute: await e.execute })))).pipe( - map(res => ({ ...pl, cmdPluginsRes: res })), - ), + from( + Promise.all( + pl.cmdPluginsRes.map(async e => ({ ...e, execute: await e.execute })), + ), + ).pipe(map(res => ({ ...pl, cmdPluginsRes: res }))), ), ) .subscribe(({ mod, cmdPluginsRes }) => { diff --git a/src/handler/plugins/plugin.ts b/src/handler/plugins/plugin.ts index d361fa4..282e30f 100644 --- a/src/handler/plugins/plugin.ts +++ b/src/handler/plugins/plugin.ts @@ -34,7 +34,11 @@ export type CommandPlugin = Override< BasePlugin, { type: PluginType.Command; - execute: (wrapper: Client, module: Module, controller: Controller) => Awaitable>; + execute: ( + wrapper: Client, + module: Module, + controller: Controller, + ) => Awaitable>; } >; @@ -44,7 +48,10 @@ export type EventPlugin = Override< BasePlugin, { type: PluginType.Event; - execute: (event: Parameters, controller: Controller) => Awaitable>; + execute: ( + event: Parameters, + controller: Controller, + ) => Awaitable>; } >; diff --git a/src/handler/sernEmitter.ts b/src/handler/sernEmitter.ts index 26aea13..4beb0f6 100644 --- a/src/handler/sernEmitter.ts +++ b/src/handler/sernEmitter.ts @@ -26,7 +26,10 @@ export default class SernEmitter extends EventEmitter { return super.once(eventName, listener); } - public override emit(eventName: T, ...args: SernEventsMapping[T]): boolean { + public override emit( + eventName: T, + ...args: SernEventsMapping[T] + ): boolean { return super.emit(eventName, ...args); } } diff --git a/src/handler/structures/context.ts b/src/handler/structures/context.ts index 487eef1..4eb3d1b 100644 --- a/src/handler/structures/context.ts +++ b/src/handler/structures/context.ts @@ -1,6 +1,7 @@ import type { APIGuildMember } from 'discord-api-types/v9'; import type { ChatInputCommandInteraction, + Client, Guild, GuildMember, InteractionReplyOptions, @@ -12,7 +13,6 @@ import type { } from 'discord.js'; import { None, Option, Some } from 'ts-results'; import type { Nullish } from '../../types/handler'; -import type { Client } from 'discord.js'; import { ExternallyUsed } from '../utilities/externallyUsed'; function firstSome(...args: Option[]): Nullish { @@ -21,6 +21,7 @@ function firstSome(...args: Option[]): Nullish { } return null; } + //Could I refactor with Either monad? /** * The Context class will provide values that are shared between @@ -35,14 +36,17 @@ export default class Context { this.oMsg = oMsg; this.oInterac = oInterac; } + @ExternallyUsed public get message() { return this.oMsg.unwrap(); } + @ExternallyUsed public get interaction() { return this.oInterac.unwrap(); } + @ExternallyUsed public get id(): Snowflake { return firstSome( @@ -50,6 +54,7 @@ export default class Context { this.oMsg.map(m => m.id), )!; } + @ExternallyUsed public get channel(): Nullish { return firstSome( @@ -57,6 +62,7 @@ export default class Context { this.oInterac.map(i => i.channel), ); } + @ExternallyUsed public get user(): User { return firstSome( @@ -64,6 +70,7 @@ export default class Context { this.oInterac.map(i => i.user), )!; } + @ExternallyUsed public get createdTimestamp(): number { return firstSome( @@ -71,6 +78,7 @@ export default class Context { this.oInterac.map(i => i.createdTimestamp), )!; } + @ExternallyUsed public get guild(): Guild { return firstSome( @@ -78,6 +86,7 @@ export default class Context { this.oInterac.map(i => i.guild), )!; } + @ExternallyUsed public get guildId(): Snowflake { return firstSome( @@ -97,12 +106,29 @@ export default class Context { ); } + @ExternallyUsed + public get client(): Client { + return firstSome( + this.oMsg.map(m => m.client), + this.oInterac.map(i => i.client), + )!; + } + + @ExternallyUsed + public get inGuild(): boolean { + return firstSome( + this.oMsg.map(m => m.inGuild()), + this.oInterac.map(i => i.inGuild()), + )!; + } + static wrap(wrappable: ChatInputCommandInteraction | Message): Context { if ('token' in wrappable) { return new Context(None, Some(wrappable)); } return new Context(Some(wrappable), None); } + @ExternallyUsed public isEmpty() { return this.oMsg.none && this.oInterac.none; @@ -120,18 +146,4 @@ export default class Context { }), )!; } - @ExternallyUsed - public get client(): Client { - return firstSome( - this.oMsg.map(m => m.client), - this.oInterac.map(i => i.client), - )!; - } - @ExternallyUsed - public get inGuild(): boolean { - return firstSome( - this.oMsg.map(m => m.inGuild()), - this.oInterac.map(i => i.inGuild()), - )!; - } } diff --git a/src/handler/utilities/markup.ts b/src/handler/utilities/markup.ts index f6eb54d..6d0879b 100644 --- a/src/handler/utilities/markup.ts +++ b/src/handler/utilities/markup.ts @@ -657,43 +657,37 @@ class MatchInner { while ((match = regex.exec(this.raw))) { const result: DiscordRegexMatch = { matched: match[0], species: type }; switch (type) { - case DiscordRegexNames.EMOJI: - { - result.name = match[1] as string; - result.id = match[2] as string; - result.animated = this.raw.startsWith('