feat(lib/discord/actions): export ToastActionCreators

This commit is contained in:
PalmDevs 2025-05-05 19:13:07 +07:00
parent 7789c26d86
commit 7cf05a6f53
No known key found for this signature in database
GPG key ID: 6FAE8F8677ACA8BA
2 changed files with 56 additions and 4 deletions

View file

@ -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<DiscordModules.Actions.ToastActionCreators>('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
}
})!

View file

@ -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 `<Text>`'s color prop
*/
iconColor?: string
containerStyle?: ViewStyle
}): void
close(): void
}
}
export namespace Components {