From df1808cfb59fbb7168eff9f229cc02f74e872716 Mon Sep 17 00:00:00 2001 From: Jacob Nguyen <76754747+jacoobes@users.noreply.github.com> Date: Sun, 15 May 2022 16:00:05 -0500 Subject: [PATCH] style: Reformat w/ prettier --- src/handler/events/interactionCreate.ts | 28 ++++----- src/handler/events/readyEvent.ts | 6 +- src/handler/plugins/plugin.ts | 17 +++-- .../structures/modules/commands/module.ts | 28 ++++----- src/handler/utilities/markup.ts | 63 +++++++++---------- src/handler/utilities/readFile.ts | 2 +- src/handler/utilities/resolveParameters.ts | 6 +- 7 files changed, 70 insertions(+), 80 deletions(-) diff --git a/src/handler/events/interactionCreate.ts b/src/handler/events/interactionCreate.ts index 93edc67..aa739bb 100644 --- a/src/handler/events/interactionCreate.ts +++ b/src/handler/events/interactionCreate.ts @@ -21,9 +21,10 @@ import type { Module } from '../structures/modules/commands/module'; import type { EventPlugin } from '../plugins/plugin'; -function isChatInputCommand(i : CommandInteraction) : i is ChatInputCommandInteraction { +function isChatInputCommand(i: CommandInteraction): i is ChatInputCommandInteraction { return i.isChatInputCommand(); } + function applicationCommandHandler(mod: Module | undefined, interaction: CommandInteraction) { if (mod === undefined) { return throwError(() => SernError.UndefinedModule); @@ -32,27 +33,27 @@ function applicationCommandHandler(mod: Module | undefined, interaction: Command return match(interaction) .when(isChatInputCommand, i => { - const ctx = Context.wrap(i); - const res = eventPlugins.map(e => { + const ctx = Context.wrap(i); + const res = eventPlugins.map(e => { return (>e).execute( - [ctx, ['slash', i.options]] + [ctx, ['slash', i.options]] , controller); }) as Awaited>[]; //Possible unsafe cast // could result in the promises not being resolved - return of({ type : mod.type, res, plugged: mod, ctx }); + return of({ type: mod.type, res, plugged: mod, ctx }); }, ) .when( () => P._, - (ctx : UserCtxInt | MessageCtxInt) => { + (ctx: UserCtxInt | MessageCtxInt) => { //Kinda hackish const res = eventPlugins.map(e => { return e.execute( - [ctx] as UnionToTuple + [ctx] as UnionToTuple , controller); }) as Awaited>[]; - return of({ type : mod.type, res, plugged: mod, ctx }); + return of({ type: mod.type, res, plugged: mod, ctx }); }, ) .run(); @@ -68,14 +69,14 @@ function messageComponentInteractionHandler( const eventPlugins = mod.onEvent; return match(interaction) .with({ - componentType : P.union(ComponentType.Button, ComponentType.SelectMenu) - },(ctx ) => { + componentType: P.union(ComponentType.Button, ComponentType.SelectMenu), + }, (ctx) => { const res = eventPlugins.map(e => { return e.execute([ctx] as UnionToTuple, controller); }) as Awaited>[]; - return of({ type : mod.type, res, plugged: mod, ctx }); + return of({ type: mod.type, res, plugged: mod, ctx }); }) - .otherwise(() => throwError( () => SernError.NotSupportedInteraction) ); + .otherwise(() => throwError(() => SernError.NotSupportedInteraction)); } export const onInteractionCreate = (wrapper: Wrapper) => { @@ -98,8 +99,7 @@ export const onInteractionCreate = (wrapper: Wrapper) => { .MessageCompCommandStore[interaction.componentType] .get(interaction.customId); return messageComponentInteractionHandler(modul, interaction); - } - else return throwError(() => SernError.NotSupportedInteraction); + } else return throwError(() => SernError.NotSupportedInteraction); }), ) .subscribe(console.log); diff --git a/src/handler/events/readyEvent.ts b/src/handler/events/readyEvent.ts index 1cc3f7e..091d824 100644 --- a/src/handler/events/readyEvent.ts +++ b/src/handler/events/readyEvent.ts @@ -21,13 +21,13 @@ export const onReady = (wrapper: Wrapper) => { map(({ mod, absPath }) => { const name = mod?.name ?? Files.fmtFileName(basename(absPath)); if (mod?.name === undefined) { - return { name, ...mod } ; + return { name, ...mod }; } return mod; }), ); const processPlugins$ = processCommandFiles$.pipe( - concatMap(( mod ) => { + concatMap((mod) => { const cmdPluginsRes = mod.plugins.map(plug => { return { ...plug, @@ -38,7 +38,7 @@ export const onReady = (wrapper: Wrapper) => { }), }; }); - return of({ mod , cmdPluginsRes }); + return of({ mod, cmdPluginsRes }); }), ); diff --git a/src/handler/plugins/plugin.ts b/src/handler/plugins/plugin.ts index 765e06d..658a875 100644 --- a/src/handler/plugins/plugin.ts +++ b/src/handler/plugins/plugin.ts @@ -36,28 +36,25 @@ interface BasePlugin extends Override { export type CommandPlugin = { type: PluginType.Command; -} & Override< - BasePlugin, +} & Override Awaitable>; - } ->; + }>; //TODO: rn adding the modType check a little hackish. Find better way to determine the // module type of the event plugin export type EventPlugin = { type: PluginType.Event; modType: T; -} & Override< - BasePlugin, +} & Override, controller: Controller) => Awaitable>; - } ->; -export function plugins(...plug: CommandPlugin[]) : CommandPlugin[]; + }>; + +export function plugins(...plug: CommandPlugin[]): CommandPlugin[]; export function plugins(...plug: EventPlugin[]): EventPlugin[]; -export function plugins(...plug : CommandPlugin[] | EventPlugin[]) { +export function plugins(...plug: CommandPlugin[] | EventPlugin[]) { return plug; } diff --git a/src/handler/structures/modules/commands/module.ts b/src/handler/structures/modules/commands/module.ts index 6518ce0..8726b5a 100644 --- a/src/handler/structures/modules/commands/module.ts +++ b/src/handler/structures/modules/commands/module.ts @@ -14,48 +14,48 @@ import type { CommandPlugin, EventPlugin } from '../../../plugins/plugin'; //possible refactoring types into interfaces and not types export type TextCommand = { type: CommandType.Text; - onEvent : EventPlugin[]; - plugins : CommandPlugin[]; + onEvent: EventPlugin[]; + plugins: CommandPlugin[]; alias: string[] | []; } & BaseModule; export type SlashCommand = { type: CommandType.Slash; - onEvent : EventPlugin[]; - plugins : CommandPlugin[]; + onEvent: EventPlugin[]; + plugins: CommandPlugin[]; options: ApplicationCommandOptionData[] | []; } & BaseModule; export type BothCommand = { type: CommandType.Both; - onEvent : EventPlugin[] - plugins : CommandPlugin[] + onEvent: EventPlugin[] + plugins: CommandPlugin[] alias: string[] | []; options: ApplicationCommandOptionData[] | []; } & BaseModule; export type ContextMenuUser = { type: CommandType.MenuUser; - onEvent : EventPlugin[]; - plugins : CommandPlugin[]; + onEvent: EventPlugin[]; + plugins: CommandPlugin[]; } & Override Awaitable }>; export type ContextMenuMsg = { type: CommandType.MenuMsg; - onEvent : EventPlugin[]; - plugins : CommandPlugin[]; + onEvent: EventPlugin[]; + plugins: CommandPlugin[]; } & Override Awaitable }>; export type ButtonCommand = { type: CommandType.Button; - onEvent : EventPlugin[]; - plugins : CommandPlugin[]; + onEvent: EventPlugin[]; + plugins: CommandPlugin[]; } & Override Awaitable }>; export type SelectMenuCommand = { type: CommandType.MenuSelect; - onEvent : EventPlugin[]; - plugins :CommandPlugin[]; + onEvent: EventPlugin[]; + plugins: CommandPlugin[]; } & Override Awaitable }>; export type Module = diff --git a/src/handler/utilities/markup.ts b/src/handler/utilities/markup.ts index d15c105..233bde2 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('(), [ComponentType.SelectMenu]: new Map(), - [ComponentType.TextInput] : new Map() + [ComponentType.TextInput]: new Map(), }; export const TextCommandStore = { text: new Map(), diff --git a/src/handler/utilities/resolveParameters.ts b/src/handler/utilities/resolveParameters.ts index c21d8e5..33a2230 100644 --- a/src/handler/utilities/resolveParameters.ts +++ b/src/handler/utilities/resolveParameters.ts @@ -1,7 +1,7 @@ -export type UnionToTuple = T extends readonly [ infer V, infer S ] +export type UnionToTuple = T extends readonly [infer V, infer S] ? V extends V ? S extends S - ? [ V, S ] - : [ V ] + ? [V, S] + : [V] : never : never;