stuff
This commit is contained in:
parent
58c56cdf4f
commit
2ca9b3887b
|
@ -7318,7 +7318,7 @@ module.exports = (_ => {
|
|||
children: this.props.settings.map(setting => BDFDB.ReactUtils.createElement("div", {
|
||||
className: BDFDB.disCN.checkboxcontainer,
|
||||
children: BDFDB.ReactUtils.createElement(Internal.LibraryComponents.TooltipContainer, {
|
||||
text: setting,
|
||||
text: setting.toUpperCase(),
|
||||
children: BDFDB.ReactUtils.createElement(Internal.LibraryComponents.Checkbox, {
|
||||
disabled: props.disabled,
|
||||
cardId: props.key,
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
* @name ShowBadgesInChat
|
||||
* @author DevilBro
|
||||
* @authorId 278543574059057154
|
||||
* @version 1.8.9
|
||||
* @version 1.9.0
|
||||
* @description Displays Badges (Nitro, Hypesquad, etc...) in the Chat/MemberList/DMList
|
||||
* @invite Jx3TjNS
|
||||
* @donate https://www.paypal.me/MircoWittrien
|
||||
|
@ -17,8 +17,13 @@ module.exports = (_ => {
|
|||
"info": {
|
||||
"name": "ShowBadgesInChat",
|
||||
"author": "DevilBro",
|
||||
"version": "1.8.9",
|
||||
"version": "1.9.0",
|
||||
"description": "Displays Badges (Nitro, Hypesquad, etc...) in the Chat/MemberList/DMList"
|
||||
},
|
||||
"changeLog": {
|
||||
"improved": {
|
||||
"More Specific Settings": "You can now select more specifically where which Badges will be shown"
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -61,9 +66,17 @@ module.exports = (_ => {
|
|||
}
|
||||
} : (([Plugin, BDFDB]) => {
|
||||
var _this;
|
||||
var loadedUsers = {}, queuedInstances = {}, requestQueue = {queue: [], timeout: null, id: null}, cacheTimeout;
|
||||
var badgeConfigs = {}, loadedUsers = {}, queuedInstances = {}, requestQueue = {queue: [], timeout: null, id: null}, cacheTimeout;
|
||||
var specialFlag;
|
||||
|
||||
const places = ["chat", "memberList", "dmsList"];
|
||||
|
||||
const badges = {};
|
||||
|
||||
const indicators = {
|
||||
CURRENT_GUILD_BOOST: {value: true}
|
||||
};
|
||||
|
||||
return class ShowBadgesInChat extends Plugin {
|
||||
onLoad () {
|
||||
_this = this;
|
||||
|
@ -79,22 +92,10 @@ module.exports = (_ => {
|
|||
}
|
||||
};
|
||||
|
||||
this.defaults = {
|
||||
places: {
|
||||
chat: {value: true, description: "Chat"},
|
||||
memberList: {value: true, description: "Member List"},
|
||||
dmsList: {value: true, description: "DM List"}
|
||||
},
|
||||
badges: {},
|
||||
indicators: {
|
||||
CURRENT_GUILD_BOOST: {value: true}
|
||||
}
|
||||
};
|
||||
|
||||
for (let key of Object.keys(BDFDB.LibraryComponents.UserBadgeKeys).filter(n => isNaN(parseInt(n)))) {
|
||||
let basicKey = key.replace(/_LEVEL_\d+/g, "");
|
||||
if (!this.defaults.badges[basicKey]) this.defaults.badges[basicKey] = {value: true, keys: []};
|
||||
this.defaults.badges[basicKey].keys.push(BDFDB.LibraryComponents.UserBadgeKeys[key]);
|
||||
if (!badges[basicKey]) badges[basicKey] = {value: true, keys: []};
|
||||
badges[basicKey].keys.push(BDFDB.LibraryComponents.UserBadgeKeys[key]);
|
||||
}
|
||||
|
||||
this.css = `
|
||||
|
@ -152,6 +153,12 @@ module.exports = (_ => {
|
|||
${BDFDB.dotCN._showbadgesinchatbadgessettings} {
|
||||
color: var(--header-primary);
|
||||
}
|
||||
${BDFDB.dotCN._showbadgesinchatbadgessettings} * {
|
||||
cursor: default;
|
||||
}
|
||||
${BDFDB.dotCN._showbadgesinchatbadgessettings}:last-child {
|
||||
margin-right: 8px;
|
||||
}
|
||||
`;
|
||||
}
|
||||
|
||||
|
@ -159,6 +166,39 @@ module.exports = (_ => {
|
|||
queuedInstances = {}, loadedUsers = {};
|
||||
requestQueue = {queue: [], timeout: null, id: null};
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
// REMOVE 15.06.2022
|
||||
let oldPlaces = BDFDB.DataUtils.load(this, "places");
|
||||
let oldBadges = BDFDB.DataUtils.load(this, "badges");
|
||||
let oldIndicators = BDFDB.DataUtils.load(this, "indicators");
|
||||
if (Object.keys(oldBadges).length && Object.keys(oldIndicators).length && Object.keys(oldPlaces).length) {
|
||||
for (let key in oldBadges) {
|
||||
if (!badgeConfigs[key]) badgeConfigs[key] = {};
|
||||
for (let key2 in oldPlaces) badgeConfigs[key][key2] = oldBadges[key] && oldPlaces[key2];
|
||||
}
|
||||
for (let key in oldIndicators) {
|
||||
if (!badgeConfigs[key]) badgeConfigs[key] = {};
|
||||
for (let key2 in oldPlaces) badgeConfigs[key][key2] = oldIndicators[key] && oldPlaces[key2];
|
||||
}
|
||||
BDFDB.DataUtils.remove(this, "general");
|
||||
BDFDB.DataUtils.remove(this, "settings");
|
||||
BDFDB.DataUtils.remove(this, "places");
|
||||
BDFDB.DataUtils.remove(this, "badges");
|
||||
BDFDB.DataUtils.remove(this, "indicators");
|
||||
BDFDB.DataUtils.save(badgeConfigs, this, "badgeConfigs");
|
||||
}
|
||||
|
||||
let badgeCache = BDFDB.DataUtils.load(this, "badgeCache");
|
||||
if (badgeCache) {
|
||||
let now = (new Date()).getTime(), month = 1000*60*60*24*30;
|
||||
|
@ -209,35 +249,54 @@ module.exports = (_ => {
|
|||
collapseStates: collapseStates,
|
||||
children: _ => {
|
||||
let settingsItems = [];
|
||||
|
||||
settingsItems.push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsPanelList, {
|
||||
title: "Show Badges in:",
|
||||
children: Object.keys(this.defaults.places).map(key => BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsSaveItem, {
|
||||
type: "Switch",
|
||||
plugin: this,
|
||||
keys: ["places", key],
|
||||
label: this.defaults.places[key].description,
|
||||
value: this.settings.places[key]
|
||||
}))
|
||||
settingsItems.push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.FormComponents.FormTitle, {
|
||||
className: BDFDB.disCN.marginbottom4,
|
||||
tag: BDFDB.LibraryComponents.FormComponents.FormTitle.Tags.H3,
|
||||
children: "Show Badges in"
|
||||
}));
|
||||
|
||||
settingsItems.push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsPanelList, {
|
||||
title: "Display Badges:",
|
||||
children: Object.keys(this.defaults.badges).map(key => BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsSaveItem, {
|
||||
type: "Switch",
|
||||
plugin: this,
|
||||
keys: ["badges", key],
|
||||
label: key.split("_").map(n => BDFDB.LibraryModules.StringUtils.upperCaseFirstChar(n.toLowerCase())).join(" "),
|
||||
value: this.settings.badges[key],
|
||||
labelChildren: this.createSettingsBadges(key)
|
||||
})).concat(Object.keys(this.defaults.indicators).map(key => BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsSaveItem, {
|
||||
type: "Switch",
|
||||
plugin: this,
|
||||
keys: ["indicators", key],
|
||||
label: key.split("_").map(n => BDFDB.LibraryModules.StringUtils.upperCaseFirstChar(n.toLowerCase())).join(" "),
|
||||
value: this.settings.indicators[key],
|
||||
labelChildren: this.createSettingsBadges(key)
|
||||
})))
|
||||
settingsItems.push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsList, {
|
||||
settings: places,
|
||||
data: Object.keys(badges).concat(Object.keys(indicators)).map(key => badgeConfigs[key]),
|
||||
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;
|
||||
},
|
||||
children: cardData.key.split("_").map(n => BDFDB.LibraryModules.StringUtils.upperCaseFirstChar(n.toLowerCase())).join(" ")
|
||||
})
|
||||
}),
|
||||
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;
|
||||
}
|
||||
}));
|
||||
|
||||
settingsItems.push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsItem, {
|
||||
|
@ -246,7 +305,7 @@ module.exports = (_ => {
|
|||
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");
|
||||
this.forceUpdateAll();
|
||||
this.SettingsUpdated = true;
|
||||
}),
|
||||
children: BDFDB.LanguageUtils.LanguageStrings.RESET
|
||||
}));
|
||||
|
@ -269,7 +328,7 @@ module.exports = (_ => {
|
|||
}
|
||||
|
||||
processMessageUsername (e) {
|
||||
if (!e.instance.props.message || !this.settings.places.chat) return;
|
||||
if (!e.instance.props.message) return;
|
||||
let [children, index] = BDFDB.ReactUtils.findParent(e.returnvalue, {name: "Popout"});
|
||||
if (index == -1) return;
|
||||
const author = e.instance.props.userOverride || e.instance.props.message.author;
|
||||
|
@ -277,12 +336,12 @@ module.exports = (_ => {
|
|||
}
|
||||
|
||||
processMemberListItem (e) {
|
||||
if (!e.instance.props.user || !this.settings.places.memberList) return;
|
||||
this.injectBadges(BDFDB.ObjectUtils.get(e.returnvalue, "props.decorators.props.children"), e.instance.props.user, e.instance.props.channel.guild_id, "members");
|
||||
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");
|
||||
}
|
||||
|
||||
processPrivateChannel (e) {
|
||||
if (!e.instance.props.user || !this.settings.places.dmsList) return;
|
||||
if (!e.instance.props.user) return;
|
||||
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;
|
||||
|
@ -299,15 +358,16 @@ module.exports = (_ => {
|
|||
const wrapper = returnvalue.props.decorators ? returnvalue : BDFDB.ReactUtils.findChild(returnvalue, {props: ["decorators"]}) || returnvalue;
|
||||
if (!wrapper) return;
|
||||
wrapper.props.decorators = [wrapper.props.decorators].flat(10);
|
||||
this.injectBadges(wrapper.props.decorators, instance.props.user, null, "dms");
|
||||
this.injectBadges(wrapper.props.decorators, instance.props.user, null, "dmsList");
|
||||
}
|
||||
|
||||
processUserProfileBadgeList (e) {
|
||||
if (e.instance.props.custom) {
|
||||
let filter = e.instance.props.place != "settings";
|
||||
for (let i in e.returnvalue.props.children) if (e.returnvalue.props.children[i]) {
|
||||
let key = parseInt(e.returnvalue.props.children[i].key);
|
||||
let keyName = e.instance.props.filter && Object.keys(this.defaults.badges).find(n => this.defaults.badges[n].keys.includes(key));
|
||||
if (keyName && !this.settings.badges[keyName]) e.returnvalue.props.children[i] = null;
|
||||
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;
|
||||
else if (e.returnvalue.props.children[i].type.displayName == "TooltipContainer" || e.returnvalue.props.children[i].type.displayName == "Tooltip") {
|
||||
const childrenRender = e.returnvalue.props.children[i].props.children;
|
||||
e.returnvalue.props.children[i].props.children = (...args) => {
|
||||
|
@ -318,7 +378,7 @@ module.exports = (_ => {
|
|||
e.returnvalue.props.children[i] = BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.TooltipContainer, e.returnvalue.props.children[i].props);
|
||||
}
|
||||
}
|
||||
if ((this.settings.indicators.CURRENT_GUILD_BOOST || !e.instance.props.filter) && e.instance.props.premiumCurrentGuildSince) e.returnvalue.props.children.push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.TooltipContainer, {
|
||||
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, {
|
||||
text: BDFDB.LanguageUtils.LanguageStringsFormat("PREMIUM_GUILD_SUBSCRIPTION_TOOLTIP", e.instance.props.premiumCurrentGuildSince),
|
||||
children: BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.Clickable, {
|
||||
className: BDFDB.disCN.userbadgeouter,
|
||||
|
@ -335,7 +395,7 @@ module.exports = (_ => {
|
|||
}
|
||||
}
|
||||
|
||||
injectBadges (children, user, guildId, type) {
|
||||
injectBadges (children, user, guildId, place) {
|
||||
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)) {
|
||||
queuedInstances[user.id] = [].concat(queuedInstances[user.id]).filter(n => n);
|
||||
|
@ -348,7 +408,7 @@ module.exports = (_ => {
|
|||
if (queuedInstances[user.id].indexOf(this) == -1) queuedInstances[user.id].push(this);
|
||||
return null;
|
||||
}
|
||||
else return _this.createBadges(user, guildId, type);
|
||||
else return _this.createBadges(user, guildId, place);
|
||||
}
|
||||
}, {}, true));
|
||||
}
|
||||
|
@ -368,7 +428,7 @@ module.exports = (_ => {
|
|||
}
|
||||
}
|
||||
|
||||
createBadges (user, guildId, type) {
|
||||
createBadges (user, guildId, place) {
|
||||
let fakeGuildBoostDate;
|
||||
if (typeof user.id == "string" && user.id.startsWith(specialFlag + "GB")) {
|
||||
let level = parseInt(user.id.split("_").pop());
|
||||
|
@ -379,11 +439,11 @@ module.exports = (_ => {
|
|||
}
|
||||
let member = guildId && BDFDB.LibraryModules.MemberStore.getMember(guildId, user.id);
|
||||
return BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.UserBadges.default, {
|
||||
className: BDFDB.DOMUtils.formatClassName(BDFDB.disCN._showbadgesinchatbadges, BDFDB.disCN[`_showbadgesinchatbadges${type}`]),
|
||||
className: BDFDB.DOMUtils.formatClassName(BDFDB.disCN._showbadgesinchatbadges, BDFDB.disCN[`_showbadgesinchatbadges${place.toLowerCase()}`]),
|
||||
user: user,
|
||||
size: BDFDB.LibraryComponents.UserBadges.BadgeSizes.SIZE_18,
|
||||
custom: true,
|
||||
filter: type != "settings",
|
||||
place: place,
|
||||
premiumSince: loadedUsers[user.id] && loadedUsers[user.id].premium_since ? new Date(loadedUsers[user.id].premium_since) : (user.id == (specialFlag + "NITRO") ? new Date() : null),
|
||||
premiumGuildSince: fakeGuildBoostDate || (loadedUsers[user.id] && loadedUsers[user.id].premium_guild_since ? new Date(loadedUsers[user.id].premium_guild_since) : null),
|
||||
premiumCurrentGuildSince: member && member.premiumSince && new Date(member.premiumSince) || user.id == (specialFlag + "CGB") && new Date()
|
||||
|
@ -392,12 +452,12 @@ module.exports = (_ => {
|
|||
|
||||
createSettingsBadges (flag) {
|
||||
let wrappers = [];
|
||||
if (this.defaults.indicators[flag]) {
|
||||
if (indicators[flag]) {
|
||||
let id = flag == "CURRENT_GUILD_BOOST" ? (specialFlag + "CGB") : null;
|
||||
let user = new BDFDB.DiscordObjects.User({flags: 0, id: id});
|
||||
wrappers.push(this.createBadges(user, null, "settings"));
|
||||
}
|
||||
else for (let key of this.defaults.badges[flag].keys) {
|
||||
else for (let key of badges[flag].keys) {
|
||||
let userFlag = flag == "PREMIUM" || flag == "GUILD_BOOSTER" ? 0 : BDFDB.DiscordConstants.UserFlags[flag];
|
||||
let keyName = BDFDB.LibraryComponents.UserBadgeKeys[key];
|
||||
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)];
|
||||
|
|
Loading…
Reference in New Issue