fix: complying to djs v14 build

This commit is contained in:
Jacob Nguyen
2022-06-23 23:58:08 -05:00
parent 70ef4a0f8f
commit c56c3c9a8f
4 changed files with 60 additions and 241 deletions

View File

@@ -14,9 +14,13 @@ import Context from '../structures/context';
import { controller } from '../sern';
import type { Module } from '../structures/module';
import {
isApplicationCommand,
isAutocomplete,
isButton,
isChatInputCommand,
isMessageComponent,
isMessageCtxMenuCmd,
isModalSubmit,
isPromise,
isSelectMenu,
isUserContextMenuCmd,
@@ -179,24 +183,24 @@ export function onInteractionCreate(wrapper: Wrapper) {
.pipe(
/*processing plugins*/
concatMap(interaction => {
if (interaction.isCommand()) {
if (isApplicationCommand(interaction)) {
const modul =
Files.ApplicationCommands[interaction.commandType].get(
interaction.commandName,
) ?? Files.BothCommands.get(interaction.commandName);
return applicationCommandHandler(modul, interaction);
}
if (interaction.isMessageComponent()) {
if (isMessageComponent(interaction)) {
const modul = Files.MessageCompCommands[interaction.componentType].get(
interaction.customId,
);
return messageComponentInteractionHandler(modul, interaction);
}
if (interaction.isModalSubmit()) {
if (isModalSubmit(interaction)) {
const modul = Files.ModalSubmitCommands.get(interaction.customId);
return modalHandler(modul, interaction);
}
if (interaction.isAutocomplete()) {
if (isAutocomplete(interaction)) {
const modul =
Files.ApplicationCommands['1'].get(interaction.commandName) ??
Files.BothCommands.get(interaction.commandName);

View File

@@ -1,19 +1,7 @@
import {
concat,
concatMap,
from,
fromEvent,
map,
Observable,
of,
skip,
take,
throwError,
} from 'rxjs';
import { concat, concatMap, from, fromEvent, map, Observable, of, skip, take } from 'rxjs';
import { basename } from 'path';
import * as Files from '../utilities/readFile';
import type Wrapper from '../structures/wrapper';
import { controller } from '../sern';
import type { Result } from 'ts-results';
import { Err, Ok } from 'ts-results';
import type { Awaitable } from 'discord.js';
@@ -53,7 +41,7 @@ export function onReady(wrapper: Wrapper) {
if (cmdPluginRes.err) {
return cmdPluginRes.val;
}
return of({ mod, cmdPluginRes: cmdPluginRes.unwrap() });
return of({ mod, cmdPluginRes: cmdPluginRes.val });
}),
);
@@ -71,6 +59,7 @@ export function onReady(wrapper: Wrapper) {
.pipe(
concatMap(pl =>
from(
//refactor, this allocates too many objects
Promise.all(
pl.cmdPluginsRes.map(async e => ({ ...e, execute: await e.execute })),
),
@@ -78,7 +67,7 @@ export function onReady(wrapper: Wrapper) {
),
)
.subscribe(({ mod, cmdPluginsRes }) => {
const loadedPluginsCorrectly = cmdPluginsRes.every(res => res.execute.ok);
const loadedPluginsCorrectly = cmdPluginsRes.every(({ execute }) => execute.ok);
if (loadedPluginsCorrectly) {
const res = registerModule(mod);
if (res.err) {

View File

@@ -15,6 +15,12 @@ import type {
SernEventCommand,
} from '../structures/events';
import { CommandType } from '../..';
import {
AutocompleteInteraction,
Interaction,
InteractionType,
ModalSubmitInteraction,
} from 'discord.js';
export function correctModuleType<T extends keyof ModuleDefs>(
plug: Module | undefined,
@@ -49,7 +55,24 @@ export function isUserContextMenuCmd(
return i.isUserContextMenuCommand();
}
export function isPromise<T>(promiseLike: Awaitable<T>): promiseLike is Promise<T> {
export function isApplicationCommand(interaction: Interaction): interaction is CommandInteraction {
return interaction.type === InteractionType.ApplicationCommand;
}
export function isModalSubmit(interaction: Interaction): interaction is ModalSubmitInteraction {
return interaction.type === InteractionType.ModalSubmit;
}
export function isAutocomplete(interaction: Interaction): interaction is AutocompleteInteraction {
return interaction.type === InteractionType.ApplicationCommandAutocomplete;
}
export function isMessageComponent(
interaction: Interaction,
): interaction is MessageComponentInteraction {
return interaction.type === InteractionType.MessageComponent;
}
export function isPromise<T>(promiseLike: Awaitable<T>): promiseLike is PromiseLike<T> {
const keys = new Set(Object.keys(promiseLike));
return keys.has('then') && keys.has('catch');
}