Skip to content

Commit fa8fcd9

Browse files
committed
(TESTING) literally porting aliucord badge system JUST TO TEST!!!!!!! WILL REMOVE SOON
1 parent 198f26b commit fa8fcd9

File tree

7 files changed

+134
-58
lines changed

7 files changed

+134
-58
lines changed

dist/vendetta.js

Lines changed: 13 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import initQuickInstall from "@ui/quickInstall";
77
import initSafeMode from "@ui/safeMode";
88
import initSettings from "@ui/settings";
99
import initFixes from "@lib/fixes";
10-
import { initBadges } from "@/lib/badge/badges";
10+
import { patchBadges } from "@/lib/badge/badges";
1111
import logger from "@lib/logger";
1212
import windowObject from "@lib/windowObject";
1313
import { initTweaks } from "./lib/tweak";
@@ -23,7 +23,7 @@ export default async () => {
2323
initSafeMode(),
2424
initSettings(),
2525
initQuickInstall(),
26-
initBadges(),
26+
patchBadges(), // this is SO gonna break lmao
2727
]);
2828
window.vendetta = await windowObject(unloads);
2929
unloads.push(await initPlugins());

src/lib/badge/badges.ts

Lines changed: 0 additions & 25 deletions
This file was deleted.

src/lib/badge/badges.tsx

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
/*
2+
YES I KNOW THIS IS FROM ALIUCORD AND I DO NOT PLAN ON KEEPING IT LIKE THIS
3+
THIS IS JUST A CONCEPT ON TESTING BADGES
4+
5+
YES I KNOW THIS IS FROM ALIUCORD AND I DO NOT PLAN ON KEEPING IT LIKE THIS
6+
THIS IS JUST A CONCEPT ON TESTING BADGES
7+
8+
YES I KNOW THIS IS FROM ALIUCORD AND I DO NOT PLAN ON KEEPING IT LIKE THIS
9+
THIS IS JUST A CONCEPT ON TESTING BADGES
10+
11+
YES I KNOW THIS IS FROM ALIUCORD AND I DO NOT PLAN ON KEEPING IT LIKE THIS
12+
THIS IS JUST A CONCEPT ON TESTING BADGES
13+
*/
14+
15+
import { after } from "../patcher";
16+
import { ReactNative as RN, React, stylesheet, toasts } from "../metro/common";
17+
import { findByName } from "../metro/filters";
18+
19+
const { View, Image, TouchableOpacity } = RN;
20+
21+
interface BadgeOwner {
22+
roles: string[];
23+
custom?: Badge[];
24+
}
25+
26+
interface Badge {
27+
url: string;
28+
text: string;
29+
}
30+
31+
const roles = {
32+
"developer": {
33+
"url": "https://raw.githubusercontent.com/Opti-mod/assets/main/opti_cog.PNG",
34+
"text": "Opti Developer"
35+
},
36+
};
37+
38+
const url = "https://raw.githubusercontent.com/Opti-mod/Opti/rewrite/src/lib/badge/users.ts";
39+
40+
export function patchBadges()
41+
{
42+
const ProfileBadges = findByName("ProfileBadges", false);
43+
44+
const styles = stylesheet.createThemedStyleSheet({
45+
container: {
46+
flexDirection: "row",
47+
alignItems: "center",
48+
flexWrap: "wrap",
49+
justifyContent: "flex-end",
50+
},
51+
img: {
52+
width: 24,
53+
height: 24,
54+
resizeMode: "contain",
55+
marginHorizontal: 4
56+
}
57+
});
58+
59+
const cache: Record<string, Badge[]> = {};
60+
61+
after(ProfileBadges, "default", (ctx : any) => {
62+
const [, forceUpdate] = React.useReducer(x => x = !x, false);
63+
64+
const user = ctx.args[0]?.user;
65+
if (user === undefined) return;
66+
67+
const badges = cache[user.id];
68+
if (badges === undefined) {
69+
fetch(`${url}/users/${user.id}.json`)
70+
.then(r => r.json())
71+
.then((badges: BadgeOwner) => {
72+
cache[user.id] = [...badges.roles.map(it => roles[it]), ...(badges.custom ?? [])];
73+
cache[user.id].length && forceUpdate();
74+
});
75+
return;
76+
}
77+
78+
const renderedBadgesView = (
79+
<View key="opti-badges" style={styles.container}>
80+
{badges.map(badge => (
81+
<TouchableOpacity key={badge.url} onPress={() => {
82+
toasts.open({
83+
content: badge.text,
84+
source: { uri: badge.url }
85+
});
86+
}}>
87+
<Image source={{ uri: badge.url }} style={styles.img} />
88+
</TouchableOpacity>
89+
))}
90+
</View>
91+
);
92+
93+
if (!ctx.result) return renderedBadgesView;
94+
95+
ctx.result.props.children.push(renderedBadgesView);
96+
return;
97+
});
98+
}

src/ui/components/ErrorBoundary.tsx

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
import { ErrorBoundaryProps } from "@types";
1+
import { ButtonColors, ErrorBoundaryProps } from "@types";
22
import { React, ReactNative as RN, stylesheet, clipboard } from "@metro/common";
33
import { Forms, Button, Codeblock, } from "@ui/components";
44
import { sendCrashReport } from "@lib/webhook";
5+
import { showConfirmationAlert } from "../alerts";
56

67
interface ErrorBoundaryState {
78
hasErr: boolean;
@@ -54,22 +55,34 @@ export default class ErrorBoundary extends React.Component<ErrorBoundaryProps, E
5455
onPress={() => this.setState({ hasErr: false, errText: undefined })}
5556
text="Retry"
5657
/>
57-
58+
<Forms.FormText style={styles.br}> </Forms.FormText>
5859
<Button
5960
color={Button.Colors.BRAND}
6061
size={Button.Sizes.MEDIUM}
6162
look={Button.Looks.FILLED}
6263
onPress={() => clipboard.setString("" + this.state.errStack)}
6364
text="Copy Error to Clipboard"
6465
/>
65-
66+
<Forms.FormText style={styles.br}> </Forms.FormText>
6667
<Button
6768
color={Button.Colors.BRAND}
6869
size={Button.Sizes.SMALL}
6970
look={Button.Looks.FILLED}
70-
onPress={() => sendCrashReport(
71-
"Crash Report Caused: " + this.state.errStack
72-
)}
71+
onPress={() =>
72+
showConfirmationAlert({
73+
title: "Are you sure?",
74+
content: `Sending a crash report will include the following details.
75+
- Username / UserID
76+
- Crash Stack
77+
- Time of Crash`,
78+
confirmText: "Send Report",
79+
cancelText: "Cancel",
80+
confirmColor: ButtonColors.RED,
81+
onConfirm: () => {
82+
sendCrashReport("This is a placeholder.");
83+
}
84+
})
85+
}
7386
text="Send Crash Report"
7487
/>
7588
</RN.ScrollView>

src/ui/settings/data.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ export const getScreens = (youKeys = false): Screen[] => [
4646
},
4747
{
4848
key: formatKey("VendettaSettingsTM", youKeys),
49-
title: "Tweak Manager",
49+
title: "Tweaks",
5050
icon: "ic_hammer_and_chisel_24px",
5151
render: TweakManager,
5252
},

src/ui/settings/pages/General.tsx

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,7 @@ export default function General() {
103103
showToast("Copied Opti version to clipboard!", getAssetIDByName("ic_badge_staff"));
104104
}
105105
}
106-
/>
107-
106+
/>
108107
<FormDivider />
109108
<FormRow
110109
label="Discord Server"
@@ -121,18 +120,6 @@ export default function General() {
121120
/>
122121
</FormSection>
123122
<FormSection title="Actions">
124-
<FormRow
125-
label="Tweak Manager"
126-
subLabel={`Manage Opti's built in tweaks.`}
127-
leading={<FormRow.Icon source={{ uri: 'https://raw.githubusercontent.com/Opti-mod/assets/main/Opti%202.png' }} /> }
128-
onPress={() =>
129-
navigation.push("VendettaCustomPage", {
130-
title: "Tweak Manager",
131-
render: TweakManager,
132-
})
133-
}
134-
/>
135-
<FormDivider />
136123
<FormRow
137124
label="Reload Discord"
138125
subLabel={`This has a chance of crashing instead of directly reloading.`}

0 commit comments

Comments
 (0)