diff --git a/src/handler/messageEvent.ts b/src/handler/events/messageEvent.ts similarity index 100% rename from src/handler/messageEvent.ts rename to src/handler/events/messageEvent.ts diff --git a/src/handler/events/readyEvent.ts b/src/handler/events/readyEvent.ts new file mode 100644 index 0000000..1d5356a --- /dev/null +++ b/src/handler/events/readyEvent.ts @@ -0,0 +1,18 @@ +import { concatMap, first, fromEvent, pipe, tap } from "rxjs"; +import * as Files from '../utilities/readFile'; +import type Wrapper from '../structures/wrapper'; + +export const onReady = ( wrapper : Wrapper ) => { + const { client, init, commands, } = wrapper; + fromEvent(client, 'ready') + .pipe( + first(), + tap(() => init?.( wrapper ) ), + concatMap( + pipe( + () => Files.buildData(commands), + ) + ), + ) + .subscribe(); +} diff --git a/src/handler/readyEvent.ts b/src/handler/readyEvent.ts deleted file mode 100644 index 8b13789..0000000 --- a/src/handler/readyEvent.ts +++ /dev/null @@ -1 +0,0 @@ - diff --git a/src/handler/sern.ts b/src/handler/sern.ts index 9e61999..5fc046c 100644 --- a/src/handler/sern.ts +++ b/src/handler/sern.ts @@ -18,24 +18,14 @@ import { AllTrue } from './utilities/higherOrders'; import type Module from './structures/module'; import Context from './structures/context'; import type Wrapper from './structures/wrapper'; -import { concatMap, first, fromEvent, pipe, tap } from 'rxjs'; +import { fromEvent } from 'rxjs'; import { SernError } from './structures/errors'; +import { onReady } from './events/readyEvent'; export function init( wrapper : Wrapper) { - const { events, client, init, commands } = wrapper; + const { events, client } = wrapper; if (events !== undefined) eventObserver(client, events); - - fromEvent(client, 'ready') - .pipe( - first(), - tap(() => init?.( wrapper ) ), - concatMap( - pipe( - () => Files.buildData(commands), - ) - ), - ) - .subscribe(console.log); + onReady(wrapper); } function eventObserver(client: Client, events: DiscordEvent[] ) { @@ -57,13 +47,7 @@ export class Handler { this.wrapper = wrapper; this.client - /** - * On ready, builds command data and registers them all - * from command directory - **/ - - .on('ready', async () => { - }) + .on('messageCreate', async (message: Message) => { const isExecutable = AllTrue(isNotFromBot, hasPrefix);