1+
12import { findByName } from "@vendetta/metro" ;
23import { after } from "@vendetta/patcher" ;
3- import { ReactNative as RN , React } from "@vendetta/metro/common" ;
4-
5- import Badges from "./Icons" ;
6- import Settings from "./Settings" ;
7- import { storage } from "@vendetta/plugin" ;
4+ // import Badges from "./Icons";
5+ // import Settings from "./Settings";
6+ // import { storage } from "@vendetta/plugin";
87
9- import { BadgeProps , CustomBadges , BadgeCache } from "./types" ;
10- import { BadgeComponent } from "./badgeComponent" ;
8+ import { CustomBadges , BadgeCache } from "./types" ;
119
1210
13- const { View } = RN ;
11+ const bunny = window . bunny . api . react . jsx
1412
1513const cache = new Map < string , BadgeCache > ( ) ;
1614const REFRESH_INTERVAL = 1000 * 60 * 30 ;
1715
16+ const badgeModule = findByName ( "useBadges" , false ) ;
17+
18+
19+
1820let unpatch ;
1921let unpatch2 ;
2022let cachUser ;
2123export default {
2224 onLoad : ( ) => {
23- const profileBadges = findByName ( "ProfileBadges" , false ) ;
24- unpatch = after ( "default" , profileBadges , ( args , res ) => {
25- let mem = res ;
26-
27- const [ , updateForce ] = React . useReducer ( x => x = ! x , false ) ;
2825
29- const user = args [ 0 ] ?. user ;
30- if ( user === undefined ) return ;
26+ const badgeProps = { } as Record < string , any > ;
3127
32- cachUser = cache . get ( user . id ) ;
33- if ( cachUser === undefined ) {
34- fetchbadges ( user . id , updateForce ) ;
35- return ;
28+ bunny . onJsxCreate ( "ProfileBadge" , ( component , ret ) => {
29+ if ( ret . props . id ?. startsWith ( "gb-" ) ) {
30+ const badgePropsCache = badgeProps [ ret . props . id ] ;
31+ if ( badgePropsCache ) {
32+ ret . props . source = badgePropsCache . source ;
33+ ret . props . label = badgePropsCache . label ;
34+ ret . props . id = badgePropsCache . id ;
35+ }
3636 }
37+ } )
3738
38- const style = mem ?. props ?. style
39- const { replugged } = cachUser ?. badges ;
40- const colors = `#${ replugged ?. custom ?. color || '7289da' } `
41-
42- // Credits here to @acquitelol
43- // https://github.com/enmity-mod/enmity/blob/8ff15a8fffc5a1ad4d41c5e8f8a02e6876a760ec/src/core/patches/badges.tsx#L81-L95
44- if ( ! mem ) {
45- mem = < View
46- style = { [ style , {
47- flexDirection : "row" ,
48- flexWrap : 'wrap' ,
49- alignItems : 'flex-end' ,
50- justifyContent : 'flex-end' ,
51- paddingVertical : 2
52- } ] }
53- accessibilityRole = { "list" }
54- accessibilityLabel = { "User Badges" }
55- /> ;
56-
57- mem . props . children = [ ] ;
39+ bunny . onJsxCreate ( "RenderBadge" , ( component , ret ) => {
40+ if ( ret . props . id ?. startsWith ( "gb-" ) ) {
41+ const badgePropsCache = badgeProps [ ret . props . id ] ;
42+ if ( badgePropsCache ) {
43+ Object . assign ( ret . props , badgePropsCache ) ;
44+ }
5845 }
59- //
46+ } )
6047
48+ unpatch = after ( "default" , badgeModule , ( [ user ] , result ) => {
49+ if ( user === null ) return ;
50+ cachUser = cache . get ( user . userId ) ;
6151
62- const pushBadge = ( { name, image, custom = false } : BadgeProps ) => {
63- const RenderableBadge = ( ) => < BadgeComponent
64- custom = { custom }
65- name = { name }
66- image = { image }
67- size = { Array . isArray ( style ) ? style ?. find ( r => r . paddingVertical && r . paddingHorizontal ) ? 16 : 22 : 16 }
68- margin = { Array . isArray ( style ) ? 4 : 6 }
69- /> ;
52+ if ( cachUser === undefined ) {
53+ fetchbadges ( user . userId )
54+ return ;
55+ }
7056
71- const pushOrUnpush = storage . left ;
72- if ( mem ?. props ?. badges ) pushOrUnpush ? mem . props . badges = [ < RenderableBadge /> , ...mem . props . badges ] : mem . props . badges = [ ...mem . props . badges , < RenderableBadge /> ] ;
73- else pushOrUnpush ? mem . props . children = [ < RenderableBadge /> , ...mem . props . children ] : mem . props . children = [ ...mem . props . children , < RenderableBadge /> ] ;
57+ const pushBadges = ( badge ) => {
58+ result . push ( badge ) ;
7459 } ;
7560
76- Object . entries ( cachUser ?. badges ) . forEach ( ( [ key , value ] ) : any => {
77- if ( storage . mods ) {
78- if ( key !== "customBadgesArray" ) return ;
79- }
80- if ( storage . customs ) {
81- if ( key === "customBadgesArray" ) return ;
82- }
61+ Object . entries ( cachUser . badges ) . forEach ( ( [ key , value ] ) : any => {
62+ let badgeId = `gb-${ key } ` ;
8363 switch ( key ) {
8464 case "customBadgesArray" :
8565 if ( value ) {
86- value . badges . map ( ( badge : CustomBadges ) => {
87- pushBadge ( {
88- name : badge . name ,
89- image : badge . badge ,
90- } ) ;
91- } ) ;
92- }
93- break ;
94- case "aliu" :
95- if ( value ?. dev ) {
96- pushBadge ( {
97- name : "Aliucord Dev" ,
98- image : "https://cdn.discordapp.com/emojis/860165259117199401.webp" ,
99- } ) ;
100- }
101- if ( value ?. donor ) {
102- pushBadge ( {
103- name : "Aliucord Donor" ,
104- image : "https://cdn.discordapp.com/emojis/859801776232202280.webp" ,
105- } ) ;
106- }
107- if ( value ?. contributor ) {
108- pushBadge ( {
109- name : "Aliucord Contributor" ,
110- image : "https://cdn.discordapp.com/emojis/886587553187246120.webp" ,
111- } ) ;
112- }
113- break ;
114- case "bd" :
115- if ( value ?. dev ) {
116- pushBadge ( {
117- name : "BD Dev" ,
118- image : "" ,
119- custom : < Badges . bdDevs />
120- } ) ;
121- }
122- break ;
123- case "enmity" :
124- if ( value ?. supporter ?. data ) {
125- pushBadge ( {
126- name : "Enmity Supporter" ,
127- image : value ?. supporter ?. data . url . dark ,
128-
129- } ) ;
66+ value . badges . forEach ( ( badge ) => {
67+ badgeId = `gb-${ key } -${ badge . name } ` ;
68+ badgeProps [ badgeId ] = {
69+ id : badgeId ,
70+ source : { uri : badge . badge } ,
71+ label : badge . name ,
72+ userId : user . userId ,
73+ }
74+ pushBadges ( {
75+ id : badgeId ,
76+ description : badge . name ,
77+ icon : "dummy" ,
78+ } )
79+ } )
13080 }
131- if ( value ?. staff ?. data ) {
132- pushBadge ( {
133- name : "Enmity Staff" ,
134- image : value ?. staff ?. data . url . dark ,
135- } ) ;
136- }
137- if ( value ?. dev ?. data ) {
138- pushBadge ( {
139- name : "Enmity Dev" ,
140- image : value ?. dev ?. data . url . dark ,
141- } ) ;
142- }
143- if ( value ?. contributor ?. data ) {
144- pushBadge ( {
145- name : "Enmity Contributor" ,
146- image : value ?. contributor ?. data . url . dark ,
147- } ) ;
148- }
149- if ( value [ user . id ] ?. data ) {
150- pushBadge ( {
151- name : "Enmity User" ,
152- image : value [ user . id ] ?. data . url . dark ,
153- } ) ;
154- }
155- break ;
156- case "goosemod" :
157- if ( value ?. sponsor ) {
158- pushBadge ( {
159- name : "GooseMod Sponsor" ,
160- image : "https://goosemod.com/img/goose_globe.png" ,
161- } ) ;
162- }
163- if ( value ?. dev ) {
164- pushBadge ( {
165- name : "GooseMod Dev" ,
166- image : "https://goosemod.com/img/goose_glitch.jpg" ,
167- } ) ;
168- }
169- if ( value ?. translator ) {
170- pushBadge ( {
171- name : "GooseMod Translator" ,
172- image : "https://goosemod.com/img/goose_globe.png" ,
173- } ) ;
174- }
175- break ;
176- case "replugged" :
177- if ( value ?. developer ) {
178- pushBadge ( {
179- name : "Replugged Developer" ,
180- image : "" ,
181- custom : < Badges . Developer color = { colors } />
182- } ) ;
183- }
184- if ( value ?. staff ) {
185- pushBadge ( {
186- name : "Replugged Staff" ,
187- image : "" ,
188- custom : < Badges . Staff color = { colors } />
189- } ) ;
190- }
191- if ( value ?. support ) {
192- pushBadge ( {
193- name : "Replugged Support" ,
194- image : "" ,
195- custom : < Badges . Support color = { colors } />
196- } ) ;
197- }
198- if ( value ?. contributor ) {
199- pushBadge ( {
200- name : "Replugged Contributor" ,
201- image : "" ,
202- custom : < Badges . Contributor color = { colors } />
203- } ) ;
204- }
205- if ( value ?. translator ) {
206- pushBadge ( {
207- name : "Replugged Translator" ,
208- image : "" ,
209- custom : < Badges . Translator color = { colors } />
210- } ) ;
211- }
212- if ( value ?. hunter ) {
213- pushBadge ( {
214- name : "Replugged Hunter" ,
215- image : "" ,
216- custom : < Badges . BugHunter color = { colors } />
217- } ) ;
218- }
219- if ( value ?. early ) {
220- pushBadge ( {
221- name : "Replugged Early Access" ,
222- image : "" ,
223- custom : < Badges . EarlyUser color = { colors } />
224- } ) ;
225- }
226- if ( value ?. booster ) {
227- pushBadge ( {
228- name : "Replugged Booster" ,
229- image : "" ,
230- custom : < Badges . Booster color = { colors } />
231- } ) ;
232- }
233- if ( value ?. custom ?. name ) {
234- pushBadge ( {
235- name : value . custom . name ,
236- image : value . custom . icon ,
237- } ) ;
238- }
239- break ;
240- case "vencord" :
241- if ( value ?. contributor ) {
242- pushBadge ( {
243- name : "Vencord Contributor" ,
244- image : "https://vencord.dev/assets/favicon.png" ,
245- } ) ;
246- }
247- if ( Boolean ( value ?. cutie ) ) {
248- value . cutie . map ( ( cutie ) => {
249- pushBadge ( {
250- name : cutie . tooltip ,
251- image : cutie . badge ,
252- } ) ;
253- } ) ;
254- }
255- break ;
256- default :
257- break ;
25881 }
259- } )
26082
83+ } )
26184 } ) ;
85+
26286 } ,
26387 onUnload : ( ) => {
26488 unpatch ?.( ) ;
265- unpatch2 ?.( ) ;
89+ // unpatch2?.();
26690 } ,
267- settings : Settings
91+ // settings: Settings
26892} ;
26993
27094
271- async function fetchbadges ( userId : string , updateForce ) {
95+
96+ async function fetchbadges ( userId : string ) {
27297 if (
27398 ! cache . has ( userId ) ||
27499 cache . get ( userId ) ! . lastFetch + REFRESH_INTERVAL < Date . now ( )
@@ -284,7 +109,6 @@ async function fetchbadges(userId: string, updateForce) {
284109 : ( cache . delete ( userId ) , { badges : body , lastFetch : Date . now ( ) } ) ;
285110
286111 cache . set ( userId , result ) ;
287- updateForce ( ) ;
288112
289113 }
290114
0 commit comments