From ad256fd9f348781eac32bef83cbf75fb0f21c438 Mon Sep 17 00:00:00 2001 From: PalmDevs Date: Sat, 14 Jun 2025 17:58:20 +0700 Subject: [PATCH] feat(lib/discord/common): export `utils` --- lib/discord/package.json | 3 +++ lib/discord/src/common/index.ts | 1 + lib/discord/src/common/utils.ts | 33 +++++++++++++++++++++++++++++++++ lib/discord/src/types/index.ts | 13 +++++++++++++ 4 files changed, 50 insertions(+) create mode 100644 lib/discord/src/common/utils.ts diff --git a/lib/discord/package.json b/lib/discord/package.json index ec465af..5ab11e5 100644 --- a/lib/discord/package.json +++ b/lib/discord/package.json @@ -15,6 +15,9 @@ "./common/flux": { "default": "./src/common/flux.ts" }, + "./common/utils": { + "default": "./src/common/utils.ts" + }, "./design": { "default": "./src/design.ts" }, diff --git a/lib/discord/src/common/index.ts b/lib/discord/src/common/index.ts index 12601d8..cb448d4 100644 --- a/lib/discord/src/common/index.ts +++ b/lib/discord/src/common/index.ts @@ -11,6 +11,7 @@ import type { DiscordModules } from '../types' export { AppStartPerformance } from '../preinit' export * as Flux from './flux' +export * as utils from './utils' const { loose, relative } = byDependencies diff --git a/lib/discord/src/common/utils.ts b/lib/discord/src/common/utils.ts new file mode 100644 index 0000000..6a49ba2 --- /dev/null +++ b/lib/discord/src/common/utils.ts @@ -0,0 +1,33 @@ +import { + byDependencies, + byName, + preferExports, +} from '@revenge-mod/modules/finders/filters' +import { lookupModule } from '@revenge-mod/modules/finders/lookup' +import { proxify } from '@revenge-mod/utils/proxy' +import type { DiscordModules } from '../types' + +const [, _createClassModuleId] = lookupModule(byName('_createClass')) +const [, _classCallCheckModuleId] = lookupModule(byName('_classCallCheck')) + +export let TypedEventEmitter: typeof DiscordModules.Utils.TypedEventEmitter = + proxify(() => { + const [module] = lookupModule( + preferExports( + byName( + 'TypedEventEmitter', + ), + byDependencies([ + _classCallCheckModuleId, + _createClassModuleId, + [], + 2, + ]), + ), + { + includeUninitialized: true, + }, + ) + + if (module) return (TypedEventEmitter = module) + })! diff --git a/lib/discord/src/types/index.ts b/lib/discord/src/types/index.ts index 05b6b5c..d46a925 100644 --- a/lib/discord/src/types/index.ts +++ b/lib/discord/src/types/index.ts @@ -1,3 +1,4 @@ +import { EventEmitter } from 'node:events' import type { ComponentProps, ComponentType, FC, ReactNode } from 'react' import type { ImageSourcePropType, @@ -626,4 +627,16 @@ export namespace DiscordModules { | StaticSettingsItem } } + + export namespace Utils { + export namespace TypedEventEmitter { + export type DefaultEventMap = [never] + export type EventMap = Record | DefaultEventMap + } + + export class TypedEventEmitter< + T extends + TypedEventEmitter.EventMap = TypedEventEmitter.DefaultEventMap, + > extends EventEmitter {} + } }