2019-09-20 22:32:52 +02:00
|
|
|
//META{"name":"BadgesEverywhere","website":"https://github.com/mwittrien/BetterDiscordAddons/tree/master/Plugins/BadgesEverywhere","source":"https://raw.githubusercontent.com/mwittrien/BetterDiscordAddons/master/Plugins/BadgesEverywhere/BadgesEverywhere.plugin.js"}*//
|
2018-10-16 21:33:23 +02:00
|
|
|
|
2018-10-11 10:21:26 +02:00
|
|
|
class BadgesEverywhere {
|
2019-03-06 14:00:44 +01:00
|
|
|
getName () {return "BadgesEverywhere";}
|
2019-01-11 18:57:49 +01:00
|
|
|
|
2019-10-30 14:03:32 +01:00
|
|
|
getVersion () {return "1.4.7";}
|
2019-01-11 18:57:49 +01:00
|
|
|
|
|
|
|
getAuthor () {return "DevilBro";}
|
|
|
|
|
2019-10-30 14:03:32 +01:00
|
|
|
getDescription () {return "Displays Badges (Nitro, HypeSquad, etc...) in the chat/memberlist/userpopout.";}
|
2019-01-26 22:45:19 +01:00
|
|
|
|
2019-09-04 12:34:02 +02:00
|
|
|
constructor () {
|
2019-05-12 09:33:50 +02:00
|
|
|
this.changelog = {
|
2019-10-30 14:03:32 +01:00
|
|
|
"improved":[["New Library Structure & React","Restructured my Library and switched to React rendering instead of DOM manipulation"]]
|
2019-05-12 09:33:50 +02:00
|
|
|
};
|
2019-09-04 12:34:02 +02:00
|
|
|
|
2018-12-27 10:16:30 +01:00
|
|
|
this.patchModules = {
|
2019-10-30 14:03:32 +01:00
|
|
|
"MemberListItem":"render",
|
|
|
|
"MessageUsername":"render",
|
|
|
|
"UserPopout":"render"
|
2018-12-27 10:16:30 +01:00
|
|
|
};
|
2019-09-04 12:34:02 +02:00
|
|
|
}
|
2019-01-26 22:45:19 +01:00
|
|
|
|
2019-09-04 12:34:02 +02:00
|
|
|
initConstructor () {
|
2019-06-03 21:24:55 +02:00
|
|
|
this.css = `
|
2018-10-11 10:21:26 +02:00
|
|
|
.BE-badge {
|
2019-06-02 14:36:54 +02:00
|
|
|
position: relative;
|
2019-05-12 09:33:50 +02:00
|
|
|
background-size: contain;
|
|
|
|
background-position: center;
|
|
|
|
background-repeat: no-repeat;
|
2019-06-02 14:36:54 +02:00
|
|
|
display: inline-flex;
|
|
|
|
align-items: center;
|
2019-06-04 09:17:54 +02:00
|
|
|
justify-content: center;
|
2019-10-30 14:03:32 +01:00
|
|
|
margin: 0 2px;
|
|
|
|
}
|
|
|
|
.BE-badge.BE-badge-popout {
|
|
|
|
margin-top: 6px;
|
2018-10-11 10:21:26 +02:00
|
|
|
}
|
2019-06-02 14:36:54 +02:00
|
|
|
.BE-badge.BE-badge-popout:not(.BE-badge-CurrentGuildBoost) {
|
2019-10-30 14:03:32 +01:00
|
|
|
top: 3px;
|
2018-10-11 10:21:26 +02:00
|
|
|
}
|
2019-07-26 11:10:09 +02:00
|
|
|
.BE-badge.BE-badge-popout.BE-badge-CurrentGuildBoost {
|
2019-10-30 14:03:32 +01:00
|
|
|
top: 1px;
|
2019-06-07 11:39:54 +02:00
|
|
|
}
|
2019-10-30 14:03:32 +01:00
|
|
|
.BE-badge.BE-badge-list:not(.BE-badge-CurrentGuildBoost) {
|
|
|
|
top: 1px;
|
2019-06-04 09:15:56 +02:00
|
|
|
}
|
2019-07-28 15:55:42 +02:00
|
|
|
.BE-badge.BE-badge-chat:not(.BE-badge-CurrentGuildBoost) {
|
2019-10-30 14:03:32 +01:00
|
|
|
top: 2px;
|
2019-07-28 15:55:42 +02:00
|
|
|
}
|
|
|
|
.BE-badge.BE-badge-chat.BE-badge-CurrentGuildBoost {
|
2019-10-30 14:03:32 +01:00
|
|
|
top: 1px;
|
2018-10-11 10:21:26 +02:00
|
|
|
}
|
2019-06-02 14:36:54 +02:00
|
|
|
${BDFDB.dotCN.userprofiletopsectionplaying} .BE-badge.BE-badge-CurrentGuildBoost svg {
|
|
|
|
color: white !important;
|
|
|
|
}
|
2019-10-30 14:03:32 +01:00
|
|
|
.BE-badge {height:17px !important;}
|
|
|
|
.BE-badge.BE-size-17 {width:17px !important; min-width:17px !important;}
|
|
|
|
.BE-badge.BE-size-21 {width:21px !important; min-width:21px !important;}
|
|
|
|
.BE-badge.BE-size-22 {width:22px !important; min-width:22px !important;}
|
|
|
|
.BE-badge.BE-size-24 {width:24px !important; min-width:24px !important;}
|
|
|
|
.BE-badge.BE-badge-mini {height:14px !important;}
|
|
|
|
.BE-badge.BE-badge-mini.BE-size-17 {width:14px !important; min-width:14px !important;}
|
|
|
|
.BE-badge.BE-badge-mini.BE-size-21 {width:18px !important; min-width:18px !important;}
|
|
|
|
.BE-badge.BE-badge-mini.BE-size-22 {width:18px !important; min-width:18px !important;}
|
|
|
|
.BE-badge.BE-badge-mini.BE-size-24 {width:19px !important; min-width:19px !important;}
|
|
|
|
|
|
|
|
.BE-badge.BE-badge-mini:first-of-type {
|
|
|
|
margin-left: 5px;
|
|
|
|
}
|
|
|
|
.BE-badge.BE-badge-mini:last-of-type {
|
|
|
|
margin-right: 0;
|
|
|
|
}
|
2019-09-04 12:34:02 +02:00
|
|
|
|
2019-07-28 18:04:17 +02:00
|
|
|
.BE-badge.BE-badge-CurrentGuildBoost {height:14px !important; width:14px !important; min-width:14px !important;}
|
2019-09-04 12:34:02 +02:00
|
|
|
|
2019-09-26 10:08:49 +02:00
|
|
|
#app-mount .BE-badge.BE-badge-settings {width:30px !important;min-width:30px !important;}
|
2019-09-04 12:34:02 +02:00
|
|
|
|
|
|
|
${BDFDB.dotCNS.member + BDFDB.dotCN.memberpremiumicon}:not(.BE-badge-CurrentGuildBoost-inner) {display: none;}`;
|
2019-01-26 22:45:19 +01:00
|
|
|
|
2018-10-11 10:21:26 +02:00
|
|
|
this.requestedusers = {};
|
|
|
|
this.loadedusers = {};
|
2019-01-26 22:45:19 +01:00
|
|
|
|
2018-10-11 10:21:26 +02:00
|
|
|
this.defaults = {
|
|
|
|
settings: {
|
2018-12-12 00:11:53 +01:00
|
|
|
showInPopout: {value:true, description:"Show Badge in User Popout."},
|
2018-10-11 10:21:26 +02:00
|
|
|
showInChat: {value:true, description:"Show Badge in Chat Window."},
|
|
|
|
showInMemberList: {value:true, description:"Show Badge in Member List."},
|
2019-05-20 14:53:31 +02:00
|
|
|
useColoredVersion: {value:true, description:"Use colored version of the Badges for Chat and Members."},
|
2019-06-02 14:36:54 +02:00
|
|
|
showNitroDate: {value:true, description:"Show the subscription date for Nitro/Boost Badges"}
|
2019-01-11 18:57:49 +01:00
|
|
|
},
|
|
|
|
badges: {
|
2019-07-28 18:04:17 +02:00
|
|
|
"STAFF": {value:true, id:"Staff", name:"STAFF_BADGE_TOOLTIP", selector:"profileBadgeStaff", size:17},
|
|
|
|
"PARTNER": {value:true, id:"Partner", name:"PARTNER_BADGE_TOOLTIP", selector:"profileBadgePartner", size:22},
|
|
|
|
"HYPESQUAD": {value:true, id:"HypeSquad", name:"HYPESQUAD_BADGE_TOOLTIP", selector:"profileBadgeHypesquad", size:17},
|
|
|
|
"BUG_HUNTER": {value:true, id:"BugHunter", name:"BUG_HUNTER_BADGE_TOOLTIP", selector:"profileBadgeBugHunter", size:17},
|
|
|
|
"MFA_SMS": {value:false, id:null, name:null, selector:false, size:0},
|
|
|
|
"PREMIUM_PROMO_DISMISSED": {value:false, id:null, name:null, selector:false, size:0},
|
|
|
|
"HYPESQUAD_ONLINE_HOUSE_1": {value:true, id:"HypeSquadBravery", name:"HypeSquad Bravery", selector:"profileBadgeHypeSquadOnlineHouse1", size:17},
|
|
|
|
"HYPESQUAD_ONLINE_HOUSE_2": {value:true, id:"HypeSquadBrilliance", name:"HypeSquad Brilliance", selector:"profileBadgeHypeSquadOnlineHouse2", size:17},
|
|
|
|
"HYPESQUAD_ONLINE_HOUSE_3": {value:true, id:"HypeSquadBalance", name:"HypeSquad Balance", selector:"profileBadgeHypeSquadOnlineHouse3", size:17},
|
|
|
|
"PREMIUM_EARLY_SUPPORTER": {value:true, id:"EarlySupporter", name:"EARLY_SUPPORTER_TOOLTIP", selector:"profileBadgeEarlySupporter", size:24},
|
|
|
|
"NITRO": {value:true, id:"Nitro", name:"Nitro", selector:"profileBadgePremium", size:21},
|
|
|
|
"GUILD_BOOST": {value:true, id:"NitroGuildBoost", name:"Nitro Guild Boost", selector:"profileGuildSubscriberlvl", size:17, types:[1,2,3,4]},
|
2019-05-31 10:31:01 +02:00
|
|
|
},
|
2019-06-02 14:36:54 +02:00
|
|
|
indicators: {
|
2019-10-17 18:54:51 +02:00
|
|
|
"CURRENT_GUILD_BOOST": {value:true, id:"CurrentGuildBoost", name:"Current Nitro Guild Boost", inner:`<svg name="PremiumGuildSubscriberBadge" class="BE-badge-CurrentGuildBoost-inner ${BDFDB.disCNS.memberpremiumicon + BDFDB.disCN.membericon}" aria-hidden="false" width="24" height="24" viewBox="0 0 8 12" style="margin: 0;"><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>`},
|
2018-10-11 10:21:26 +02:00
|
|
|
}
|
|
|
|
};
|
2019-09-04 12:34:02 +02:00
|
|
|
|
2019-09-11 12:14:43 +02:00
|
|
|
for (let flagname in BDFDB.DiscordConstants.UserFlags) if (this.defaults.badges[flagname]) {
|
2019-10-19 11:41:39 +02:00
|
|
|
if (BDFDB.LanguageUtils.LanguageStringsCheck[this.defaults.badges[flagname].name]) this.defaults.badges[flagname].name = BDFDB.LanguageUtils.LanguageStrings[this.defaults.badges[flagname].name];
|
2019-09-11 12:14:43 +02:00
|
|
|
this.defaults.badges[BDFDB.DiscordConstants.UserFlags[flagname]] = this.defaults.badges[flagname];
|
2019-05-21 15:45:43 +02:00
|
|
|
delete this.defaults.badges[flagname];
|
|
|
|
}
|
2019-09-11 12:14:43 +02:00
|
|
|
this.nitroflag = Math.pow(2, Object.keys(BDFDB.DiscordConstants.UserFlags).length);
|
2019-05-21 15:45:43 +02:00
|
|
|
this.defaults.badges[this.nitroflag] = this.defaults.badges.NITRO;
|
|
|
|
delete this.defaults.badges.NITRO;
|
2019-09-11 12:14:43 +02:00
|
|
|
this.boostflag = Math.pow(2, Object.keys(BDFDB.DiscordConstants.UserFlags).length + 1);
|
2019-06-02 14:36:54 +02:00
|
|
|
this.defaults.badges[this.boostflag] = this.defaults.badges.GUILD_BOOST;
|
|
|
|
delete this.defaults.badges.GUILD_BOOST;
|
2019-05-21 15:45:43 +02:00
|
|
|
for (let flag in this.defaults.badges) if (!this.defaults.badges[flag].selector || isNaN(parseInt(flag))) delete this.defaults.badges[flag];
|
2018-10-11 10:21:26 +02:00
|
|
|
}
|
2019-01-26 22:45:19 +01:00
|
|
|
|
2018-10-11 10:21:26 +02:00
|
|
|
getSettingsPanel () {
|
2019-01-22 11:28:32 +01:00
|
|
|
if (!global.BDFDB || typeof BDFDB != "object" || !BDFDB.loaded || !this.started) return;
|
2019-10-22 23:04:35 +02:00
|
|
|
let settings = BDFDB.DataUtils.get(this, "settings");
|
2019-11-01 22:47:23 +01:00
|
|
|
let badges = BDFDB.DataUtils.get(this, "badges");
|
|
|
|
let indicators = BDFDB.DataUtils.get(this, "indicators");
|
|
|
|
let settingsitems = [], inneritems = [];
|
2019-10-17 18:54:51 +02:00
|
|
|
|
2019-10-22 18:55:25 +02:00
|
|
|
for (let key in settings) settingsitems.push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsSwitch, {
|
2019-10-17 18:54:51 +02:00
|
|
|
className: BDFDB.disCN.marginbottom8,
|
|
|
|
plugin: this,
|
|
|
|
keys: ["settings", key],
|
|
|
|
label: this.defaults.settings[key].description,
|
|
|
|
value: settings[key]
|
|
|
|
}));
|
2019-10-22 18:55:25 +02:00
|
|
|
for (let flag in badges) inneritems.push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsSwitch, {
|
2019-10-17 18:54:51 +02:00
|
|
|
className: BDFDB.disCN.marginbottom8,
|
|
|
|
plugin: this,
|
|
|
|
keys: ["badges", flag],
|
|
|
|
label: this.defaults.badges[flag].name,
|
|
|
|
value: badges[flag],
|
2019-10-30 14:03:32 +01:00
|
|
|
labelchildren: this.createSettingsBadges(flag)
|
2019-10-17 18:54:51 +02:00
|
|
|
}));
|
2019-10-22 18:55:25 +02:00
|
|
|
for (let flag in indicators) inneritems.push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsSwitch, {
|
2019-10-17 18:54:51 +02:00
|
|
|
className: BDFDB.disCN.marginbottom8,
|
|
|
|
plugin: this,
|
|
|
|
keys: ["indicators", flag],
|
|
|
|
label: this.defaults.indicators[flag].name,
|
|
|
|
value: indicators[flag],
|
2019-10-30 14:03:32 +01:00
|
|
|
labelchildren: this.createSettingsBadges(flag)
|
2019-10-17 18:54:51 +02:00
|
|
|
}));
|
2019-10-22 18:55:25 +02:00
|
|
|
settingsitems.push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsPanelInner, {
|
2019-10-17 18:54:51 +02:00
|
|
|
title: "Display Badges:",
|
2019-11-05 08:56:21 +01:00
|
|
|
first: settingsitems.length == 0,
|
2019-11-05 08:59:26 +01:00
|
|
|
last: true,
|
2019-10-17 18:54:51 +02:00
|
|
|
children: inneritems
|
|
|
|
}));
|
|
|
|
|
2019-10-22 18:55:25 +02:00
|
|
|
return BDFDB.PluginUtils.createSettingsPanel(this, settingsitems);
|
2018-10-11 10:21:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//legacy
|
|
|
|
load () {}
|
|
|
|
|
|
|
|
start () {
|
2019-02-04 09:13:15 +01:00
|
|
|
if (!global.BDFDB) global.BDFDB = {myPlugins:{}};
|
|
|
|
if (global.BDFDB && global.BDFDB.myPlugins && typeof global.BDFDB.myPlugins == "object") global.BDFDB.myPlugins[this.getName()] = this;
|
2019-05-26 13:55:26 +02:00
|
|
|
var libraryScript = document.querySelector('head script#BDFDBLibraryScript');
|
|
|
|
if (!libraryScript || (performance.now() - libraryScript.getAttribute("date")) > 600000) {
|
2018-10-11 10:21:26 +02:00
|
|
|
if (libraryScript) libraryScript.remove();
|
|
|
|
libraryScript = document.createElement("script");
|
2019-05-26 13:55:26 +02:00
|
|
|
libraryScript.setAttribute("id", "BDFDBLibraryScript");
|
2018-10-11 10:21:26 +02:00
|
|
|
libraryScript.setAttribute("type", "text/javascript");
|
2019-10-18 10:56:41 +02:00
|
|
|
libraryScript.setAttribute("src", "https://mwittrien.github.io/BetterDiscordAddons/Plugins/BDFDB.min.js");
|
2019-01-17 23:48:29 +01:00
|
|
|
libraryScript.setAttribute("date", performance.now());
|
2019-05-26 13:55:26 +02:00
|
|
|
libraryScript.addEventListener("load", () => {this.initialize();});
|
2018-10-11 10:21:26 +02:00
|
|
|
document.head.appendChild(libraryScript);
|
2019-05-26 13:55:26 +02:00
|
|
|
}
|
|
|
|
else if (global.BDFDB && typeof BDFDB === "object" && BDFDB.loaded) this.initialize();
|
2019-11-01 10:27:07 +01:00
|
|
|
this.startTimeout = setTimeout(() => {
|
|
|
|
try {return this.initialize();}
|
|
|
|
catch (err) {console.error(`%c[${this.getName()}]%c`, "color: #3a71c1; font-weight: 700;", "", "Fatal Error: Could not initiate plugin! " + err);}
|
|
|
|
}, 30000);
|
2018-10-11 10:21:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
initialize () {
|
2019-01-17 23:48:29 +01:00
|
|
|
if (global.BDFDB && typeof BDFDB === "object" && BDFDB.loaded) {
|
2019-01-22 11:05:54 +01:00
|
|
|
if (this.started) return;
|
2019-10-22 18:55:25 +02:00
|
|
|
BDFDB.PluginUtils.init(this);
|
2019-01-26 22:45:19 +01:00
|
|
|
|
2019-10-22 18:55:25 +02:00
|
|
|
this.BadgeClasses = BDFDB.ModuleUtils.findByProperties("profileBadgeStaff", "profileBadgePremium");
|
2019-01-26 22:45:19 +01:00
|
|
|
|
2019-10-22 18:55:25 +02:00
|
|
|
BDFDB.ModuleUtils.forceAllUpdates(this);
|
2018-10-11 10:21:26 +02:00
|
|
|
}
|
2019-11-01 10:14:50 +01:00
|
|
|
else console.error(`%c[${this.getName()}]%c`, "color: #3a71c1; font-weight: 700;", "", "Fatal Error: Could not load BD functions!");
|
2018-10-11 10:21:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
stop () {
|
2019-01-17 23:48:29 +01:00
|
|
|
if (global.BDFDB && typeof BDFDB === "object" && BDFDB.loaded) {
|
2019-10-22 11:37:23 +02:00
|
|
|
this.stopping = true;
|
2019-10-30 14:03:32 +01:00
|
|
|
|
2019-10-22 18:55:25 +02:00
|
|
|
BDFDB.PluginUtils.clear(this);
|
2018-10-11 10:21:26 +02:00
|
|
|
}
|
|
|
|
}
|
2019-01-26 22:45:19 +01:00
|
|
|
|
|
|
|
|
2018-10-11 10:21:26 +02:00
|
|
|
// begin of own functions
|
2019-01-26 22:45:19 +01:00
|
|
|
|
2019-10-30 14:03:32 +01:00
|
|
|
onSettingsClosed () {
|
|
|
|
if (this.SettingsUpdated) {
|
|
|
|
delete this.SettingsUpdated;
|
|
|
|
BDFDB.ModuleUtils.forceAllUpdates(this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-29 18:55:11 +01:00
|
|
|
processMemberListItem (e) {
|
2019-10-30 14:03:32 +01:00
|
|
|
if (!BDFDB.DataUtils.get(this, "settings", "showInMemberList")) return;
|
|
|
|
if (e.instance.props.user) this.injectBadges(e.instance, BDFDB.ReactUtils.getValue(e.returnvalue, "props.decorators.props.children"), e.instance.props.user, "list");
|
2018-12-27 10:16:30 +01:00
|
|
|
}
|
2019-01-26 22:45:19 +01:00
|
|
|
|
2019-10-29 18:55:11 +01:00
|
|
|
processMessageUsername (e) {
|
2019-10-30 14:03:32 +01:00
|
|
|
if (!BDFDB.DataUtils.get(this, "settings", "showInChat")) return;
|
|
|
|
let user = BDFDB.ReactUtils.getValue(e.instance, "props.message.author");
|
|
|
|
if (user) this.injectBadges(e.instance, BDFDB.ReactUtils.getValue(e.returnvalue, "props.children.props.children"), user, "chat");
|
2018-10-11 10:21:26 +02:00
|
|
|
}
|
2019-09-04 12:34:02 +02:00
|
|
|
|
2019-10-29 18:55:11 +01:00
|
|
|
processUserPopout (e) {
|
2019-10-30 14:03:32 +01:00
|
|
|
if (!BDFDB.DataUtils.get(this, "settings", "showInPopout")) return;
|
|
|
|
if (e.instance.props.user) {
|
|
|
|
let [children, index] = BDFDB.ReactUtils.findChildren(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);
|
2018-10-11 10:21:26 +02:00
|
|
|
}
|
|
|
|
}
|
2019-01-26 22:45:19 +01:00
|
|
|
|
2019-10-30 14:03:32 +01:00
|
|
|
injectBadges (instance, children, info, type, colored) {
|
|
|
|
if (!BDFDB.ArrayUtils.is(children) || !info || info.bot || this.stopping) return;
|
|
|
|
if (!BDFDB.ArrayUtils.is(this.requestedusers[info.id])) {
|
|
|
|
this.requestedusers[info.id] = [instance];
|
2019-09-11 12:14:43 +02:00
|
|
|
BDFDB.LibraryModules.APIUtils.get(BDFDB.DiscordConstants.Endpoints.USER_PROFILE(info.id)).then(result => {
|
2019-10-30 14:03:32 +01:00
|
|
|
let usercopy = Object.assign({}, result.body.user);
|
2019-05-21 15:45:43 +02:00
|
|
|
if (result.body.premium_since) usercopy.flags += this.nitroflag;
|
2019-05-20 14:53:31 +02:00
|
|
|
usercopy.premium_since = result.body.premium_since;
|
2019-06-02 14:36:54 +02:00
|
|
|
if (result.body.premium_guild_since) usercopy.flags += this.boostflag;
|
|
|
|
usercopy.premium_guild_since = result.body.premium_guild_since;
|
2018-12-27 10:16:30 +01:00
|
|
|
this.loadedusers[info.id] = usercopy;
|
2019-10-30 14:03:32 +01:00
|
|
|
for (let queredinstance of this.requestedusers[info.id]) BDFDB.ReactUtils.forceUpdate(queredinstance);
|
2018-12-27 10:16:30 +01:00
|
|
|
});
|
|
|
|
}
|
2019-10-30 14:03:32 +01:00
|
|
|
else if (!this.loadedusers[info.id]) this.requestedusers[info.id].push(instance);
|
|
|
|
else children.push(this.createBadges(info, type, colored));
|
2018-12-27 10:16:30 +01:00
|
|
|
}
|
2019-01-26 22:45:19 +01:00
|
|
|
|
2019-10-30 14:03:32 +01:00
|
|
|
createBadges (info, type, uncolored) {
|
2019-10-22 19:49:57 +02:00
|
|
|
let badges = BDFDB.DataUtils.get(this, "badges");
|
|
|
|
let indicators = BDFDB.DataUtils.get(this, "indicators");
|
|
|
|
let settings = BDFDB.DataUtils.get(this, "settings");
|
2019-10-30 14:03:32 +01:00
|
|
|
if (uncolored == undefined) uncolored = !settings.useColoredVersion;
|
|
|
|
let badgewrapper = BDFDB.ReactUtils.elementToReact(BDFDB.DOMUtils.create(`<span class="BE-badges BE-badges-${type} ${uncolored ? BDFDB.disCN.userprofiletopsectionplaying : BDFDB.disCN.userprofiletopsectionnormal}" style="all: unset !important;"></span>`));
|
|
|
|
badgewrapper.props.children = [];
|
|
|
|
for (let flag in badges) if ((this.loadedusers[info.id].flags | flag) == this.loadedusers[info.id].flags && badges[flag]) {
|
|
|
|
badgewrapper.props.children.push(this.createBadge(settings.showNitroDate ? this.getTimeString(info.id, flag) : null, type, flag, flag == this.boostflag ? BDFDB.LibraryModules.GuildBoostUtils.getUserLevel(this.loadedusers[info.id].premium_guild_since) : null));
|
2018-10-11 10:21:26 +02:00
|
|
|
}
|
2019-09-11 12:14:43 +02:00
|
|
|
let member = BDFDB.LibraryModules.MemberStore.getMember(BDFDB.LibraryModules.LastGuildStore.getGuildId(), info.id);
|
2019-06-02 14:36:54 +02:00
|
|
|
if (indicators.CURRENT_GUILD_BOOST && member && member.premiumSince) {
|
2019-10-30 14:03:32 +01:00
|
|
|
badgewrapper.props.children.push(this.createBadge(settings.showNitroDate ? this.getTimeString(info.id, "CURRENT_GUILD_BOOST") : null, type, "CURRENT_GUILD_BOOST"));
|
2019-05-31 10:31:01 +02:00
|
|
|
}
|
2019-10-30 14:03:32 +01:00
|
|
|
return badgewrapper.props.children.length ? badgewrapper : null;
|
|
|
|
}
|
|
|
|
|
|
|
|
createBadge (timestring, type, flag, rank) {
|
|
|
|
let data = this.defaults.badges[flag] || this.defaults.indicators[flag];
|
|
|
|
if (!data) return null;
|
|
|
|
return BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.TooltipContainer, {
|
|
|
|
className: BDFDB.DOMUtils.formatClassName(`BE-badge`, `BE-badge-${type}`, ["list", "chat"].includes(type) ? `BE-badge-mini` : null, data.id ? `BE-badge-${data.id}` : null, data.selector ? this.BadgeClasses[data.selector + (rank || "")] : null, data.size ? `BE-size-${data.size}` : null),
|
|
|
|
text: timestring || data.name,
|
|
|
|
tooltipConfig: {
|
|
|
|
style: "white-space: nowrap; max-width: unset;"
|
|
|
|
},
|
|
|
|
children: data.inner ? BDFDB.ReactUtils.elementToReact(BDFDB.DOMUtils.create(data.inner)) : null
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
getTimeString (id, flag) {
|
|
|
|
let member = BDFDB.LibraryModules.MemberStore.getMember(BDFDB.LibraryModules.LastGuildStore.getGuildId(), id);
|
|
|
|
if (flag == this.nitroflag) return BDFDB.LanguageUtils.LanguageStringsFormat("PREMIUM_BADGE_TOOLTIP", new Date(this.loadedusers[id].premium_since));
|
|
|
|
else if (flag == this.boostflag) return BDFDB.LanguageUtils.LanguageStringsFormat("PREMIUM_GUILD_SUBSCRIPTION_TOOLTIP", new Date(this.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 colorbadgewrapper = BDFDB.ReactUtils.elementToReact(BDFDB.DOMUtils.create(`<span class="BE-badges BE-badges-settings ${BDFDB.disCN.userprofiletopsectionnormal}" style="all: unset !important;"></span>`));
|
|
|
|
let uncolorbadgewrapper = BDFDB.ReactUtils.elementToReact(BDFDB.DOMUtils.create(`<span class="BE-badges BE-badges-settings ${BDFDB.disCN.userprofiletopsectionplaying}" style="all: unset !important;"></span>`));
|
|
|
|
if (Array.isArray(data.types)) {
|
|
|
|
for (let rank of data.types) {
|
|
|
|
let badge = this.createBadge(null, "settings", flag, rank);
|
|
|
|
colorbadgewrapper.props.children.push(badge);
|
|
|
|
uncolorbadgewrapper.props.children.push(badge);
|
2019-06-07 11:39:54 +02:00
|
|
|
}
|
|
|
|
}
|
2019-10-30 14:03:32 +01:00
|
|
|
else {
|
|
|
|
let badge = this.createBadge(null, "settings", flag);
|
|
|
|
colorbadgewrapper.props.children.push(badge);
|
|
|
|
uncolorbadgewrapper.props.children.push(badge);
|
|
|
|
}
|
|
|
|
return [colorbadgewrapper, uncolorbadgewrapper];
|
2018-10-11 10:21:26 +02:00
|
|
|
}
|
2018-12-27 12:56:10 +01:00
|
|
|
}
|