diff --git a/src/_internal.ts b/src/_internal.ts index 7749ac3..690c56d 100644 --- a/src/_internal.ts +++ b/src/_internal.ts @@ -13,9 +13,14 @@ import { type _Module, } from './core/_internal'; import { createInteractionHandler, executeModule, makeModuleExecutor } from './handlers/event-utils'; -import type { Emitter } from './core/interfaces' +import type { Emitter, ErrorHandling, Logging } from './core/interfaces' +import { Services } from './core/ioc/dependency-injection'; -export function interactionHandler(client: Emitter, emitter: Emitter, modules: Map) { +export function interactionHandler(client: Emitter, + emitter: Emitter, + log: Logging, + err: ErrorHandling, + modules: Map) { const interactionStream$ = sharedEventStream(client, 'interactionCreate'); const handle = createInteractionHandler(interactionStream$, modules); @@ -29,3 +34,9 @@ export function interactionHandler(client: Emitter, emitter: Emitter, modules: M emitter.emit('module.activate', resultPayload(PayloadType.Failure, module, SernError.PluginFailure)))), mergeMap(payload => executeModule(emitter, log, err, payload))); } + +export const __dependencies = () => + Services('@sern/emitter', + '@sern/errors', + '@sern/logger', + '@sern/client'); diff --git a/src/core/_internal.ts b/src/core/_internal.ts index 3504597..a946f20 100644 --- a/src/core/_internal.ts +++ b/src/core/_internal.ts @@ -5,7 +5,6 @@ export * from './operators'; export * as Files from './module-loading'; export * from './functions'; export { SernError } from './structures/enums'; -export { __Services } from './structures'; export { useContainerRaw } from './ioc/base'; export type _Module = { diff --git a/src/core/create-plugins.ts b/src/core/create-plugins.ts index 4db4ce6..1659e17 100644 --- a/src/core/create-plugins.ts +++ b/src/core/create-plugins.ts @@ -1,4 +1,4 @@ -import { CommandType, EventType, PluginType } from './structures'; +import { CommandType, EventType, PluginType } from './structures/enums'; import type { Plugin, PluginResult, EventArgs, CommandArgs } from '../types/core-plugin'; import type { ClientEvents } from 'discord.js'; import { err, ok } from './functions'; diff --git a/src/core/functions.ts b/src/core/functions.ts index 39ff159..b0d9ab6 100644 --- a/src/core/functions.ts +++ b/src/core/functions.ts @@ -11,7 +11,7 @@ import type { AutocompleteInteraction } from 'discord.js'; import { ApplicationCommandOptionType, InteractionType } from 'discord.js'; -import { PayloadType, PluginType } from './structures'; +import { PayloadType, PluginType } from './structures/enums'; import assert from 'assert'; import type { Payload } from '../types/utility'; diff --git a/src/core/id.ts b/src/core/id.ts index 91ab87b..3ef4669 100644 --- a/src/core/id.ts +++ b/src/core/id.ts @@ -1,5 +1,5 @@ import { ApplicationCommandType, ComponentType, Interaction, InteractionType } from 'discord.js'; -import { CommandType, EventType } from './structures'; +import { CommandType, EventType } from './structures/enums'; /** * Construct unique ID for a given interaction object. diff --git a/src/core/ioc/base.ts b/src/core/ioc/base.ts index 296f3f0..0e86dee 100644 --- a/src/core/ioc/base.ts +++ b/src/core/ioc/base.ts @@ -2,7 +2,7 @@ import * as assert from 'assert'; import type { CoreDependencies, DependencyConfiguration } from '../../types/ioc'; import { CoreContainer } from './container'; import { Result } from 'ts-results-es'; -import { __Services } from '../_internal'; +import * as __Services from '../structures/default-services'; import { AnyFunction } from '../../types/utility'; import type { Logging } from '../interfaces'; import type { UnpackFunction } from 'iti'; diff --git a/src/core/ioc/container.ts b/src/core/ioc/container.ts index 085f05b..d7afd0a 100644 --- a/src/core/ioc/container.ts +++ b/src/core/ioc/container.ts @@ -2,7 +2,7 @@ import { Container } from 'iti'; import type { Disposable } from '../interfaces'; import * as assert from 'node:assert'; import { Subject } from 'rxjs'; -import { __Services } from '../_internal'; +import * as __Services from '../structures/default-services'; import * as Hooks from './hooks'; import { EventEmitter } from 'node:events'; diff --git a/src/core/modules.ts b/src/core/modules.ts index ea361bb..c6d48ae 100644 --- a/src/core/modules.ts +++ b/src/core/modules.ts @@ -1,15 +1,16 @@ -import { ClientEvents } from 'discord.js'; -import { EventType } from '../core/structures'; +import type { ClientEvents } from 'discord.js'; +import { EventType } from '../core/structures/enums'; import type { AnyEventPlugin, } from '../types/core-plugin'; import type { InputCommand, InputEvent, } from '../types/core-modules'; -import { _Module, partitionPlugins } from './_internal'; +import { type _Module, partitionPlugins } from './_internal'; import type { Awaitable } from '../types/utility'; import callsites from 'callsites'; import * as Files from './module-loading' import * as Id from './id' + /** * @since 1.0.0 The wrapper function to define command modules for sern * @param mod @@ -40,7 +41,6 @@ export function commandModule(mod: InputCommand): _Module { export function eventModule(mod: InputEvent): _Module { const [onEvent, plugins] = partitionPlugins(mod.plugins); const initCallsite = callsites()[1].getFileName(); - console.log(initCallsite); if(!initCallsite) throw Error("initCallsite is null"); const { name, absPath } = Files.parseCallsite(initCallsite); mod.name ??= name; diff --git a/src/core/operators.ts b/src/core/operators.ts index 28f1c33..a15c185 100644 --- a/src/core/operators.ts +++ b/src/core/operators.ts @@ -26,7 +26,7 @@ import type { VoidResult } from './_internal'; * @param item */ export function filterMapTo(item: () => V): OperatorFunction { - return concatMap(shouldKeep => (shouldKeep ? of(item()) : EMPTY)); + return concatMap(keep => keep ? of(item()) : EMPTY); } interface PluginExecutable { diff --git a/src/core/presences.ts b/src/core/presences.ts index dbd5c6b..0031c1f 100644 --- a/src/core/presences.ts +++ b/src/core/presences.ts @@ -46,8 +46,7 @@ export const Presence = { }, /** * @example - * Presence - * .of({ + * Presence.of({ * activities: [ * { name: "Chilling out" } * ] diff --git a/src/core/structures/index.ts b/src/core/structures/index.ts deleted file mode 100644 index 1a715ae..0000000 --- a/src/core/structures/index.ts +++ /dev/null @@ -1,4 +0,0 @@ -export { CommandType, PluginType, PayloadType, EventType } from './enums'; -export * from './context'; -export * as __Services from './default-services'; - diff --git a/src/handlers/event-utils.ts b/src/handlers/event-utils.ts index 3fe3645..c72a64f 100644 --- a/src/handlers/event-utils.ts +++ b/src/handlers/event-utils.ts @@ -35,7 +35,8 @@ import type { ControlPlugin } from '../types/core-plugin'; import type { AnyModule, CommandMeta, CommandModule, Module, Processed } from '../types/core-modules'; import { EventEmitter } from 'node:events'; import * as assert from 'node:assert'; -import { CommandType, Context } from '../core/structures'; +import { Context } from '../core/structures/context'; +import { CommandType } from '../core/structures/enums' import type { Args } from '../types/utility'; import { inspect } from 'node:util' import { disposeAll } from '../core/ioc/base'; diff --git a/src/handlers/message-event.ts b/src/handlers/message-event.ts index 6342bc4..f04d971 100644 --- a/src/handlers/message-event.ts +++ b/src/handlers/message-event.ts @@ -15,8 +15,7 @@ function isNonBot(prefix: string) { function hasPrefix(prefix: string, content: string) { const prefixInContent = content.slice(0, prefix.length); - return ( - prefixInContent.localeCompare(prefix, undefined, { + return (prefixInContent.localeCompare(prefix, undefined, { sensitivity: 'accent', }) === 0 ); diff --git a/src/handlers/user-defined-events.ts b/src/handlers/user-defined-events.ts index d195c6b..9051374 100644 --- a/src/handlers/user-defined-events.ts +++ b/src/handlers/user-defined-events.ts @@ -1,5 +1,5 @@ import { ObservableInput } from 'rxjs'; -import { EventType } from '../core/structures'; +import { EventType } from '../core/structures/enums'; import { SernError } from '../core/_internal'; import { eventDispatcher } from './event-utils' import { Service } from '../core/ioc'; diff --git a/src/index.ts b/src/index.ts index d7d43fc..787eea1 100644 --- a/src/index.ts +++ b/src/index.ts @@ -53,5 +53,6 @@ export { export * from './core/presences' export * from './core/interfaces' export * from './core/create-plugins'; -export * from './core/structures'; +export { CommandType, PluginType, PayloadType, EventType } from './core/structures/enums'; +export { Context } from './core/structures/context'; export * from './core/ioc'; diff --git a/src/types/core-modules.ts b/src/types/core-modules.ts index 5151079..aa1b4b7 100644 --- a/src/types/core-modules.ts +++ b/src/types/core-modules.ts @@ -15,7 +15,8 @@ import type { UserContextMenuCommandInteraction, UserSelectMenuInteraction, } from 'discord.js'; -import type { CommandType, Context, EventType } from '../core/structures'; +import type { CommandType, EventType } from '../core/structures/enums'; +import { Context } from '../core/structures/context' import { AnyCommandPlugin, AnyEventPlugin, ControlPlugin, InitPlugin } from './core-plugin'; import { Awaitable, Args, SlashOptions, SernEventsMapping } from './utility';