diff --git a/src/plugins/staff-settings/index.ts b/src/plugins/staff-settings/index.ts deleted file mode 100644 index 03d3337..0000000 --- a/src/plugins/staff-settings/index.ts +++ /dev/null @@ -1,35 +0,0 @@ -import { byProps } from '@revenge-mod/modules/finders/filters' -import { waitForModules } from '@revenge-mod/modules/finders/wait' - -import { instead } from '@revenge-mod/patcher' - -import { InternalPluginFlags, registerPlugin } from '@revenge-mod/plugins/_' -import { PluginFlags } from '@revenge-mod/plugins/constants' - -registerPlugin( - { - id: 'revenge.staff-settings', - name: 'Staff Settings', - description: "Allows accessing Discord's Staff Settings.", - author: 'Revenge', - icon: 'StaffBadgeIcon', - }, - { - init({ cleanup }) { - const unsub = waitForModules(byProps('isStaffEnv'), UserStoreUtils => { - unsub() - cleanup(instead(UserStoreUtils, 'isStaffEnv', () => true)) - }) - - cleanup(unsub) - }, - start({ plugin }) { - if (plugin.flags & PluginFlags.EnabledLate) plugin.stop() - }, - stop({ plugin }) { - plugin.flags |= PluginFlags.ReloadRequired - }, - }, - PluginFlags.Enabled, - InternalPluginFlags.Internal, -) diff --git a/src/plugins/staff-settings/index.tsx b/src/plugins/staff-settings/index.tsx new file mode 100644 index 0000000..ca6359d --- /dev/null +++ b/src/plugins/staff-settings/index.tsx @@ -0,0 +1,67 @@ +import { AlertActionCreators } from '@revenge-mod/discord/actions' +import { getStore, Stores } from '@revenge-mod/discord/common/flux' +import { Design } from '@revenge-mod/discord/design' + +import { byProps } from '@revenge-mod/modules/finders/filters' +import { getModule } from '@revenge-mod/modules/finders/get' + +import { instead } from '@revenge-mod/patcher' + +import { InternalPluginFlags, registerPlugin } from '@revenge-mod/plugins/_' +import { PluginFlags } from '@revenge-mod/plugins/constants' + +registerPlugin( + { + id: 'revenge.staff-settings', + name: 'Staff Settings', + description: "Allows accessing Discord's Staff Settings.", + author: 'Revenge', + icon: 'StaffBadgeIcon', + }, + { + start({ cleanup, logger, plugin }) { + if (plugin.flags & PluginFlags.EnabledLate) showNoticeAlert() + + function reinitDEStore() { + cleanup( + getStore<{ initialize(): void }>('DeveloperExperimentStore', store => { + logger.log('Reinitializing DeveloperExperimentStore to apply changes...') + + setTimeout(() => { + const unpatch = instead(Object, 'defineProperties', () => {}) + store.initialize() + unpatch() + }) + }), + ) + } + + cleanup( + getModule(byProps('isStaffEnv'), UserStoreUtils => { + logger.log('Patching UserStoreUtils...') + + cleanup( + instead(UserStoreUtils, 'isStaffEnv', ([user]) => user === Stores.UserStore.getCurrentUser()), + ) + + reinitDEStore() + }), + reinitDEStore, + showNoticeAlert, + ) + }, + }, + PluginFlags.Enabled, + InternalPluginFlags.Internal, +) + +function showNoticeAlert() { + AlertActionCreators.openAlert( + 'staff-settings-notice', + } + />, + ) +}