diff --git a/src/handler/events/readyEvent.ts b/src/handler/events/readyEvent.ts index 4d27ebe..60c7909 100644 --- a/src/handler/events/readyEvent.ts +++ b/src/handler/events/readyEvent.ts @@ -1,12 +1,13 @@ -import { from, fromEvent, map, take,concat, concatAll, mergeMap, skip} from 'rxjs'; import { basename } from 'path'; +import { from, fromEvent, map, take,concat, concatAll, mergeMap, skip, Observable, defer} from 'rxjs'; import { basename } from 'path'; import * as Files from '../utilities/readFile'; import type Wrapper from '../structures/wrapper'; import type { HandlerCallback, ModuleHandlers, ModuleStates, ModuleType } from '../structures/modules/commands/moduleHandler'; import { CommandType } from '../sern'; import type { CommandPlugin, SernPlugin } from '../plugins/plugin'; import { partition } from './observableHandling'; -import { Err, Ok } from 'ts-results'; +import { Err, Ok, Result } from 'ts-results'; import type { PluggedModule } from '../structures/modules/module'; +import type { Awaitable } from 'discord.js'; export const onReady = ( wrapper : Wrapper ) => { const { client, commands } = wrapper; @@ -31,16 +32,24 @@ export const onReady = ( wrapper : Wrapper ) => { }) }), ); - concat(ready$.pipe(skip(1)),processCommandFiles$) - .subscribe( _ => { - if(a.ok) { + (concat(ready$.pipe(skip(1)),processCommandFiles$) as Observable<{ + res : Awaitable>, plugged : PluggedModule + }>).pipe( + mergeMap(async( {res, plugged})=> ({ res:await res, plugged }) ) + ) + .subscribe( ({ res, plugged: { mod, plugins }}) => { + if(res.ok) { registerModule(mod.name!, mod, plugins) } else { - + // TODO: add event emitter for command failures + console.log('a plugin failed to load'); + console.log(`Did not register command ${mod.name!}`) + console.log(mod); } }) } + // Refactor : ? Possibly repetitive and verbose. const handler = ( name : string ) => ({ diff --git a/src/handler/plugins/defaultPlugins.ts b/src/handler/plugins/defaultPlugins.ts index 4ce781f..0663b72 100644 --- a/src/handler/plugins/defaultPlugins.ts +++ b/src/handler/plugins/defaultPlugins.ts @@ -1,5 +1,5 @@ import type { Client } from "discord.js"; -import type { Module } from "../.."; +import { Module, Sern } from "../.."; import { CommandPlugin, Controller, PluginType } from "./plugin"; export function reload( @@ -13,6 +13,7 @@ export function reload( async execute(client : Client, module: Module, controller : Controller ) { const curGuild = await client.guilds.fetch(data.guildId); await curGuild.commands.edit(data.applicationId, { + type : Sern.cmdTypeToDjs(module.type), name : module.name!, description: module.description, }) diff --git a/src/handler/sern.ts b/src/handler/sern.ts index 73e66b2..2e67472 100644 --- a/src/handler/sern.ts +++ b/src/handler/sern.ts @@ -2,12 +2,14 @@ import type { DiscordEvent, } from '../types/handler'; -import type { +import { + ApplicationCommandType, Client, + MessageType, } from 'discord.js'; import type Wrapper from './structures/wrapper'; -import { fromEvent } from 'rxjs'; +import { fromEvent, throwError } from 'rxjs'; import { SernError } from './structures/errors'; import { onReady } from './events/readyEvent'; import { onMessageCreate } from './events/messageEvent'; @@ -45,3 +47,13 @@ export enum CommandType { Auto = 0b1000000 } +export function cmdTypeToDjs(ty: CommandType) { + switch (ty) { + case CommandType.Slash : case CommandType.Both : return ApplicationCommandType.ChatInput; + case CommandType.MenuUser : return ApplicationCommandType.User; + case CommandType.MenuMsg : return ApplicationCommandType.Message; + default : throw new Error(`Cannot turn this CommandType to ApplicationCommandType`) + } +} + +