From 92ca9eb85919f7a0a276d322f1eecb7a5f69a4d1 Mon Sep 17 00:00:00 2001 From: Jacob Nguyen <76754747+jacoobes@users.noreply.github.com> Date: Wed, 3 Jul 2024 22:25:24 -0500 Subject: [PATCH] namespace presence types again --- src/core/presences.ts | 36 ++++++++++++++++++++---------------- src/handlers/presence.ts | 8 ++++---- src/sern.ts | 4 ++-- 3 files changed, 26 insertions(+), 22 deletions(-) diff --git a/src/core/presences.ts b/src/core/presences.ts index 4060fbc2..ee2850b7 100644 --- a/src/core/presences.ts +++ b/src/core/presences.ts @@ -3,16 +3,9 @@ import type { IntoDependencies } from "./ioc"; import type { Emitter } from "./interfaces"; type Status = 'online' | 'idle' | 'invisible' | 'dnd' -type PresenceReduce = (previous: PresenceResult) => PresenceResult; +type PresenceReduce = (previous: Presence.Result) => Presence.Result; + -export interface PresenceResult { - status?: Status; - afk?: boolean; - activities?: ActivitiesOptions[]; - shardId?: number[]; - repeat?: number | [Emitter, string]; - onRepeat?: (previous: PresenceResult) => PresenceResult; -} export const Presence = { /** @@ -20,13 +13,13 @@ export const Presence = { * Create a Presence module which **MUST** be put in a file called presence.(language-extension) * adjacent to the file where **Sern.init** is CALLED. */ - module : (conf: PresenceConfig) => conf, + module : (conf: Presence.Config) => conf, /** * Create a Presence body which can be either: * - once, the presence is activated only once. * - repeated, per cycle or event, the presence can be changed. */ - of : (root: Omit) => { + of : (root: Omit) => { return { /** * @example @@ -56,9 +49,20 @@ export const Presence = { }; } } +export declare namespace Presence { + type Config = { + inject?: [...T] + execute: (...v: IntoDependencies) => Presence.Result; + + } + + export interface Result { + status?: Status; + afk?: boolean; + activities?: ActivitiesOptions[]; + shardId?: number[]; + repeat?: number | [Emitter, string]; + onRepeat?: (previous: Result) => Result; + } +} -export type PresenceConfig = { - inject?: [...T] - execute: (...v: IntoDependencies) => PresenceResult; - -}; diff --git a/src/handlers/presence.ts b/src/handlers/presence.ts index f2528b6f..2282e3d3 100644 --- a/src/handlers/presence.ts +++ b/src/handlers/presence.ts @@ -1,11 +1,11 @@ import { concatMap, from, interval, of, map, scan, startWith, fromEvent, take } from "rxjs" -import { PresenceConfig, PresenceResult } from "../core/presences"; +import { Presence } from "../core/presences"; import { Services } from "../core/ioc"; import assert from "node:assert"; import * as Files from "../core/module-loading"; -type SetPresence = (conf: PresenceResult) => Promise +type SetPresence = (conf: Presence.Result) => Promise -const parseConfig = async (conf: Promise) => { +const parseConfig = async (conf: Promise) => { return conf.then(s => { if('repeat' in s) { const { onRepeat, repeat } = s; @@ -23,7 +23,7 @@ const parseConfig = async (conf: Promise) => { export const presenceHandler = (path: string, setPresence: SetPresence) => { const presence = Files - .importModule>(path) + .importModule>(path) .then(({ module }) => { //fetch services with the order preserved, passing it to the execute fn const fetchedServices = Services(...module.inject ?? []); diff --git a/src/sern.ts b/src/sern.ts index 85f8aab3..07f50a9d 100644 --- a/src/sern.ts +++ b/src/sern.ts @@ -11,7 +11,7 @@ import interactionHandler from './handlers/interaction'; import { presenceHandler } from './handlers/presence'; import { handleCrash } from './handlers/event-utils'; import { UnpackedDependencies } from './types/utility'; -import type { PresenceResult } from './core/presences'; +import type { Presence} from './core/presences'; interface Wrapper { commands: string; @@ -52,7 +52,7 @@ export function init(maybeWrapper: Wrapper = { commands: "./dist/commands" }) { const time = ((performance.now() - startTime) / 1000).toFixed(2); deps['@sern/logger']?.info({ message: `sern: registered in ${time} s` }); if(presencePath.exists) { - const setPresence = async (p: PresenceResult) => { + const setPresence = async (p: Presence.Result) => { return deps['@sern/client'].user?.setPresence(p); } presenceHandler(presencePath.path, setPresence).subscribe();