style: prettier line feed changes

This commit is contained in:
Jacob Nguyen
2022-08-19 01:24:53 -05:00
parent ebe759f5e0
commit 4323be47d7
11 changed files with 4864 additions and 4859 deletions

View File

@@ -61,15 +61,12 @@ export default class InteractionHandler extends EventsHandler<{
this.discordEvent.subscribe({
next: event => {
if (isMessageComponent(event)) {
const mod = Files.MessageCompCommands[event.componentType].get(
event.customId,
);
const mod = Files.MessageCompCommands[event.componentType].get(event.customId);
this.setState({ event, mod });
} else if (isApplicationCommand(event) || isAutocomplete(event)) {
const mod =
Files.ApplicationCommands[event.commandType].get(
event.commandName,
) ?? Files.BothCommands.get(event.commandName);
Files.ApplicationCommands[event.commandType].get(event.commandName) ??
Files.BothCommands.get(event.commandName);
this.setState({ event, mod });
} else if (isModalSubmit(event)) {
/**
@@ -106,10 +103,7 @@ export default class InteractionHandler extends EventsHandler<{
{ type: CommandType.Modal },
modalCommandDispatcher(event as ModalSubmitInteraction),
)
.with(
{ type: CommandType.Button },
buttonCommandDispatcher(event as ButtonInteraction),
)
.with({ type: CommandType.Button }, buttonCommandDispatcher(event as ButtonInteraction))
.with(
{ type: CommandType.MenuSelect },
selectMenuCommandDispatcher(event as SelectMenuInteraction),

View File

@@ -7,7 +7,6 @@ import type { CommandType } from '../structures/enums';
import type Wrapper from '../structures/wrapper';
import { PayloadType } from '../structures/enums';
export function ignoreNonBot(prefix: string) {
return (src: Observable<Message>) =>
new Observable<Message>(subscriber => {

View File

@@ -1,7 +1,7 @@
import { ApplicationCommandType, ComponentType } from 'discord.js';
import { readdirSync, statSync } from 'fs';
import { join } from 'path';
import { type Observable, from, concatAll } from 'rxjs';
import { type Observable, from, concatAll } from 'rxjs';
import type { CommandModule } from '../structures/module';
import { SernError } from '../structures/errors';
import { type Result, Err, Ok } from 'ts-results-es';
@@ -63,19 +63,22 @@ export function buildData<T>(commandDir: string): Observable<
>
> {
const commands = getCommands(commandDir);
return from(Promise.all(commands.map(async absPath => {
let mod : T | undefined;
try {
// eslint-disable-next-line @typescript-eslint/no-var-requires
mod = require(absPath).default;
} catch {
mod = (await import(`file:///` +absPath)).default;
}
if (mod !== undefined) {
return Ok({ mod, absPath });
} else return Err(SernError.UndefinedModule);
})
)).pipe(concatAll());
return from(
Promise.all(
commands.map(async absPath => {
let mod: T | undefined;
try {
// eslint-disable-next-line @typescript-eslint/no-var-requires
mod = require(absPath).default;
} catch {
mod = (await import(`file:///` + absPath)).default;
}
if (mod !== undefined) {
return Ok({ mod, absPath });
} else return Err(SernError.UndefinedModule);
}),
),
).pipe(concatAll());
}
export function getCommands(dir: string): string[] {

View File

@@ -1,31 +1,40 @@
import type { SernOptionsData } from '../structures/module';
import { ApplicationCommandOptionType, AutocompleteInteraction } from 'discord.js';
export default function treeSearch(iAutocomplete: AutocompleteInteraction, options: SernOptionsData[] | undefined) {
if(options === undefined) return undefined;
export default function treeSearch(
iAutocomplete: AutocompleteInteraction,
options: SernOptionsData[] | undefined,
) {
if (options === undefined) return undefined;
const _options = options.slice(); // required to prevent direct mutation of options
while ( _options.length > 0 ) {
while (_options.length > 0) {
const cur = _options.pop()!;
switch ( cur.type ) {
case ApplicationCommandOptionType.Subcommand : {
for ( const option of cur.options ?? [] ) {
_options.push(option);
}
} break;
case ApplicationCommandOptionType.SubcommandGroup : {
for (const command of cur.options ?? []) {
_options.push(command);
}
} break;
default : {
if(cur.autocomplete) {
const choice = iAutocomplete.options.getFocused(true);
if(cur.name === choice.name && cur.autocomplete) {
return cur;
switch (cur.type) {
case ApplicationCommandOptionType.Subcommand:
{
for (const option of cur.options ?? []) {
_options.push(option);
}
return undefined;
}
} break;
break;
case ApplicationCommandOptionType.SubcommandGroup:
{
for (const command of cur.options ?? []) {
_options.push(command);
}
}
break;
default:
{
if (cur.autocomplete) {
const choice = iAutocomplete.options.getFocused(true);
if (cur.name === choice.name && cur.autocomplete) {
return cur;
}
return undefined;
}
}
break;
}
}
}
}