diff --git a/lib/discord/src/actions.ts b/lib/discord/src/actions.ts index 131c44a..9d88786 100644 --- a/lib/discord/src/actions.ts +++ b/lib/discord/src/actions.ts @@ -1,9 +1,19 @@ -import { proxify } from '@revenge-mod/utils/proxy' -import { lookupModule } from '../../modules/src/finders/lookup' -import { byDependencies, byProps, moduleStateAware, relativeDep } from '@revenge-mod/modules/finders/filters' -import type { DiscordModules } from '../types' +import { lookupModule, lookupModules } from '@revenge-mod/modules/finders' +import { + byDependencies, + byProps, + every, + moduleStateAware, + relativeDep, + withoutProps, +} from '@revenge-mod/modules/finders/filters' + import { ReactJsxRuntimeModuleId, ReactModuleId } from '@revenge-mod/react' +import { proxify } from '@revenge-mod/utils/proxy' + +import type { DiscordModules } from '../types' + export let AlertActionCreators: DiscordModules.Actions.AlertActionCreators = proxify( () => { // ID: 3667 @@ -35,3 +45,30 @@ export let AlertActionCreators: DiscordModules.Actions.AlertActionCreators = pro hint: 'object', }, )! + +export let ToastActionCreators: DiscordModules.Actions.ToastActionCreators = proxify(() => { + // Many other modules share the same dependencies, the second yielded should be the correct module. + // [684, 2] + + // Dispatcher.tsx (ID: 684) + // [685, 652, 606, 585, 806, 2] + + const generator = lookupModules( + moduleStateAware( + every(byProps('open'), withoutProps('init')), + byDependencies([[relativeDep(1), undefined, undefined, undefined, undefined, 2], 2]), + ), + { + includeUninitialized: true, + }, + ) + + for (const module of generator) + if (module.open.length === 1) { + // This allows the Proxy instance to be garbage collected + // after the module is initialized. + ToastActionCreators = module + gc() + return module + } +})! diff --git a/lib/discord/types/index.ts b/lib/discord/types/index.ts index 5aba6c1..d7acacf 100644 --- a/lib/discord/types/index.ts +++ b/lib/discord/types/index.ts @@ -142,6 +142,21 @@ export namespace DiscordModules { // TODO useAlertStore(): unknown } + + export interface ToastActionCreators { + open(options: { + key: string + content?: string + icon?: number | FC + IconComponent?: FC + /** + * The icon's color, same string format as ``'s color prop + */ + iconColor?: string + containerStyle?: ViewStyle + }): void + close(): void + } } export namespace Components {