From ba06f970d33bf1ad5f257191fe72cfccde54de55 Mon Sep 17 00:00:00 2001 From: Jacob Nguyen <76754747+jacoobes@users.noreply.github.com> Date: Wed, 31 Jan 2024 14:27:14 -0600 Subject: [PATCH] inline and cleanup --- src/handlers/event-utils.ts | 2 +- src/handlers/message-event.ts | 2 +- src/handlers/ready-event.ts | 2 +- src/optional/localizer.ts | 2 +- src/sern.ts | 22 +++++++--------------- 5 files changed, 11 insertions(+), 19 deletions(-) diff --git a/src/handlers/event-utils.ts b/src/handlers/event-utils.ts index fd079384..f766bcb6 100644 --- a/src/handlers/event-utils.ts +++ b/src/handlers/event-utils.ts @@ -26,7 +26,7 @@ import { import { Emitter, ErrorHandling, Logging, ModuleManager, PayloadType } from '../core'; import { contextArgs, createDispatcher } from './dispatchers'; import { ObservableInput, pipe } from 'rxjs'; -import { Err, Ok, Result } from 'ts-results-es'; +import { Err, Ok, Result, Option } from 'ts-results-es'; import type { Awaitable } from '../types/utility'; import type { ControlPlugin } from '../types/core-plugin'; import type { AnyModule, CommandModule, Module, Processed } from '../types/core-modules'; diff --git a/src/handlers/message-event.ts b/src/handlers/message-event.ts index bb84d48b..86b14466 100644 --- a/src/handlers/message-event.ts +++ b/src/handlers/message-event.ts @@ -1,6 +1,6 @@ import { mergeMap, EMPTY } from 'rxjs'; import type { Message } from 'discord.js'; -import { PayloadType, SernEmitter } from '../core'; +import { PayloadType } from '../core'; import { sharedEventStream, SernError, filterTap, resultPayload } from '../core/_internal'; import { createMessageHandler, executeModule, makeModuleExecutor } from './_internal'; import type { DependencyList } from '../types/ioc'; diff --git a/src/handlers/ready-event.ts b/src/handlers/ready-event.ts index b4e811bd..80c6ad03 100644 --- a/src/handlers/ready-event.ts +++ b/src/handlers/ready-event.ts @@ -9,7 +9,7 @@ import * as util from 'node:util'; import type { DependencyList } from '../types/ioc'; import type { AnyModule, Processed } from '../types/core-modules'; -export function startReadyEvent( +export function readyHandler( [sEmitter, , , moduleManager, client]: DependencyList, allPaths: ObservableInput, ) { diff --git a/src/optional/localizer.ts b/src/optional/localizer.ts index f2e7fda6..c6c0654f 100644 --- a/src/optional/localizer.ts +++ b/src/optional/localizer.ts @@ -8,7 +8,7 @@ import assert from 'node:assert'; /** * @since 3.4.0 - * @internal + * @internal */ export class ShrimpleLocalizer implements Localizer, Init { private __localization!: Localization; diff --git a/src/sern.ts b/src/sern.ts index 0d48c03d..d294e7f3 100644 --- a/src/sern.ts +++ b/src/sern.ts @@ -5,7 +5,7 @@ import { merge } from 'rxjs'; import { Services } from './core/ioc'; import { Wrapper } from './types/core'; import { eventsHandler } from './handlers/user-defined-events'; -import { startReadyEvent } from './handlers/ready-event'; +import { readyHandler } from './handlers/ready-event'; import { messageHandler } from './handlers/message-event'; import { interactionHandler } from './handlers/interaction-event'; import { presenceHandler } from './handlers/presence'; @@ -26,7 +26,11 @@ import { Client } from 'discord.js'; export function init(maybeWrapper: Wrapper | 'file') { const startTime = performance.now(); const wrapper = Files.loadConfig(maybeWrapper); - const dependencies = useDependencies(); + const dependencies = Services('@sern/emitter', + '@sern/errors', + '@sern/logger', + '@sern/modules', + '@sern/client'); const logger = dependencies[2], errorHandler = dependencies[1]; @@ -37,7 +41,7 @@ export function init(maybeWrapper: Wrapper | 'file') { const initCallsite = callsites()[1].getFileName(); const presencePath = Files.shouldHandle(initCallsite!, "presence"); //Ready event: load all modules and when finished, time should be taken and logged - startReadyEvent(dependencies, Files.getFullPathTree(wrapper.commands)) + readyHandler(dependencies, Files.getFullPathTree(wrapper.commands)) .add(() => { const time = ((performance.now() - startTime) / 1000).toFixed(2); dependencies[0].emit('modulesLoaded'); @@ -55,15 +59,3 @@ export function init(maybeWrapper: Wrapper | 'file') { // listening to the message stream and interaction stream merge(messages$, interactions$).pipe(handleCrash(errorHandler, logger)).subscribe(); } - -function useDependencies() { - return Services( - '@sern/emitter', - '@sern/errors', - '@sern/logger', - '@sern/modules', - '@sern/client', - ); -} - -