2020-10-20 23:25:34 +02:00
/ * *
* @ name BadgesEverywhere
2021-03-05 13:26:41 +01:00
* @ author DevilBro
2020-10-20 23:25:34 +02:00
* @ authorId 278543574059057154
2021-04-23 20:35:45 +02:00
* @ version 1.6 . 8
2021-03-05 13:26:41 +01:00
* @ description Displays Badges ( Nitro , Hypesquad , etc ... ) in the Chat / MemberList / UserPopout
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/
* @ source https : //github.com/mwittrien/BetterDiscordAddons/tree/master/Plugins/BadgesEverywhere/
2021-03-10 09:17:37 +01:00
* @ updateUrl https : //mwittrien.github.io/BetterDiscordAddons/Plugins/BadgesEverywhere/BadgesEverywhere.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 = ( _ => {
2020-10-09 21:09:35 +02:00
const config = {
2020-09-19 20:49:33 +02:00
"info" : {
"name" : "BadgesEverywhere" ,
"author" : "DevilBro" ,
2021-04-23 20:35:45 +02:00
"version" : "1.6.8" ,
2021-03-04 11:31:05 +01:00
"description" : "Displays Badges (Nitro, Hypesquad, etc...) in the Chat/MemberList/UserPopout"
2021-04-23 12:01:44 +02:00
} ,
"changeLog" : {
"fixed" : {
2021-04-23 20:35:45 +02:00
"Margin & Overlapping" : "Fixed Margin and Overlapping Issue, thanks Discord"
2021-04-23 12:01:44 +02:00
}
2020-02-04 08:20:40 +01:00
}
2020-09-19 20:49:33 +02:00
} ;
2021-02-05 21:45:34 +01:00
2020-10-09 21:09:35 +02:00
return ! window . BDFDB _Global || ( ! window . BDFDB _Global . loaded && ! window . BDFDB _Global . started ) ? class {
2021-01-06 12:38:36 +01:00
getName ( ) { return config . info . name ; }
getAuthor ( ) { return config . info . author ; }
getVersion ( ) { return config . info . version ; }
2021-02-01 17:13:13 +01:00
getDescription ( ) { return ` The Library Plugin needed for ${ config . info . name } is missing. Open the Plugin Settings to download it. \n \n ${ config . info . description } ` ; }
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 ;
2021-01-14 16:14:44 +01:00
BdApi . showConfirmationModal ( "Library Missing" , ` The Library Plugin needed for ${ config . info . 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
} ) ;
}
if ( ! window . BDFDB _Global . pluginQueue . includes ( config . info . name ) ) window . BDFDB _Global . pluginQueue . push ( config . info . 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" ) ;
2021-01-14 16:14:44 +01: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 ${ config . info . 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 ] ) => {
2020-11-19 16:51:14 +01:00
var badgeClasses , requestedUsers = { } , loadedUsers = { } , requestQueue = { queue : [ ] , timeout : null , id : null } , cacheTimeout ;
2020-09-19 20:49:33 +02:00
var nitroFlag , boostFlag ;
var settings = { } , badges = { } , indicators = { } ;
const miniTypes = [ "list" , "chat" ] ;
2020-10-09 21:09:35 +02:00
return class BadgesEverywhere extends Plugin {
2021-01-06 12:38:36 +01:00
onLoad ( ) {
2020-09-19 20:49:33 +02:00
this . patchedModules = {
after : {
MemberListItem : "render" ,
2020-10-07 10:20:55 +02:00
MessageUsername : "default" ,
2020-09-19 20:49:33 +02:00
UserPopout : "render"
}
} ;
2020-07-01 10:16:47 +02:00
2020-09-19 20:49:33 +02:00
this . defaults = {
settings : {
2020-11-19 16:51:14 +01:00
showInPopout : { value : true , description : "Show Badge in User Popout" } ,
showInChat : { value : true , description : "Show Badge in Chat Window" } ,
showInMemberList : { value : true , description : "Show Badge in Member List" } ,
useColoredVersion : { value : true , description : "Use colored version of the Badges for Chat and Members" } ,
showNitroDate : { value : true , description : "Show the subscription date for Nitro/Boost Badges" }
2020-04-13 20:06:13 +02:00
} ,
2020-09-19 20:49:33 +02:00
badges : {
"STAFF" : {
value : true ,
id : "Staff" ,
"name" : "STAFF_BADGE_TOOLTIP" ,
icon : "profileBadgeStaff" ,
size : 17
} ,
"PARTNER" : {
value : true ,
id : "Partner" ,
"name" : "PARTNER_BADGE_TOOLTIP" ,
icon : "profileBadgePartner" ,
size : 22
} ,
"HYPESQUAD" : {
value : true ,
id : "HypeSquad" ,
"name" : "HYPESQUAD_BADGE_TOOLTIP" ,
icon : "profileBadgeHypesquad" ,
size : 17
} ,
"BUG_HUNTER_LEVEL_1" : {
value : true ,
id : "BugHunter1" ,
"name" : "BUG_HUNTER_BADGE_TOOLTIP" ,
icon : "profileBadgeBugHunterLevel1" ,
size : 17 ,
suffix : "Level 1"
} ,
"BUG_HUNTER_LEVEL_2" : {
value : true ,
id : "BugHunter2" ,
"name" : "BUG_HUNTER_BADGE_TOOLTIP" ,
icon : "profileBadgeBugHunterLevel2" ,
size : 17 ,
suffix : "Level 2"
} ,
"VERIFIED_DEVELOPER" : {
value : true ,
id : "VerifiedDeveloper" ,
"name" : "VERIFIED_DEVELOPER_BADGE_TOOLTIP" ,
icon : "profileBadgeVerifiedDeveloper" ,
size : 17
} ,
"HYPESQUAD_ONLINE_HOUSE_1" : {
value : true ,
id : "HypeSquad1" ,
"name" : "HypeSquad Bravery" ,
icon : "profileBadgeHypeSquadOnlineHouse1" ,
size : 17
} ,
"HYPESQUAD_ONLINE_HOUSE_2" : {
value : true ,
id : "HypeSquad2" ,
"name" : "HypeSquad Brilliance" ,
icon : "profileBadgeHypeSquadOnlineHouse2" ,
size : 17
} ,
"HYPESQUAD_ONLINE_HOUSE_3" : {
value : true ,
id : "HypeSquad3" ,
"name" : "HypeSquad Balance" ,
icon : "profileBadgeHypeSquadOnlineHouse3" ,
size : 17
} ,
"PREMIUM_EARLY_SUPPORTER" : {
value : true ,
id : "EarlySupporter" ,
"name" : "EARLY_SUPPORTER_TOOLTIP" ,
icon : "profileBadgeEarlySupporter" ,
size : 24
} ,
"NITRO" : {
value : true ,
id : "Nitro" ,
"name" : "Nitro" ,
icon : "profileBadgePremium" ,
size : 21
} ,
"GUILD_BOOST" : {
value : true ,
id : "NitroGuildBoost" ,
"name" : "Nitro Guild Boost" ,
icon : "profileGuildSubscriberlvl" ,
size : 17 ,
types : [ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 ]
}
2020-04-13 20:06:13 +02:00
} ,
2020-09-19 20:49:33 +02:00
indicators : {
"CURRENT_GUILD_BOOST" : {
value : true ,
id : "CurrentGuildBoost" ,
"name" : "Current Nitro Guild Boost" ,
inner : ` <svg name="PremiumGuildSubscriberBadge" class=" ${ BDFDB . disCNS . memberpremiumicon + BDFDB . disCN . membericon } " aria-hidden="false" width="24" height="24" viewBox="0 0 8 12"><path d="M4 0L0 4V8L4 12L8 8V4L4 0ZM7 7.59L4 10.59L1 7.59V4.41L4 1.41L7 4.41V7.59Z" fill="currentColor"></path><path d="M2 4.83V7.17L4 9.17L6 7.17V4.83L4 2.83L2 4.83Z" fill="currentColor"></path></svg> `
} ,
}
} ;
this . css = `
2021-05-06 17:50:44 +02:00
$ { BDFDB . dotCN . _badgeseverywherebadges } {
display : flex ;
justify - content : center ;
align - items : center ;
}
$ { BDFDB . dotCN . _badgeseverywherebadgespopout } {
margin - top : 6 px ;
}
2020-09-19 20:49:33 +02:00
$ { BDFDB . dotCN . _badgeseverywherebadgeschat } {
display : inline - flex ;
position : relative ;
top : 2 px ;
}
2021-01-11 14:07:57 +01:00
$ { BDFDB . dotCNS . messagerepliedmessage + BDFDB . dotCN . _badgeseverywherebadgeschat } {
top : 0 ;
}
$ { BDFDB . dotCNS . messagecompact + BDFDB . dotCN . messageusername } ~ $ { BDFDB . dotCN . _badgeseverywherebadges } ,
$ { BDFDB . dotCNS . messagerepliedmessage + BDFDB . dotCN . messageusername } ~ $ { BDFDB . dotCN . _badgeseverywherebadges } {
2020-09-19 20:49:33 +02:00
margin - right : . 25 rem ;
text - indent : 0 ;
}
2021-01-11 14:07:57 +01:00
$ { BDFDB . dotCNS . messagerepliedmessage + BDFDB . dotCN . messageusername } ~ $ { BDFDB . dotCN . _badgeseverywherebadges } {
margin - left : 0 ;
}
2021-05-06 17:50:44 +02:00
$ { BDFDB . dotCN . _badgeseverywheremini } {
margin - left : 5 px ;
}
2020-09-19 20:49:33 +02:00
$ { BDFDB . dotCN . _badgeseverywherebadgesinner } {
display : inline - grid ;
grid - auto - flow : column ;
grid - gap : 6 px ;
}
$ { BDFDB . dotCNS . _badgeseverywheremini + BDFDB . dotCN . _badgeseverywherebadgesinner } {
grid - gap : 4 px ;
}
2020-11-23 19:20:23 +01:00
$ { BDFDB . dotCN . _badgeseverywherebadgessettings } {
color : var ( -- header - primary ) ;
}
2020-09-19 20:49:33 +02:00
$ { BDFDB . dotCN . _badgeseverywherebadge } {
background - size : contain ;
background - position : center ;
background - repeat : no - repeat ;
}
$ { BDFDB . dotCN . _badgeseverywhereindicator } {
display : flex ;
align - items : center ;
justify - content : center ;
}
$ { BDFDB . dotCN . _badgeseverywhereindicatorinner } {
position : static ! important ;
margin : 0 ! important ;
}
$ { BDFDB . dotCN . _badgeseverywherebadge } {
height : 17 px ! important ;
}
$ { BDFDB . dotCN . _badgeseverywheresize17 } {
width : 17 px ! important ; min - width : 17 px ! important ;
}
$ { BDFDB . dotCN . _badgeseverywheresize21 } {
width : 21 px ! important ; min - width : 21 px ! important ;
}
$ { BDFDB . dotCN . _badgeseverywheresize22 } {
width : 22 px ! important ; min - width : 22 px ! important ;
}
$ { BDFDB . dotCN . _badgeseverywheresize24 } {
width : 24 px ! important ; min - width : 24 px ! important ;
}
$ { BDFDB . dotCN . _badgeseverywhereindicator } {
height : 14 px ! important ; min - height : 14 px ! important ; width : 14 px ! important ; min - width : 14 px ! important ;
}
$ { BDFDB . dotCN . _badgeseverywhereindicatorinner } {
height : inherit ! important ; min - height : inherit ! important ; width : inherit ! important ; min - width : inherit ! important ;
}
$ { BDFDB . dotCNS . _badgeseverywheremini + BDFDB . dotCN . _badgeseverywherebadge } {
height : 14 px ! important ;
}
$ { BDFDB . dotCNS . _badgeseverywheremini + BDFDB . dotCN . _badgeseverywheresize17 } {
width : 14 px ! important ; min - width : 14 px ! important ;
}
$ { BDFDB . dotCNS . _badgeseverywheremini + BDFDB . dotCN . _badgeseverywheresize21 } {
width : 18 px ! important ; min - width : 18 px ! important ;
}
$ { BDFDB . dotCNS . _badgeseverywheremini + BDFDB . dotCN . _badgeseverywheresize22 } {
width : 18 px ! important ; min - width : 18 px ! important ;
}
$ { BDFDB . dotCNS . _badgeseverywheremini + BDFDB . dotCN . _badgeseverywheresize24 } {
width : 19 px ! important ; min - width : 19 px ! important ;
}
$ { BDFDB . dotCNS . _badgeseverywheremini + BDFDB . dotCN . _badgeseverywhereindicator } {
height : 12 px ! important ; min - height : 12 px ! important ; width : 12 px ! important ; min - width : 12 px ! important ;
}
# app - mount $ { BDFDB . dotCNS . _badgeseverywherebadgessettings + BDFDB . dotCN . _badgeseverywherebadge } {
width : 30 px ! important ; min - width : 30 px ! important ;
}
2020-10-15 18:30:46 +02:00
$ { BDFDB . dotCN . _badgeseverywherebadgesinner + BDFDB . notCNS . userbadgescolored + BDFDB . dotCN . _badgeseverywherebadge } svg {
2020-09-19 20:49:33 +02:00
color : unset ! important ;
2020-04-13 20:06:13 +02:00
}
2018-10-11 10:21:26 +02:00
2020-09-19 20:49:33 +02:00
$ { BDFDB . dotCNS . member + BDFDB . dotCN . memberpremiumicon + BDFDB . notCN . _badgeseverywhereindicatorinner } { display : none ; }
` ;
2018-10-11 10:21:26 +02:00
2020-09-19 20:49:33 +02:00
for ( let flagName in BDFDB . DiscordConstants . UserFlags ) if ( this . defaults . badges [ flagName ] ) {
if ( BDFDB . LanguageUtils . LanguageStringsCheck [ this . defaults . badges [ flagName ] . name ] ) this . defaults . badges [ flagName ] . name = BDFDB . LanguageUtils . LanguageStrings [ this . defaults . badges [ flagName ] . name ] ;
this . defaults . badges [ BDFDB . DiscordConstants . UserFlags [ flagName ] ] = this . defaults . badges [ flagName ] ;
delete this . defaults . badges [ flagName ] ;
}
nitroFlag = Math . max ( ... BDFDB . ObjectUtils . toArray ( BDFDB . DiscordConstants . UserFlags ) ) * 2 ;
this . defaults . badges [ nitroFlag ] = this . defaults . badges . NITRO ;
delete this . defaults . badges . NITRO ;
boostFlag = nitroFlag * 2 ;
this . defaults . badges [ boostFlag ] = this . defaults . badges . GUILD _BOOST ;
delete this . defaults . badges . GUILD _BOOST ;
for ( let flag in this . defaults . badges ) if ( ! this . defaults . badges [ flag ] . icon || isNaN ( parseInt ( flag ) ) ) delete this . defaults . badges [ flag ] ;
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 ( ) {
2020-10-14 19:24:48 +02:00
badgeClasses = BDFDB . DiscordClassModules . UserBadges || { } ;
2019-01-26 22:45:19 +01:00
2020-02-04 08:20:40 +01:00
requestedUsers = { } , loadedUsers = { } ;
2020-11-19 16:51:14 +01:00
requestQueue = { queue : [ ] , timeout : null , id : null } ;
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" ) ;
}
2020-09-11 19:31:36 +02:00
BDFDB . PatchUtils . patch ( this , BDFDB . LibraryModules . DispatchApiUtils , "dispatch" , { after : e => {
2020-07-01 10:16:47 +02:00
if ( BDFDB . ObjectUtils . is ( e . methodArguments [ 0 ] ) && e . methodArguments [ 0 ] . type == BDFDB . DiscordConstants . ActionTypes . USER _PROFILE _MODAL _FETCH _SUCCESS && e . methodArguments [ 0 ] . user ) {
let userCopy = Object . assign ( { } , e . methodArguments [ 0 ] . user ) ;
2020-09-19 20:49:33 +02:00
if ( e . methodArguments [ 0 ] . premium _since ) userCopy . flags += nitroFlag ;
2020-07-01 10:16:47 +02:00
userCopy . premium _since = e . methodArguments [ 0 ] . premium _since ;
2020-09-19 20:49:33 +02:00
if ( e . methodArguments [ 0 ] . premium _guild _since ) userCopy . flags += boostFlag ;
2020-07-01 10:16:47 +02:00
userCopy . premium _guild _since = e . methodArguments [ 0 ] . premium _guild _since ;
loadedUsers [ e . methodArguments [ 0 ] . user . id ] = BDFDB . ObjectUtils . extract ( userCopy , "flags" , "premium_since" , "premium_guild_since" ) ;
loadedUsers [ e . methodArguments [ 0 ] . user . 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 == e . methodArguments [ 0 ] . user . id ) {
while ( requestedUsers [ requestQueue . id ] . length ) BDFDB . ReactUtils . forceUpdate ( requestedUsers [ requestQueue . id ] . pop ( ) ) ;
requestQueue . id = null ;
BDFDB . TimeUtils . timeout ( _ => { this . runQueue ( ) ; } , 1000 ) ;
}
}
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 = { } ) {
let settingsPanel , settingsItems = [ ] , innerItems = [ ] ;
for ( let key in settings ) settingsItems . push ( BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . SettingsSaveItem , {
type : "Switch" ,
plugin : this ,
keys : [ "settings" , key ] ,
label : this . defaults . settings [ key ] . description ,
value : settings [ key ]
} ) ) ;
for ( let flag in badges ) innerItems . push ( BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . SettingsSaveItem , {
type : "Switch" ,
plugin : this ,
keys : [ "badges" , flag ] ,
label : this . defaults . badges [ flag ] . name + ( this . defaults . badges [ flag ] . suffix ? ` ${ this . defaults . badges [ flag ] . suffix } ` : "" ) ,
value : badges [ flag ] ,
2021-02-05 21:45:34 +01:00
labelChildren : this . createSettingsBadges ( flag )
2020-09-19 20:49:33 +02:00
} ) ) ;
for ( let flag in indicators ) innerItems . push ( BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . SettingsSaveItem , {
type : "Switch" ,
plugin : this ,
keys : [ "indicators" , flag ] ,
label : this . defaults . indicators [ flag ] . name + ( this . defaults . indicators [ flag ] . suffix ? ` ${ this . defaults . indicators [ flag ] . suffix } ` : "" ) ,
value : indicators [ flag ] ,
2021-02-05 21:45:34 +01:00
labelChildren : this . createSettingsBadges ( flag )
2020-09-19 20:49:33 +02:00
} ) ) ;
2020-12-15 10:35:30 +01:00
settingsItems . push ( BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . SettingsPanelList , {
2020-11-19 16:45:36 +01:00
title : "Display Badges:" ,
2020-09-19 20:49:33 +02:00
children : innerItems
} ) ) ;
return settingsPanel = BDFDB . PluginUtils . createSettingsPanel ( this , 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-01-06 12:38:36 +01:00
forceUpdateAll ( ) {
2020-09-19 20:49:33 +02:00
settings = BDFDB . DataUtils . get ( this , "settings" ) ;
badges = BDFDB . DataUtils . get ( this , "badges" ) ;
indicators = BDFDB . DataUtils . get ( this , "indicators" ) ;
BDFDB . PatchUtils . forceAllUpdates ( this ) ;
BDFDB . MessageUtils . rerenderAll ( ) ;
2020-02-04 08:20:40 +01:00
}
2019-09-04 12:34:02 +02:00
2020-09-19 20:49:33 +02:00
processMemberListItem ( e ) {
if ( e . instance . props . user && settings . showInMemberList ) {
this . injectBadges ( e . instance , BDFDB . ObjectUtils . get ( e . returnvalue , "props.decorators.props.children" ) , e . instance . props . user , "list" ) ;
}
2020-02-04 08:20:40 +01:00
}
2019-01-26 22:45:19 +01:00
2020-10-07 10:20:55 +02:00
processMessageUsername ( e ) {
2020-09-19 20:49:33 +02:00
if ( e . instance . props . message && settings . showInChat ) {
2020-10-07 10:20:55 +02:00
this . injectBadges ( e . instance , e . returnvalue . props . children , e . instance . props . message . author , "chat" ) ;
2020-09-19 20:49:33 +02:00
}
2020-02-04 08:20:40 +01:00
}
2020-09-19 20:49:33 +02:00
processUserPopout ( e ) {
if ( e . instance . props . user && settings . showInPopout ) {
let [ children , index ] = BDFDB . ReactUtils . findParent ( e . returnvalue , { name : "CustomStatus" } ) ;
if ( index > - 1 ) this . injectBadges ( e . instance , children , e . instance . props . user , "popout" , e . instance . props . activity && e . instance . props . activity . type != BDFDB . DiscordConstants . ActivityTypes . CUSTOM _STATUS ) ;
2020-07-01 10:16:47 +02:00
}
}
2019-01-26 22:45:19 +01:00
2020-09-19 20:49:33 +02:00
injectBadges ( instance , children , user , type , colored ) {
if ( ! BDFDB . ArrayUtils . is ( children ) || ! user || user . bot ) return ;
if ( loadedUsers [ user . id ] && ( ( new Date ( ) ) . getTime ( ) - loadedUsers [ user . id ] . date < 1000 * 60 * 60 * 24 * 7 ) ) children . push ( this . createBadges ( user , type , colored ) ) ;
else if ( ! BDFDB . ArrayUtils . is ( requestedUsers [ user . id ] ) ) {
requestedUsers [ user . id ] = [ instance ] ;
requestQueue . queue . push ( user . id ) ;
this . runQueue ( ) ;
}
else requestedUsers [ user . id ] . push ( instance ) ;
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
createWrapper ( renderedBadges , type , uncolored ) {
return BDFDB . ReactUtils . createElement ( "div" , {
className : BDFDB . DOMUtils . formatClassName ( BDFDB . disCN . _badgeseverywherebadges , BDFDB . disCN [ ` _badgeseverywherebadges ${ type } ` ] , miniTypes . includes ( type ) && BDFDB . disCN . _badgeseverywheremini ) ,
2020-10-14 19:24:48 +02:00
children : BDFDB . ReactUtils . createElement ( "div" , {
2021-04-23 20:35:45 +02:00
className : BDFDB . DOMUtils . formatClassName ( BDFDB . disCN . _badgeseverywherebadgesinner , ! uncolored && BDFDB . disCN . userbadgescolored ) ,
2020-10-14 19:24:48 +02:00
children : renderedBadges
} )
2020-09-19 20:49:33 +02:00
} ) ;
}
createBadges ( user , type , uncolored ) {
2020-07-01 10:16:47 +02:00
let renderedBadges = [ ] ;
2020-09-19 20:49:33 +02:00
for ( let flag in badges ) if ( ( loadedUsers [ user . id ] . flags | flag ) == loadedUsers [ user . id ] . flags && badges [ flag ] ) {
renderedBadges . push ( this . createBadge ( settings . showNitroDate ? this . getTimeString ( user . id , flag ) : null , type , flag , flag == boostFlag ? BDFDB . LibraryModules . GuildBoostUtils . getUserLevel ( loadedUsers [ user . id ] . premium _guild _since ) : null ) ) ;
}
let member = BDFDB . LibraryModules . MemberStore . getMember ( BDFDB . LibraryModules . LastGuildStore . getGuildId ( ) , user . id ) ;
if ( indicators . CURRENT _GUILD _BOOST && member && member . premiumSince ) {
renderedBadges . push ( this . createBadge ( settings . showNitroDate ? this . getTimeString ( user . id , "CURRENT_GUILD_BOOST" ) : null , type , "CURRENT_GUILD_BOOST" ) ) ;
}
if ( ! renderedBadges . length ) return null ;
else return this . createWrapper ( renderedBadges , type , uncolored == undefined ? ! settings . useColoredVersion : uncolored ) ;
2020-02-04 08:20:40 +01:00
}
2020-09-19 20:49:33 +02:00
createBadge ( timestring , type , flag , rank ) {
let data = this . defaults . badges [ flag ] || this . defaults . indicators [ flag ] ;
if ( ! data ) return null ;
let inner = data . inner && BDFDB . ReactUtils . elementToReact ( BDFDB . DOMUtils . create ( data . inner ) ) ;
if ( inner ) inner . props . className = BDFDB . DOMUtils . formatClassName ( BDFDB . disCN . _badgeseverywhereindicatorinner , inner . props . className ) ;
else inner = null ;
return BDFDB . ReactUtils . createElement ( BDFDB . LibraryComponents . TooltipContainer , {
text : timestring || ( data . name + ( data . suffix ? ` ${ data . suffix } ` : "" ) + ( rank ? ` Level ${ rank } ` : "" ) ) ,
tooltipConfig : { style : "white-space: nowrap; max-width: unset;" } ,
children : BDFDB . ReactUtils . createElement ( "div" , {
className : BDFDB . DOMUtils . formatClassName ( BDFDB . disCN . _badgeseverywherebadge , data . inner && BDFDB . disCN . _badgeseverywhereindicator , data . icon && badgeClasses [ data . icon + ( rank || "" ) ] , data . size && BDFDB . disCN [ ` _badgeseverywheresize ${ data . size } ` ] ) ,
badgeId : data . id ,
children : inner
} )
} ) ;
2019-06-07 11:39:54 +02:00
}
2020-06-08 10:34:09 +02:00
2020-09-19 20:49:33 +02:00
getTimeString ( id , flag ) {
let member = BDFDB . LibraryModules . MemberStore . getMember ( BDFDB . LibraryModules . LastGuildStore . getGuildId ( ) , id ) ;
if ( flag == nitroFlag ) return BDFDB . LanguageUtils . LanguageStringsFormat ( "PREMIUM_BADGE_TOOLTIP" , new Date ( loadedUsers [ id ] . premium _since ) ) ;
else if ( flag == boostFlag ) return BDFDB . LanguageUtils . LanguageStringsFormat ( "PREMIUM_GUILD_SUBSCRIPTION_TOOLTIP" , new Date ( loadedUsers [ id ] . premium _guild _since ) ) ;
else if ( member && flag == "CURRENT_GUILD_BOOST" ) return BDFDB . LanguageUtils . LanguageStringsFormat ( "PREMIUM_GUILD_SUBSCRIPTION_TOOLTIP" , new Date ( member . premiumSince ) ) ;
return null ;
}
createSettingsBadges ( flag ) {
let data = this . defaults . badges [ flag ] || this . defaults . indicators [ flag ] ;
if ( ! data ) return null ;
let eles = null ;
if ( Array . isArray ( data . types ) ) {
let renderedBadges = [ ] ;
for ( let rank of data . types ) renderedBadges . push ( this . createBadge ( null , "settings" , flag , rank ) ) ;
eles = BDFDB . ReactUtils . createElement ( "div" , { children : [ this . createWrapper ( renderedBadges , "settings" , false ) , BDFDB . ReactUtils . createElement ( "br" ) , this . createWrapper ( renderedBadges , "settings" , true ) ] } ) ;
}
else {
let badge = this . createBadge ( null , "settings" , flag ) ;
eles = [ this . createWrapper ( badge , "settings" , false ) , this . createWrapper ( badge , "settings" , true ) ] ;
}
return eles ;
}
} ;
2020-10-09 21:09:35 +02:00
} ) ( window . BDFDB _Global . PluginUtils . buildPlugin ( config ) ) ;
2020-09-19 20:49:33 +02:00
} ) ( ) ;