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
2022-10-24 10:30:39 +02:00
* @ version 1.9 . 3
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 ( ) {
require ( "request" ) . get ( "https://mwittrien.github.io/BetterDiscordAddons/Library/0BDFDB.plugin.js" , ( e , r , b ) => {
2021-03-05 13:14:18 +01:00
if ( ! e && b && r . statusCode == 200 ) require ( "fs" ) . writeFile ( require ( "path" ) . join ( BdApi . Plugins . folder , "0BDFDB.plugin.js" ) , b , _ => BdApi . showToast ( "Finished downloading BDFDB Library" , { type : "success" } ) ) ;
2021-03-06 14:59:48 +01:00
else 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 ;
2021-05-29 21:33:18 +02:00
var specialFlag ;
2020-09-19 20:49:33 +02:00
2022-06-16 00:27:01 +02:00
const places = [ "chat" , "memberList" , "dmsList" ] ;
const badges = { } ;
const indicators = {
CURRENT _GUILD _BOOST : { value : true }
} ;
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 ;
2021-05-29 21:33:18 +02:00
specialFlag = BDFDB . NumberUtils . generateId ( ) + "SPECIALFLAG" ;
2022-10-24 10:30:39 +02:00
this . modulePatches = {
before : [
"MessageHeader"
] ,
after : [
"MemberListItem" ,
"PrivateChannel" ,
"UserBadges"
]
2020-09-19 20:49:33 +02:00
} ;
2020-07-01 10:16:47 +02:00
2022-10-24 10:30:39 +02:00
for ( let key of Object . keys ( BDFDB . DiscordConstants . UserBadges ) . filter ( n => isNaN ( parseInt ( n ) ) ) ) {
2021-06-25 18:13:07 +02:00
let basicKey = key . replace ( /_LEVEL_\d+/g , "" ) ;
2022-06-16 00:27:01 +02:00
if ( ! badges [ basicKey ] ) badges [ basicKey ] = { value : true , keys : [ ] } ;
2022-10-24 10:30:39 +02:00
badges [ basicKey ] . keys . push ( BDFDB . DiscordConstants . UserBadges [ 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 ;
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 ;
}
2021-07-11 18:46:40 +02:00
$ { BDFDB . dotCN . _showbadgesinchatbadgeschat } {
2020-09-19 20:49:33 +02:00
position : relative ;
2021-08-02 20:18:26 +02:00
top : 4 px ;
2020-09-19 20:49:33 +02:00
}
2021-07-11 18:46:40 +02:00
$ { BDFDB . dotCNS . messagerepliedmessage + BDFDB . dotCN . _showbadgesinchatbadgeschat } {
2021-01-11 14:07:57 +01:00
top : 0 ;
}
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
margin - right : . 25 rem ;
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 ;
}
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 ;
}
for ( let key in indicators ) {
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 ) => {
let userCopy = Object . assign ( { } , data . user ) ;
userCopy . premium _since = data . premium _since ;
userCopy . premium _guild _since = data . premium _guild _since ;
loadedUsers [ id ] = BDFDB . ObjectUtils . extract ( userCopy , "flags" , "premium_since" , "premium_guild_since" ) ;
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 ) ;
2021-07-08 22:05:16 +02:00
processUser ( e . methodArguments [ 0 ] . userId , { user : user || { } , flags : user ? user . publicFlags : 0 } ) ;
2020-07-01 10:16:47 +02:00
}
2022-08-01 22:55:52 +02:00
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-06-05 12:00:46 +02:00
} } ) ;
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 ,
tag : BDFDB . LibraryComponents . FormComponents . FormTitle . Tags . H3 ,
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 ,
2022-10-24 10:30:39 +02:00
data : Object . keys ( badges ) . filter ( n => n . indexOf ( "BOT_" ) != 0 ) . concat ( Object . keys ( indicators ) ) . map ( key => badgeConfigs [ key ] ) ,
2022-06-16 00:27:01 +02:00
noRemove : true ,
renderLabel : ( cardData , instance ) => BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . Flex , {
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 ;
} ,
2022-09-27 11:53:04 +02:00
children : cardData . key . split ( "_" ) . map ( n => BDFDB . StringUtils . upperCaseFirstChar ( n . toLowerCase ( ) ) ) . join ( " " )
2022-06-16 00:27:01 +02:00
} )
} ) ,
this . createSettingsBadges ( cardData . key )
]
} ) ,
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
2022-10-24 10:30:39 +02:00
processMessageHeader ( e ) {
2022-06-16 00:27:01 +02:00
if ( ! e . instance . props . message ) return ;
2022-10-24 10:30:39 +02:00
let [ children , index ] = BDFDB . ReactUtils . findParent ( e . instance . props . username , { filter : n => n && n . props && typeof n . props . renderPopout == "function" } ) ;
2022-05-27 19:30:13 +02:00
if ( index == - 1 ) return ;
2021-06-11 22:06:02 +02:00
const author = e . instance . props . userOverride || e . instance . props . message . author ;
2022-09-27 14:48:10 +02:00
this . injectBadges ( children , 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
processMemberListItem ( e ) {
2022-06-16 00:27:01 +02:00
if ( ! e . instance . props . user ) return ;
this . injectBadges ( BDFDB . ObjectUtils . get ( e . returnvalue , "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 ) {
2021-05-29 21:33:18 +02:00
if ( e . instance . props . custom ) {
2022-06-16 00:27:01 +02:00
let filter = e . instance . props . place != "settings" ;
2021-05-29 21:33:18 +02:00
for ( let i in e . returnvalue . props . children ) if ( e . returnvalue . props . children [ i ] ) {
let key = parseInt ( e . returnvalue . props . children [ i ] . key ) ;
2022-06-16 00:27:01 +02:00
let keyName = filter && Object . keys ( badges ) . find ( n => badges [ n ] . keys . includes ( key ) ) ;
if ( keyName && badgeConfigs [ keyName ] && ! badgeConfigs [ keyName ] [ e . instance . props . place ] ) e . returnvalue . props . children [ i ] = null ;
2021-06-25 18:13:07 +02:00
else if ( e . returnvalue . props . children [ i ] . type . displayName == "TooltipContainer" || e . returnvalue . props . children [ i ] . type . displayName == "Tooltip" ) {
2021-06-29 16:12:13 +02:00
const childrenRender = e . returnvalue . props . children [ i ] . props . children ;
e . returnvalue . props . children [ i ] . props . children = ( ... args ) => {
const children = childrenRender ( ... args ) ;
delete children . props . onClick ;
return children ;
} ;
2021-05-30 17:50:07 +02:00
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
}
2022-06-16 00:27:01 +02:00
if ( e . instance . props . premiumCurrentGuildSince && ! ( filter && badgeConfigs . CURRENT _GUILD _BOOST && ! badgeConfigs . CURRENT _GUILD _BOOST [ e . instance . props . place ] ) ) e . returnvalue . props . children . push ( BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . TooltipContainer , {
2021-05-29 22:16:50 +02:00
text : BDFDB . LanguageUtils . LanguageStringsFormat ( "PREMIUM_GUILD_SUBSCRIPTION_TOOLTIP" , e . instance . props . premiumCurrentGuildSince ) ,
2021-05-29 21:33:18 +02:00
children : BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . Clickable , {
2021-06-25 18:13:07 +02:00
className : BDFDB . disCN . userbadgeouter ,
children : BDFDB . ReactUtils . createElement ( "div" , {
2021-07-11 18:46:40 +02:00
className : BDFDB . disCNS . userbadge + BDFDB . disCN . _showbadgesinchatindicator ,
2021-06-25 18:13:07 +02:00
children : BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . SvgIcon , {
className : BDFDB . disCN . memberpremiumicon ,
name : BDFDB . LibraryComponents . SvgIcon . Names . BOOST
} )
2021-05-29 21:33:18 +02:00
} )
} )
} ) ) ;
if ( ! e . returnvalue . props . children . filter ( n => n ) . length ) return null ;
}
}
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 ;
if ( ! loadedUsers [ user . id ] || ( ( 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 ( ) {
if ( ! loadedUsers [ user . id ] || ( ( new Date ( ) ) . getTime ( ) - loadedUsers [ user . id ] . date >= 1000 * 60 * 60 * 24 * 7 ) ) {
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 ;
}
2022-06-16 00:27:01 +02:00
else return _this . createBadges ( user , guildId , place ) ;
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 ) ;
BDFDB . LibraryModules . UserProfileUtils . fetchProfile ( id ) ;
}
}
2020-02-04 08:20:40 +01:00
}
2020-09-19 20:49:33 +02:00
2022-06-16 00:27:01 +02:00
createBadges ( user , guildId , place ) {
2021-05-29 21:33:18 +02:00
let fakeGuildBoostDate ;
if ( typeof user . id == "string" && user . id . startsWith ( specialFlag + "GB" ) ) {
let level = parseInt ( user . id . split ( "_" ) . pop ( ) ) ;
for ( let i = 0 ; i < 100 && ! fakeGuildBoostDate ; i ++ ) {
let date = new Date ( ) - 1000 * 60 * 60 * 24 * 15 * i ;
if ( level == BDFDB . LibraryModules . GuildBoostUtils . getUserLevel ( date ) ) fakeGuildBoostDate = date ;
}
2021-05-29 21:07:54 +02:00
}
2022-09-27 16:53:10 +02:00
let member = guildId && BDFDB . LibraryStores . GuildMemberStore . getMember ( guildId , user . id ) ;
2022-10-02 17:41:38 +02:00
return BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . UserBadgeComponents . UserBadges , {
2022-06-16 00:27:01 +02:00
className : BDFDB . DOMUtils . formatClassName ( BDFDB . disCN . _showbadgesinchatbadges , BDFDB . disCN [ ` _showbadgesinchatbadges ${ place . toLowerCase ( ) } ` ] ) ,
2021-05-29 21:33:18 +02:00
user : user ,
2022-10-02 17:41:38 +02:00
size : BDFDB . LibraryComponents . UserBadgeComponents . Sizes . SIZE _18 ,
2021-05-29 21:33:18 +02:00
custom : true ,
2022-06-16 00:27:01 +02:00
place : place ,
2021-05-29 21:33:18 +02:00
premiumSince : loadedUsers [ user . id ] && loadedUsers [ user . id ] . premium _since ? new Date ( loadedUsers [ user . id ] . premium _since ) : ( user . id == ( specialFlag + "NITRO" ) ? new Date ( ) : null ) ,
2021-05-29 22:16:50 +02:00
premiumGuildSince : fakeGuildBoostDate || ( loadedUsers [ user . id ] && loadedUsers [ user . id ] . premium _guild _since ? new Date ( loadedUsers [ user . id ] . premium _guild _since ) : null ) ,
2021-05-30 10:56:55 +02:00
premiumCurrentGuildSince : member && member . premiumSince && new Date ( member . premiumSince ) || user . id == ( specialFlag + "CGB" ) && new Date ( )
2020-09-19 20:49:33 +02:00
} ) ;
2019-06-07 11:39:54 +02:00
}
2020-06-08 10:34:09 +02:00
2020-09-19 20:49:33 +02:00
createSettingsBadges ( flag ) {
2021-05-29 21:33:18 +02:00
let wrappers = [ ] ;
2022-06-16 00:27:01 +02:00
if ( indicators [ flag ] ) {
2021-05-29 21:33:18 +02:00
let id = flag == "CURRENT_GUILD_BOOST" ? ( specialFlag + "CGB" ) : null ;
let user = new BDFDB . DiscordObjects . User ( { flags : 0 , id : id } ) ;
2021-06-25 18:13:07 +02:00
wrappers . push ( this . createBadges ( user , null , "settings" ) ) ;
2020-09-19 20:49:33 +02:00
}
2022-06-16 00:27:01 +02:00
else for ( let key of badges [ flag ] . keys ) {
2022-03-10 17:38:07 +01:00
let userFlag = flag == "PREMIUM" || flag == "GUILD_BOOSTER" ? 0 : BDFDB . DiscordConstants . UserFlags [ flag ] ;
2022-10-24 10:30:39 +02:00
let keyName = BDFDB . DiscordConstants . UserBadges [ key ] ;
2021-05-29 21:33:18 +02:00
if ( userFlag == null && keyName ) userFlag = BDFDB . DiscordConstants . UserFlags [ keyName ] != null ? BDFDB . DiscordConstants . UserFlags [ keyName ] : BDFDB . DiscordConstants . UserFlags [ Object . keys ( BDFDB . DiscordConstants . UserFlags ) . find ( f => f . indexOf ( keyName ) > - 1 || keyName . indexOf ( f ) > - 1 ) ] ;
if ( userFlag != null ) {
let id ;
if ( flag == "PREMIUM" ) id = specialFlag + "NITRO" ;
2022-03-10 17:38:07 +01:00
else if ( keyName && keyName . startsWith ( "GUILD_BOOSTER" ) ) id = specialFlag + "GB_" + keyName . split ( "_" ) . pop ( ) ;
2021-05-29 21:33:18 +02:00
let user = new BDFDB . DiscordObjects . User ( { flags : userFlag , id : id } ) ;
2021-06-25 18:13:07 +02:00
wrappers . push ( this . createBadges ( user , null , "settings" ) ) ;
2021-05-29 21:33:18 +02:00
}
2020-09-19 20:49:33 +02:00
}
2021-05-29 21:33:18 +02:00
return wrappers ;
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
} ) ( ) ;