style: Reformat w/ prettier

This commit is contained in:
Jacob Nguyen
2022-05-15 16:00:05 -05:00
parent b6bf08f673
commit df1808cfb5
7 changed files with 70 additions and 80 deletions

View File

@@ -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 (<EventPlugin<CommandType.Both>>e).execute(
[ctx, <Args>['slash', i.options]]
[ctx, <Args>['slash', i.options]]
, controller);
}) as Awaited<Result<void, void>>[];
//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<CommandType.MenuMsg | CommandType.MenuUser>
[ctx] as UnionToTuple<CommandType.MenuMsg | CommandType.MenuUser>
, controller);
}) as Awaited<Result<void, void>>[];
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<CommandType.Button | CommandType.MenuSelect>, controller);
}) as Awaited<Result<void, void>>[];
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);

View File

@@ -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 });
}),
);

View File

@@ -36,28 +36,25 @@ interface BasePlugin extends Override<BaseModule, executeCmdPlugin> {
export type CommandPlugin = {
type: PluginType.Command;
} & Override<
BasePlugin,
} & Override<BasePlugin,
{
execute: (wrapper: Client, module: Module, controller: Controller) => Awaitable<Result<void, void>>;
}
>;
}>;
//TODO: rn adding the modType check a little hackish. Find better way to determine the
// module type of the event plugin
export type EventPlugin<T extends CommandType> = {
type: PluginType.Event;
modType: T;
} & Override<
BasePlugin,
} & Override<BasePlugin,
{
execute: (event: Parameters<ModuleDefs[T]['execute']>, controller: Controller) => Awaitable<Result<void, void>>;
}
>;
export function plugins(...plug: CommandPlugin[]) : CommandPlugin[];
}>;
export function plugins(...plug: CommandPlugin[]): CommandPlugin[];
export function plugins<T extends CommandType>(...plug: EventPlugin<T>[]): EventPlugin<T>[];
export function plugins<T extends CommandType>(...plug : CommandPlugin[] | EventPlugin<T>[]) {
export function plugins<T extends CommandType>(...plug: CommandPlugin[] | EventPlugin<T>[]) {
return plug;
}

View File

@@ -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<CommandType.Text>[];
plugins : CommandPlugin[];
onEvent: EventPlugin<CommandType.Text>[];
plugins: CommandPlugin[];
alias: string[] | [];
} & BaseModule;
export type SlashCommand = {
type: CommandType.Slash;
onEvent : EventPlugin<CommandType.Slash>[];
plugins : CommandPlugin[];
onEvent: EventPlugin<CommandType.Slash>[];
plugins: CommandPlugin[];
options: ApplicationCommandOptionData[] | [];
} & BaseModule;
export type BothCommand = {
type: CommandType.Both;
onEvent : EventPlugin<CommandType.Both>[]
plugins : CommandPlugin[]
onEvent: EventPlugin<CommandType.Both>[]
plugins: CommandPlugin[]
alias: string[] | [];
options: ApplicationCommandOptionData[] | [];
} & BaseModule;
export type ContextMenuUser = {
type: CommandType.MenuUser;
onEvent : EventPlugin<CommandType.MenuUser>[];
plugins : CommandPlugin[];
onEvent: EventPlugin<CommandType.MenuUser>[];
plugins: CommandPlugin[];
} & Override<BaseModule, { execute: (ctx: UserContextMenuCommandInteraction) => Awaitable<void> }>;
export type ContextMenuMsg = {
type: CommandType.MenuMsg;
onEvent : EventPlugin<CommandType.MenuUser>[];
plugins : CommandPlugin[];
onEvent: EventPlugin<CommandType.MenuUser>[];
plugins: CommandPlugin[];
} & Override<BaseModule, { execute: (ctx: MessageContextMenuCommandInteraction) => Awaitable<void> }>;
export type ButtonCommand = {
type: CommandType.Button;
onEvent : EventPlugin<CommandType.Button>[];
plugins : CommandPlugin[];
onEvent: EventPlugin<CommandType.Button>[];
plugins: CommandPlugin[];
} & Override<BaseModule, { execute: (ctx: ButtonInteraction) => Awaitable<void> }>;
export type SelectMenuCommand = {
type: CommandType.MenuSelect;
onEvent : EventPlugin<CommandType.MenuSelect>[];
plugins :CommandPlugin[];
onEvent: EventPlugin<CommandType.MenuSelect>[];
plugins: CommandPlugin[];
} & Override<BaseModule, { execute: (ctx: SelectMenuInteraction) => Awaitable<void> }>;
export type Module =

View File

@@ -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('<a:');
}
case DiscordRegexNames.EMOJI: {
result.name = match[1] as string;
result.id = match[2] as string;
result.animated = this.raw.startsWith('<a:');
}
break;
case DiscordRegexNames.JUMP_CHANNEL:
{
result.guildId = match[1] as string;
result.channelId = match[2] as string;
}
case DiscordRegexNames.JUMP_CHANNEL: {
result.guildId = match[1] as string;
result.channelId = match[2] as string;
}
break;
case DiscordRegexNames.JUMP_CHANNEL_MESSAGE:
{
result.guildId = match[1] as string;
result.channelId = match[2] as string;
result.messageId = match[3] as string;
}
case DiscordRegexNames.JUMP_CHANNEL_MESSAGE: {
result.guildId = match[1] as string;
result.channelId = match[2] as string;
result.messageId = match[3] as string;
}
break;
case DiscordRegexNames.MENTION_CHANNEL:
case DiscordRegexNames.MENTION_ROLE:
{
result.id = match[1] as string;
}
case DiscordRegexNames.MENTION_ROLE: {
result.id = match[1] as string;
}
break;
case DiscordRegexNames.MENTION_USER:
{
result.id = match[2] as string;
result.mentionType = match[1] as string;
}
case DiscordRegexNames.MENTION_USER: {
result.id = match[2] as string;
result.mentionType = match[1] as string;
}
break;
case DiscordRegexNames.TEXT_CODEBLOCK:
{
result.language = match[2] as string;
result.text = match[3] as string;
}
case DiscordRegexNames.TEXT_CODEBLOCK: {
result.language = match[2] as string;
result.text = match[3] as string;
}
break;
case DiscordRegexNames.TEXT_BOLD:
case DiscordRegexNames.TEXT_CODESTRING:
@@ -702,10 +696,9 @@ class MatchInner {
case DiscordRegexNames.TEXT_SPOILER:
case DiscordRegexNames.TEXT_STRIKE:
case DiscordRegexNames.TEXT_UNDERLINE:
case DiscordRegexNames.TEXT_URL:
{
result.text = match[1] as string;
}
case DiscordRegexNames.TEXT_URL: {
result.text = match[1] as string;
}
break;
default: {
throw new global.Error(`Unknown regex type: ${type}`);

View File

@@ -14,7 +14,7 @@ export const ApplicationCommandStore = {
export const MessageCompCommandStore = {
[ComponentType.Button]: new Map<string, Module>(),
[ComponentType.SelectMenu]: new Map<string, Module>(),
[ComponentType.TextInput] : new Map<string, Module>()
[ComponentType.TextInput]: new Map<string, Module>(),
};
export const TextCommandStore = {
text: new Map<string, Module>(),

View File

@@ -1,7 +1,7 @@
export type UnionToTuple<T> = T extends readonly [ infer V, infer S ]
export type UnionToTuple<T> = T extends readonly [infer V, infer S]
? V extends V
? S extends S
? [ V, S ]
: [ V ]
? [V, S]
: [V]
: never
: never;