feat(events) Moving default events to its own folder for organization

This commit is contained in:
Jacob Nguyen
2022-03-09 14:25:20 -06:00
parent 08f593792e
commit df626e0864
4 changed files with 23 additions and 22 deletions

View File

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

View File

@@ -1 +0,0 @@

View File

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