2020-10-20 23:25:34 +02:00
/ * *
2021-07-11 18:46:40 +02:00
* @ name ShowBadgesInChat
2021-03-05 13:26:41 +01:00
* @ author DevilBro
2020-10-20 23:25:34 +02:00
* @ authorId 278543574059057154
2024-09-10 21:45:40 +02:00
* @ version 2.0 . 8
2021-07-11 18:46:40 +02:00
* @ description Displays Badges ( Nitro , Hypesquad , etc ... ) in the Chat / MemberList / DMList
2020-10-20 23:25:34 +02:00
* @ invite Jx3TjNS
2020-11-19 16:45:36 +01:00
* @ donate https : //www.paypal.me/MircoWittrien
* @ patreon https : //www.patreon.com/MircoWittrien
2021-03-09 15:10:55 +01:00
* @ website https : //mwittrien.github.io/
2021-07-11 18:46:40 +02:00
* @ source https : //github.com/mwittrien/BetterDiscordAddons/tree/master/Plugins/ShowBadgesInChat/
* @ updateUrl https : //mwittrien.github.io/BetterDiscordAddons/Plugins/ShowBadgesInChat/ShowBadgesInChat.plugin.js
2020-10-20 23:25:34 +02:00
* /
2018-10-16 21:33:23 +02:00
2020-09-19 20:49:33 +02:00
module . exports = ( _ => {
2022-09-01 14:40:11 +02:00
const changeLog = {
2022-09-02 12:37:10 +02:00
2020-09-19 20:49:33 +02:00
} ;
2021-02-05 21:45:34 +01:00
2022-02-05 21:14:17 +01:00
return ! window . BDFDB _Global || ( ! window . BDFDB _Global . loaded && ! window . BDFDB _Global . started ) ? class {
2022-09-01 14:55:22 +02:00
constructor ( meta ) { for ( let key in meta ) this [ key ] = meta [ key ] ; }
getName ( ) { return this . name ; }
getAuthor ( ) { return this . author ; }
getVersion ( ) { return this . version ; }
getDescription ( ) { return ` The Library Plugin needed for ${ this . name } is missing. Open the Plugin Settings to download it. \n \n ${ this . description } ` ; }
2021-02-01 17:13:13 +01:00
downloadLibrary ( ) {
2023-11-18 18:31:04 +01:00
BdApi . Net . fetch ( "https://mwittrien.github.io/BetterDiscordAddons/Library/0BDFDB.plugin.js" ) . then ( r => {
if ( ! r || r . status != 200 ) throw new Error ( ) ;
else return r . text ( ) ;
} ) . then ( b => {
if ( ! b ) throw new Error ( ) ;
else return require ( "fs" ) . writeFile ( require ( "path" ) . join ( BdApi . Plugins . folder , "0BDFDB.plugin.js" ) , b , _ => BdApi . showToast ( "Finished downloading BDFDB Library" , { type : "success" } ) ) ;
} ) . catch ( error => {
BdApi . alert ( "Error" , "Could not download BDFDB Library Plugin. Try again later or download it manually from GitHub: https://mwittrien.github.io/downloader/?library" ) ;
2021-02-01 17:13:13 +01:00
} ) ;
}
2020-09-19 20:49:33 +02:00
2021-01-06 12:38:36 +01:00
load ( ) {
2020-11-19 16:51:14 +01:00
if ( ! window . BDFDB _Global || ! Array . isArray ( window . BDFDB _Global . pluginQueue ) ) window . BDFDB _Global = Object . assign ( { } , window . BDFDB _Global , { pluginQueue : [ ] } ) ;
2020-09-19 20:49:33 +02:00
if ( ! window . BDFDB _Global . downloadModal ) {
window . BDFDB _Global . downloadModal = true ;
2022-09-01 14:55:22 +02:00
BdApi . showConfirmationModal ( "Library Missing" , ` The Library Plugin needed for ${ this . name } is missing. Please click "Download Now" to install it. ` , {
2020-09-19 20:49:33 +02:00
confirmText : "Download Now" ,
cancelText : "Cancel" ,
onCancel : _ => { delete window . BDFDB _Global . downloadModal ; } ,
2020-09-20 08:15:13 +02:00
onConfirm : _ => {
delete window . BDFDB _Global . downloadModal ;
2021-02-01 17:13:13 +01:00
this . downloadLibrary ( ) ;
2020-09-20 08:15:13 +02:00
}
2020-09-19 20:49:33 +02:00
} ) ;
}
2022-09-01 14:55:22 +02:00
if ( ! window . BDFDB _Global . pluginQueue . includes ( this . name ) ) window . BDFDB _Global . pluginQueue . push ( this . name ) ;
2020-10-09 21:09:35 +02:00
}
2021-01-06 12:38:36 +01:00
start ( ) { this . load ( ) ; }
stop ( ) { }
getSettingsPanel ( ) {
2020-11-28 23:12:09 +01:00
let template = document . createElement ( "template" ) ;
2022-09-01 14:55:22 +02:00
template . innerHTML = ` <div style="color: var(--header-primary); font-size: 16px; font-weight: 300; white-space: pre; line-height: 22px;">The Library Plugin needed for ${ this . name } is missing. \n Please click <a style="font-weight: 500;">Download Now</a> to install it.</div> ` ;
2021-02-01 17:13:13 +01:00
template . content . firstElementChild . querySelector ( "a" ) . addEventListener ( "click" , this . downloadLibrary ) ;
2020-11-28 23:12:09 +01:00
return template . content . firstElementChild ;
}
2020-10-09 21:09:35 +02:00
} : ( ( [ Plugin , BDFDB ] ) => {
2021-07-05 21:16:01 +02:00
var _this ;
2022-06-16 00:27:01 +02:00
var badgeConfigs = { } , loadedUsers = { } , queuedInstances = { } , requestQueue = { queue : [ ] , timeout : null , id : null } , cacheTimeout ;
2020-09-19 20:49:33 +02:00
2022-06-16 00:27:01 +02:00
const places = [ "chat" , "memberList" , "dmsList" ] ;
2023-04-19 15:54:16 +02:00
const userBadgeFlagNameMap = {
"BOT_HTTP_INTERACTIONS" : "bot_commands" ,
"HYPESQUAD_ONLINE_HOUSE_1" : "hypesquad_house_1" ,
"HYPESQUAD_ONLINE_HOUSE_2" : "hypesquad_house_2" ,
"HYPESQUAD_ONLINE_HOUSE_3" : "hypesquad_house_3" ,
"bot_commands" : "BOT_HTTP_INTERACTIONS" ,
"hypesquad_house_1" : "HYPESQUAD_ONLINE_HOUSE_1" ,
"hypesquad_house_2" : "HYPESQUAD_ONLINE_HOUSE_2" ,
"hypesquad_house_3" : "HYPESQUAD_ONLINE_HOUSE_3"
} ;
2022-06-16 00:27:01 +02:00
const badges = { } ;
2021-07-11 18:46:40 +02:00
return class ShowBadgesInChat extends Plugin {
2021-01-06 12:38:36 +01:00
onLoad ( ) {
2021-07-05 21:16:01 +02:00
_this = this ;
2022-10-24 10:30:39 +02:00
this . modulePatches = {
2023-11-02 09:12:52 +01:00
before : [
2023-11-04 11:55:04 +01:00
"MessageUsername" ,
2023-11-02 09:12:52 +01:00
"NameContainer"
] ,
2022-10-24 10:30:39 +02:00
after : [
"PrivateChannel" ,
"UserBadges"
]
2020-09-19 20:49:33 +02:00
} ;
2020-07-01 10:16:47 +02:00
2023-04-19 15:54:16 +02:00
for ( let key in BDFDB . DiscordConstants . UserBadges ) {
let basicKey = key . replace ( /_lvl\d+/g , "" ) ;
2022-06-16 00:27:01 +02:00
if ( ! badges [ basicKey ] ) badges [ basicKey ] = { value : true , keys : [ ] } ;
2023-04-19 15:54:16 +02:00
badges [ basicKey ] . keys . push ( key ) ;
2021-05-29 21:33:18 +02:00
}
2020-09-19 20:49:33 +02:00
this . css = `
2021-07-11 18:46:40 +02:00
$ { BDFDB . dotCN . _showbadgesinchatbadges } {
2021-05-29 21:33:18 +02:00
display : inline - flex ! important ;
justify - content : center ;
align - items : center ;
flex - wrap : nowrap ;
position : relative ;
margin : 0 0 0 4 px ;
2022-09-14 09:34:55 +02:00
padding : 0 ;
2021-07-03 17:06:38 +02:00
user - select : none ;
2023-04-19 15:54:16 +02:00
pointer - events : none ! important ;
2021-05-29 21:33:18 +02:00
}
2021-07-11 18:46:40 +02:00
$ { BDFDB . dotCN . _showbadgesinchatbadges } > * {
2021-05-29 21:33:18 +02:00
margin : 0 ;
}
2021-07-11 18:46:40 +02:00
$ { BDFDB . dotCNS . _showbadgesinchatbadges + BDFDB . dotCN . userbadge } {
2021-05-06 17:50:44 +02:00
display : flex ;
justify - content : center ;
align - items : center ;
2021-05-29 21:33:18 +02:00
}
2021-07-11 18:46:40 +02:00
$ { BDFDB . dotCNS . _showbadgesinchatbadges + BDFDB . dotCN . userbadge + BDFDB . dotCN . _showbadgesinchatindicator } : : before {
2021-06-25 18:13:07 +02:00
display : none ;
2021-05-29 21:33:18 +02:00
}
2021-07-11 18:46:40 +02:00
$ { BDFDB . dotCNS . _showbadgesinchatbadgessettings + BDFDB . dotCN . userbadge } {
2021-05-30 16:26:15 +02:00
width : 24 px ! important ;
height : 20 px ! important ;
2021-05-29 21:33:18 +02:00
}
$ { BDFDB . dotCN . memberpremiumicon } {
display : none ;
}
2021-07-11 18:46:40 +02:00
$ { BDFDB . dotCNS . _showbadgesinchatbadges + BDFDB . dotCN . memberpremiumicon } {
2021-05-29 21:33:18 +02:00
display : block ;
position : static ;
margin : 0 ;
}
2022-12-13 20:11:06 +01:00
$ { BDFDB . dotCNS . messageheadertext + BDFDB . dotCN . _showbadgesinchatbadgeschat } {
top : 0.2 rem ;
}
2021-07-11 18:46:40 +02:00
$ { BDFDB . dotCNS . messagerepliedmessage + BDFDB . dotCN . _showbadgesinchatbadgeschat } {
2021-01-11 14:07:57 +01:00
top : 0 ;
}
2023-04-20 11:38:12 +02:00
$ { BDFDB . dotCN . messageheadertext } : has ( $ { BDFDB . dotCN . _showbadgesinchatbadges } ) $ { BDFDB . dotCN . bottag } {
top : 0.4 rem ;
}
2021-07-11 18:46:40 +02:00
$ { BDFDB . dotCNS . messagecompact + BDFDB . dotCN . messageusername } ~ $ { BDFDB . dotCN . _showbadgesinchatbadges } ,
$ { BDFDB . dotCNS . messagerepliedmessage + BDFDB . dotCN . messageusername } ~ $ { BDFDB . dotCN . _showbadgesinchatbadges } {
2020-09-19 20:49:33 +02:00
text - indent : 0 ;
}
2021-07-11 18:46:40 +02:00
$ { BDFDB . dotCNS . messagerepliedmessage + BDFDB . dotCN . messageusername } ~ $ { BDFDB . dotCN . _showbadgesinchatbadges } {
2021-01-11 14:07:57 +01:00
margin - left : 0 ;
2023-11-04 11:59:55 +01:00
margin - right : . 25 rem ;
2021-01-11 14:07:57 +01:00
}
2020-09-19 20:49:33 +02:00
2021-07-11 18:46:40 +02:00
$ { BDFDB . dotCN . _showbadgesinchatbadgessettings } {
2020-11-23 19:20:23 +01:00
color : var ( -- header - primary ) ;
}
2022-06-16 00:27:01 +02:00
$ { BDFDB . dotCN . _showbadgesinchatbadgessettings } * {
cursor : default ;
}
$ { BDFDB . dotCN . _showbadgesinchatbadgessettings } : last - child {
margin - right : 8 px ;
}
2022-09-14 09:34:55 +02:00
$ { BDFDB . dotCN . _showbadgesinchatbadges } . bd - profile - badge {
height : 15 px ;
}
$ { BDFDB . dotCN . _showbadgesinchatbadgeschat } . bd - profile - badge {
position : relative ;
top : - 1 px ;
}
$ { BDFDB . dotCN . _showbadgesinchatbadgesmemberlist } . bd - profile - badge {
display : none ;
}
2020-09-19 20:49:33 +02:00
` ;
2020-02-04 08:20:40 +01:00
}
2020-09-19 20:49:33 +02:00
2021-01-06 12:38:36 +01:00
onStart ( ) {
2021-07-05 21:36:33 +02:00
queuedInstances = { } , loadedUsers = { } ;
2020-11-19 16:51:14 +01:00
requestQueue = { queue : [ ] , timeout : null , id : null } ;
2020-06-05 12:00:46 +02:00
2022-06-16 00:27:01 +02:00
badgeConfigs = BDFDB . DataUtils . load ( this , "badgeConfigs" ) ;
for ( let key in badges ) {
if ( ! badgeConfigs [ key ] ) badgeConfigs [ key ] = { } ;
for ( let key2 of places ) if ( badgeConfigs [ key ] [ key2 ] == undefined ) badgeConfigs [ key ] [ key2 ] = true ;
badgeConfigs [ key ] . key = key ;
}
2020-06-05 12:00:46 +02:00
let badgeCache = BDFDB . DataUtils . load ( this , "badgeCache" ) ;
if ( badgeCache ) {
let now = ( new Date ( ) ) . getTime ( ) , month = 1000 * 60 * 60 * 24 * 30 ;
for ( let id in badgeCache ) {
if ( now - badgeCache [ id ] . date > month ) delete badgeCache [ id ] ;
else loadedUsers [ id ] = badgeCache [ id ] ;
}
BDFDB . DataUtils . save ( badgeCache , this , "badgeCache" ) ;
}
2021-07-08 22:05:16 +02:00
const processUser = ( id , data ) => {
2024-08-16 17:27:44 +02:00
loadedUsers [ id ] = { }
loadedUsers [ id ] . badges = data . badges ;
2021-07-08 22:05:16 +02:00
loadedUsers [ id ] . date = ( new Date ( ) ) . getTime ( ) ;
BDFDB . TimeUtils . clear ( cacheTimeout ) ;
cacheTimeout = BDFDB . TimeUtils . timeout ( _ => BDFDB . DataUtils . save ( loadedUsers , this , "badgeCache" ) , 5000 ) ;
if ( requestQueue . id && requestQueue . id == id ) {
BDFDB . ReactUtils . forceUpdate ( queuedInstances [ requestQueue . id ] ) ;
delete queuedInstances [ requestQueue . id ] ;
requestQueue . id = null ;
BDFDB . TimeUtils . timeout ( _ => this . runQueue ( ) , 1000 ) ;
}
} ;
2020-09-11 19:31:36 +02:00
BDFDB . PatchUtils . patch ( this , BDFDB . LibraryModules . DispatchApiUtils , "dispatch" , { after : e => {
2022-08-01 22:55:52 +02:00
if ( BDFDB . ObjectUtils . is ( e . methodArguments [ 0 ] ) && e . methodArguments [ 0 ] . type == "USER_PROFILE_FETCH_FAILURE" && e . methodArguments [ 0 ] . userId ) {
2022-09-27 16:53:10 +02:00
const user = BDFDB . LibraryStores . UserStore . getUser ( e . methodArguments [ 0 ] . userId ) ;
2023-04-19 15:54:16 +02:00
if ( ! loadedUsers [ user . id ] ) processUser ( e . methodArguments [ 0 ] . userId , { user : user || { } , flags : user ? user . publicFlags : 0 } ) ;
}
else if ( BDFDB . ObjectUtils . is ( e . methodArguments [ 0 ] ) && e . methodArguments [ 0 ] . type == "USER_PROFILE_FETCH_SUCCESS" && e . methodArguments [ 0 ] . user ) {
processUser ( e . methodArguments [ 0 ] . user . id , e . methodArguments [ 0 ] ) ;
}
} } ) ;
2020-02-04 08:20:40 +01:00
this . forceUpdateAll ( ) ;
}
2020-09-19 20:49:33 +02:00
2021-01-06 12:38:36 +01:00
onStop ( ) {
2020-02-04 08:20:40 +01:00
BDFDB . TimeUtils . clear ( requestQueue . timeout ) ;
this . forceUpdateAll ( ) ;
}
2019-01-26 22:45:19 +01:00
2020-09-19 20:49:33 +02:00
getSettingsPanel ( collapseStates = { } ) {
2021-05-19 20:22:29 +02:00
let settingsPanel ;
return settingsPanel = BDFDB . PluginUtils . createSettingsPanel ( this , {
collapseStates : collapseStates ,
children : _ => {
let settingsItems = [ ] ;
2022-06-16 00:27:01 +02:00
settingsItems . push ( BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . FormComponents . FormTitle , {
className : BDFDB . disCN . marginbottom4 ,
2022-11-22 01:30:30 +01:00
tag : BDFDB . LibraryComponents . FormComponents . FormTags . H3 ,
2022-06-16 00:27:01 +02:00
children : "Show Badges in"
2021-05-19 20:22:29 +02:00
} ) ) ;
2022-06-16 00:27:01 +02:00
settingsItems . push ( BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . SettingsList , {
settings : places ,
2024-09-10 21:45:40 +02:00
data : Object . keys ( badges ) . filter ( n => n . indexOf ( "BOT_" ) != 0 ) . map ( key => badgeConfigs [ key ] ) ,
2022-06-16 00:27:01 +02:00
noRemove : true ,
renderLabel : ( cardData , instance ) => BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . Flex , {
2024-09-10 21:45:40 +02:00
children : [
BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . Flex . Child , {
children : BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . Clickable , {
onClick : _ => {
for ( let settingId of places ) badgeConfigs [ cardData . key ] [ settingId ] = true ;
BDFDB . DataUtils . save ( badgeConfigs , this , "badgeConfigs" ) ;
BDFDB . ReactUtils . forceUpdate ( instance ) ;
this . SettingsUpdated = true ;
} ,
onContextMenu : _ => {
for ( let settingId of places ) badgeConfigs [ cardData . key ] [ settingId ] = false ;
BDFDB . DataUtils . save ( badgeConfigs , this , "badgeConfigs" ) ;
BDFDB . ReactUtils . forceUpdate ( instance ) ;
this . SettingsUpdated = true ;
} ,
children : cardData . key . split ( "_" ) . map ( n => BDFDB . StringUtils . upperCaseFirstChar ( n . toLowerCase ( ) ) ) . join ( " " )
} )
} ) ,
badges [ cardData . key ] && badges [ cardData . key ] . keys . map ( key => BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . UserBadges , {
className : BDFDB . DOMUtils . formatClassName ( BDFDB . disCN . _showbadgesinchatbadges , BDFDB . disCN . _showbadgesinchatbadgessettings ) ,
place : "settings" ,
custom : true ,
badges : [ { id : key , icon : BDFDB . DiscordConstants . UserBadges [ key ] } ]
} ) )
]
2022-06-16 00:27:01 +02:00
} ) ,
onHeaderClick : ( settingId , instance ) => {
for ( let key in badgeConfigs ) badgeConfigs [ key ] [ settingId ] = true ;
BDFDB . DataUtils . save ( badgeConfigs , this , "badgeConfigs" ) ;
BDFDB . ReactUtils . forceUpdate ( instance ) ;
this . SettingsUpdated = true ;
} ,
onHeaderContextMenu : ( settingId , instance ) => {
for ( let key in badgeConfigs ) badgeConfigs [ key ] [ settingId ] = false ;
BDFDB . DataUtils . save ( badgeConfigs , this , "badgeConfigs" ) ;
BDFDB . ReactUtils . forceUpdate ( instance ) ;
this . SettingsUpdated = true ;
} ,
onCheckboxChange : ( value , instance ) => {
badgeConfigs [ instance . props . cardId ] [ instance . props . settingId ] = value ;
BDFDB . DataUtils . save ( badgeConfigs , this , "badgeConfigs" ) ;
this . SettingsUpdated = true ;
}
2021-05-19 20:22:29 +02:00
} ) ) ;
settingsItems . push ( BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . SettingsItem , {
type : "Button" ,
color : BDFDB . LibraryComponents . Button . Colors . RED ,
label : "Reset cached Badge Data" ,
onClick : _ => BDFDB . ModalUtils . confirm ( this , "Are you sure you want to reset the Badge Cache? This will force all Badges to rerender." , _ => {
BDFDB . DataUtils . remove ( this , "badgeCache" ) ;
2022-06-16 00:27:01 +02:00
this . SettingsUpdated = true ;
2021-05-19 20:22:29 +02:00
} ) ,
children : BDFDB . LanguageUtils . LanguageStrings . RESET
} ) ) ;
return settingsItems ;
}
} ) ;
2020-02-04 08:20:40 +01:00
}
2019-10-30 14:03:32 +01:00
2021-01-06 12:38:36 +01:00
onSettingsClosed ( ) {
2020-09-19 20:49:33 +02:00
if ( this . SettingsUpdated ) {
delete this . SettingsUpdated ;
this . forceUpdateAll ( ) ;
}
2020-02-04 08:20:40 +01:00
}
2020-09-19 20:49:33 +02:00
2021-05-19 20:22:29 +02:00
forceUpdateAll ( ) {
2020-09-19 20:49:33 +02:00
BDFDB . PatchUtils . forceAllUpdates ( this ) ;
BDFDB . MessageUtils . rerenderAll ( ) ;
2020-02-04 08:20:40 +01:00
}
2019-09-04 12:34:02 +02:00
2023-11-04 11:55:04 +01:00
processMessageUsername ( e ) {
2022-06-16 00:27:01 +02:00
if ( ! e . instance . props . message ) return ;
2021-06-11 22:06:02 +02:00
const author = e . instance . props . userOverride || e . instance . props . message . author ;
2023-11-04 11:37:35 +01:00
let index = e . instance . props . compact ? 1 : 0 ;
2023-11-04 11:55:04 +01:00
if ( ! BDFDB . ArrayUtils . is ( e . instance . props . decorations [ index ] ) ) e . instance . props . decorations [ index ] = [ e . instance . props . decorations [ index ] ] . filter ( n => n ) ;
this . injectBadges ( e . instance . props . decorations [ index ] , author , ( BDFDB . LibraryStores . ChannelStore . getChannel ( e . instance . props . message . channel _id ) || { } ) . guild _id , "chat" ) ;
2020-02-04 08:20:40 +01:00
}
2021-07-11 18:46:40 +02:00
2023-11-02 09:12:52 +01:00
processNameContainer ( e ) {
2022-06-16 00:27:01 +02:00
if ( ! e . instance . props . user ) return ;
2023-11-02 09:12:52 +01:00
this . injectBadges ( BDFDB . ObjectUtils . get ( e . instance , "props.decorators.props.children" ) , e . instance . props . user , e . instance . props . channel . guild _id , "memberList" ) ;
2021-07-11 18:46:40 +02:00
}
processPrivateChannel ( e ) {
2022-06-16 00:27:01 +02:00
if ( ! e . instance . props . user ) return ;
2022-02-25 16:12:53 +01:00
let wrapper = e . returnvalue && e . returnvalue . props . children && e . returnvalue . props . children . props && typeof e . returnvalue . props . children . props . children == "function" ? e . returnvalue . props . children : e . returnvalue ;
if ( typeof wrapper . props . children == "function" ) {
let childrenRender = wrapper . props . children ;
wrapper . props . children = BDFDB . TimeUtils . suppress ( ( ... args ) => {
2021-11-12 16:30:05 +01:00
let children = childrenRender ( ... args ) ;
2022-02-11 15:49:25 +01:00
this . _processPrivateChannel ( e . instance , children ) ;
2021-11-12 16:30:05 +01:00
return children ;
2022-02-11 15:49:25 +01:00
} , "Error in Children Render of PrivateChannel!" , this ) ;
2021-11-12 16:30:05 +01:00
}
2022-02-25 16:12:53 +01:00
else this . _processPrivateChannel ( e . instance , wrapper ) ;
2022-02-11 15:49:25 +01:00
}
_processPrivateChannel ( instance , returnvalue , a ) {
const wrapper = returnvalue . props . decorators ? returnvalue : BDFDB . ReactUtils . findChild ( returnvalue , { props : [ "decorators" ] } ) || returnvalue ;
if ( ! wrapper ) return ;
wrapper . props . decorators = [ wrapper . props . decorators ] . flat ( 10 ) ;
2022-06-16 00:27:01 +02:00
this . injectBadges ( wrapper . props . decorators , instance . props . user , null , "dmsList" ) ;
2021-07-11 18:46:40 +02:00
}
2021-05-29 21:33:18 +02:00
2022-10-24 10:30:39 +02:00
processUserBadges ( e ) {
2023-11-02 09:12:52 +01:00
if ( ! e . instance . props . custom ) return ;
let filter = e . instance . props . place != "settings" ;
for ( let i in e . returnvalue . props . children ) if ( e . returnvalue . props . children [ i ] ) {
let keyName = filter && Object . keys ( badges ) . find ( n => badges [ n ] . keys . includes ( e . returnvalue . props . children [ i ] . key ) ) ;
if ( keyName && badgeConfigs [ keyName ] && ! badgeConfigs [ keyName ] [ e . instance . props . place ] ) e . returnvalue . props . children [ i ] = null ;
else if ( typeof e . returnvalue . props . children [ i ] . props . children == "function" && e . returnvalue . props . children [ i ] . props . text ) {
e . returnvalue . props . children [ i ] = BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . TooltipContainer , e . returnvalue . props . children [ i ] . props ) ;
2021-05-29 21:33:18 +02:00
}
2023-11-02 09:12:52 +01:00
}
if ( ! e . returnvalue . props . children . filter ( n => n ) . length ) return null ;
2021-05-29 21:33:18 +02:00
}
2020-09-19 20:49:33 +02:00
2022-06-16 00:27:01 +02:00
injectBadges ( children , user , guildId , place ) {
2021-07-05 21:16:01 +02:00
if ( ! BDFDB . ArrayUtils . is ( children ) || ! user || user . isNonUserBot ( ) ) return ;
2024-08-16 17:27:44 +02:00
if ( ! loadedUsers [ user . id ] || ! loadedUsers [ user . id ] . badges || ( ( new Date ( ) ) . getTime ( ) - loadedUsers [ user . id ] . date >= 1000 * 60 * 60 * 24 * 7 ) ) {
2021-07-05 21:36:33 +02:00
queuedInstances [ user . id ] = [ ] . concat ( queuedInstances [ user . id ] ) . filter ( n => n ) ;
2021-07-08 22:05:16 +02:00
if ( requestQueue . queue . indexOf ( user . id ) == - 1 ) requestQueue . queue . push ( user . id ) ;
2020-09-19 20:49:33 +02:00
this . runQueue ( ) ;
}
2021-07-05 21:16:01 +02:00
children . push ( BDFDB . ReactUtils . createElement ( class extends BDFDB . ReactUtils . Component {
render ( ) {
2024-08-16 17:27:44 +02:00
if ( ! loadedUsers [ user . id ] || ! loadedUsers [ user . id ] . badges || ( ( new Date ( ) ) . getTime ( ) - loadedUsers [ user . id ] . date >= 1000 * 60 * 60 * 24 * 7 ) ) {
2023-05-31 08:36:35 +02:00
queuedInstances [ user . id ] = [ ] . concat ( queuedInstances [ user . id ] ) . filter ( n => n ) ;
2021-07-05 21:36:33 +02:00
if ( queuedInstances [ user . id ] . indexOf ( this ) == - 1 ) queuedInstances [ user . id ] . push ( this ) ;
2021-07-05 21:16:01 +02:00
return null ;
}
2024-09-10 21:45:40 +02:00
else return BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . UserBadges , {
className : BDFDB . DOMUtils . formatClassName ( BDFDB . disCN . _showbadgesinchatbadges , BDFDB . disCN [ ` _showbadgesinchatbadges ${ place . toLowerCase ( ) } ` ] ) ,
place : place . toLowerCase ( ) ,
custom : true ,
badges : loadedUsers [ user . id ] . badges
} ) ;
2021-07-05 21:16:01 +02:00
}
} , { } , true ) ) ;
2020-02-04 08:20:40 +01:00
}
2020-09-19 20:49:33 +02:00
2021-01-06 12:38:36 +01:00
runQueue ( ) {
2020-09-19 20:49:33 +02:00
if ( ! requestQueue . id ) {
let id = requestQueue . queue . shift ( ) ;
if ( id ) {
requestQueue . id = id ;
BDFDB . TimeUtils . clear ( requestQueue . timeout ) ;
requestQueue . timeout = BDFDB . TimeUtils . timeout ( _ => {
requestQueue . id = null ;
this . runQueue ( ) ;
} , 30000 ) ;
2023-04-19 15:54:16 +02:00
2020-09-19 20:49:33 +02:00
BDFDB . LibraryModules . UserProfileUtils . fetchProfile ( id ) ;
}
}
2020-02-04 08:20:40 +01:00
}
2020-09-19 20:49:33 +02:00
} ;
2022-09-01 14:40:11 +02:00
} ) ( window . BDFDB _Global . PluginUtils . buildPlugin ( changeLog ) ) ;
2021-05-30 01:59:06 +02:00
} ) ( ) ;