1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
|
From 3b8d2305b7f49f24b2b82d3bff35ce5aebbcc7fb Mon Sep 17 00:00:00 2001
From: 1024x2 <2pow11@gmail.com>
Date: Sat, 8 Jun 2024 23:11:43 +0100
Subject: [PATCH 3/6] Experiments: Re-add isStaff and staging banner
(it's funny)
---
src/plugins/experiments/index.tsx | 54 +++++++++++++++++++++++++++++--
1 file changed, 52 insertions(+), 2 deletions(-)
diff --git a/src/plugins/experiments/index.tsx b/src/plugins/experiments/index.tsx
index cf4dbf24..5a01ffad 100644
--- a/src/plugins/experiments/index.tsx
+++ b/src/plugins/experiments/index.tsx
@@ -16,19 +16,37 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
+import { definePluginSettings } from "@api/Settings";
import { disableStyle, enableStyle } from "@api/Styles";
import ErrorBoundary from "@components/ErrorBoundary";
import { ErrorCard } from "@components/ErrorCard";
import { Devs } from "@utils/constants";
+import { Logger } from "@utils/Logger";
import { Margins } from "@utils/margins";
-import definePlugin from "@utils/types";
+import definePlugin, { OptionType } from "@utils/types";
import { findByPropsLazy } from "@webpack";
-import { Forms, React } from "@webpack/common";
+import { Forms, React, UserStore } from "@webpack/common";
+import { User } from "discord-types/general";
import hideBugReport from "./hideBugReport.css?managed";
const KbdStyles = findByPropsLazy("key", "removeBuildOverride");
+const settings = definePluginSettings({
+ enableIsStaff: {
+ description: "Enable isStaff",
+ type: OptionType.BOOLEAN,
+ default: false,
+ restartNeeded: true
+ },
+ forceStagingBanner: {
+ description: "Whether to force Staging banner under user area.",
+ type: OptionType.BOOLEAN,
+ default: false,
+ restartNeeded: true
+ }
+});
+
export default definePlugin({
name: "Experiments",
description: "Enable Access to Experiments & other dev-only features in Discord!",
@@ -39,6 +57,7 @@ export default definePlugin({
Devs.BanTheNons,
Devs.Nuckyz
],
+ settings,
patches: [
{
@@ -69,12 +88,43 @@ export default definePlugin({
match: /\i\.isStaff\(\)/,
replace: "true"
}
+ },
+ {
+ find: '"isStaff",',
+ predicate: () => settings.store.enableIsStaff,
+ replacement: [
+ {
+ match: /(?<=>)(\i)\.hasFlag\((\i\.\i)\.STAFF\)(?=})/,
+ replace: (_, user, flags) => `$self.isStaff(${user},${flags})`
+ },
+ {
+ match: /hasFreePremium\(\){return this.isStaff\(\)\s*?\|\|/,
+ replace: "hasFreePremium(){return ",
+ }
+ ]
+ },
+ {
+ find: ".Messages.DEV_NOTICE_STAGING",
+ predicate: () => settings.store.forceStagingBanner,
+ replacement: {
+ match: /window\.GLOBAL_ENV\.RELEASE_CHANNEL/,
+ replace: "\"staging\""
+ }
}
],
start: () => enableStyle(hideBugReport),
stop: () => disableStyle(hideBugReport),
+ isStaff(user: User, flags: any) {
+ try {
+ return UserStore.getCurrentUser()?.id === user.id || user.hasFlag(flags.STAFF);
+ } catch (err) {
+ new Logger("Experiments").error(err);
+ return user.hasFlag(flags.STAFF);
+ }
+ },
+
settingsAboutComponent: () => {
const isMacOS = navigator.platform.includes("Mac");
const modKey = isMacOS ? "cmd" : "ctrl";
--
2.45.2
|