Update OwnerTag.plugin.js

This commit is contained in:
Mirco Wittrien 2021-03-08 16:02:53 +01:00
parent d5a9fae7a5
commit 4f06dcc109
1 changed files with 119 additions and 98 deletions

View File

@ -2,7 +2,7 @@
* @name OwnerTag * @name OwnerTag
* @author DevilBro * @author DevilBro
* @authorId 278543574059057154 * @authorId 278543574059057154
* @version 1.3.7 * @version 1.3.8
* @description Adds a Tag/Crown to Server Owners (or Admins/Management) * @description Adds a Tag/Crown to Server Owners (or Admins/Management)
* @invite Jx3TjNS * @invite Jx3TjNS
* @donate https://www.paypal.me/MircoWittrien * @donate https://www.paypal.me/MircoWittrien
@ -17,12 +17,12 @@ module.exports = (_ => {
"info": { "info": {
"name": "OwnerTag", "name": "OwnerTag",
"author": "DevilBro", "author": "DevilBro",
"version": "1.3.7", "version": "1.3.8",
"description": "Adds a Tag/Crown to Server Owners (or Admins/Management)" "description": "Adds a Tag/Crown to Server Owners (or Admins/Management)"
}, },
"changeLog": { "changeLog": {
"added": { "added": {
"Voice Channel List": "Added Option to add Role Tag in the Voice Channel List for Users" "New Settings": "Added new tag options for Management (Users/Messages) and restructured the Settings so you might need to reconfigure some stuff"
} }
} }
}; };
@ -72,8 +72,6 @@ module.exports = (_ => {
OWNER: 3 OWNER: 3
}; };
var settings = {}, inputs = {};
return class OwnerTag extends Plugin { return class OwnerTag extends Plugin {
onLoad () { onLoad () {
this.patchedModules = { this.patchedModules = {
@ -87,24 +85,32 @@ module.exports = (_ => {
}; };
this.defaults = { this.defaults = {
settings: { general: {
addInChatWindow: {value: true, inner: true, description: "Messages"}, useCrown: {value: true, description: "Use the Crown Icon instead of the Bot Tag Style"},
addInMemberList: {value: true, inner: true, description: "Member List"}, useRoleColor: {value: true, description: "Use the Role Color instead of the default Blurple"},
addInVoiceList: {value: true, inner: true, description: "Voice User List"}, useBlackFont: {value: false, description: "Use black Font instead of darkening the Role Color on bright Colors"},
addInUserPopout: {value: true, inner: true, description: "User Popouts"}, ignoreBots: {value: false, description: "Don't add the Owner/Admin/Management Tag for Bots"}
addInUserProfile: {value: true, inner: true, description: "User Profile Modal"}, },
useRoleColor: {value: true, inner: false, description: "Use the Rolecolor instead of the default blue"}, tagTypes: {
useBlackFont: {value: false, inner: false, description: "Instead of darkening the Rolecolor on bright colors use black font"}, owners: {value: true, description: "Owner Tag (Server/Group Owner)"},
useCrown: {value: false, inner: false, description: "Use the Crown Icon instead of the Bot Tag Style"}, admins: {value: true, description: "Admin Tag (Admin Permissions)"},
hideNativeCrown: {value: true, inner: false, description: "Hide the native Crown Icon (not the Plugin one)"}, managementG: {value: true, description: "Management Tag (Server Management)"},
addForAdmins: {value: false, inner: false, description: "Add an Admin Tag for users with admin permissions"}, managementC: {value: true, description: "Management Tag (Channel Management)"},
addForManagement: {value: false, inner: false, description: "Add a Management Tag for users with management permissions"}, managementR: {value: true, description: "Management Tag (Role Management)"},
ignoreBotAdmins: {value: false, inner: false, description: "Do not add the Admin/Management tag for bots"} managementU: {value: true, description: "Management Tag (User Management 'Kick/Ban')"},
managementM: {value: true, description: "Management Tag (Message Management)"}
},
tagPlaces: {
chat: {value: true, description: "Messages"},
memberList: {value: true, description: "Member List"},
voiceList: {value: true, description: "Voice User List"},
userPopout: {value: true, description: "User Popouts"},
userProfile: {value: true, description: "User Profile Modal"},
}, },
inputs: { inputs: {
ownTagName: {value: "Owner", description: "Tag Text for Owners"}, ownOwnerTagName: {value: "Owner", description: "Owner Tags"},
ownAdminTagName: {value: "Admin", description: "Tag Text for Admins"}, ownAdminTagName: {value: "Admin", description: "Admin Tags"},
ownManagementTagName: {value: "Management", description: "Tag Text for Management"} ownManagementTagName: {value: "Management", description: "Management Tags"}
} }
}; };
@ -141,57 +147,67 @@ module.exports = (_ => {
} }
getSettingsPanel (collapseStates = {}) { getSettingsPanel (collapseStates = {}) {
let settingsPanel, settingsItems = []; let settingsPanel;
return settingsPanel = BDFDB.PluginUtils.createSettingsPanel(this, {
collapseStates: collapseStates,
children: _ => {
let settingsItems = [];
settingsItems.push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.CollapseContainer, { settingsItems.push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.CollapseContainer, {
title: "Settings", title: "Settings",
collapseStates: collapseStates, collapseStates: collapseStates,
children: Object.keys(settings).map(key => !this.defaults.settings[key].inner && BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsSaveItem, { children: Object.keys(this.settings.general).map(key => BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsSaveItem, {
type: "Switch", type: "Switch",
plugin: this, plugin: this,
key: key, key: key,
disabled: key == "hideNativeCrown" && settings.useCrown, keys: ["general", key],
keys: ["settings", key], label: this.defaults.general[key].description,
label: this.defaults.settings[key].description, value: this.settings.general[key]
value: settings[key], }))
onChange: key == "useCrown" ? (value, instance) => { }));
let hideNativeCrownInstance = BDFDB.ReactUtils.findOwner(BDFDB.ObjectUtils.get(instance, `${BDFDB.ReactUtils.instanceKey}.return`), {key: "hideNativeCrown"}); settingsItems.push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.CollapseContainer, {
if (hideNativeCrownInstance) { title: "Tag Settings",
hideNativeCrownInstance.props.disabled = value; collapseStates: collapseStates,
BDFDB.ReactUtils.forceUpdate(hideNativeCrownInstance); children: [
} BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsPanelList, {
} : null title: "Add Tags for:",
})) dividerBottom: true,
})); children: Object.keys(this.settings.tagTypes).map(key => BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsSaveItem, {
settingsItems.push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.CollapseContainer, { type: "Switch",
title: "Tag Settings", plugin: this,
collapseStates: collapseStates, keys: ["tagTypes", key],
children: [BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.FormComponents.FormTitle, { label: this.defaults.tagTypes[key].description,
className: BDFDB.disCN.marginbottom4, value: this.settings.tagTypes[key]
tag: BDFDB.LibraryComponents.FormComponents.FormTitle.Tags.H3, }))
children: "Add Tags in: " }),
})].concat(Object.keys(settings).map(key => this.defaults.settings[key].inner && BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsSaveItem, { BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsPanelList, {
type: "Switch", title: "Add Tags in:",
plugin: this, children: Object.keys(this.settings.tagPlaces).map(key => BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsSaveItem, {
keys: ["settings", key], type: "Switch",
label: this.defaults.settings[key].description, plugin: this,
value: settings[key] keys: ["tagPlaces", key],
}))) label: this.defaults.tagPlaces[key].description,
})); value: this.settings.tagPlaces[key]
settingsItems.push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.CollapseContainer, { }))
title: "Tag Text Settings", })
collapseStates: collapseStates, ]
children: Object.keys(inputs).map(key => BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsSaveItem, { }));
type: "TextInput", settingsItems.push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.CollapseContainer, {
plugin: this, title: "Tag Text Settings",
keys: ["inputs", key], collapseStates: collapseStates,
label: this.defaults.inputs[key].description, children: Object.keys(this.defaults.inputs).map(key => BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsSaveItem, {
basis: "50%", type: "TextInput",
value: inputs[key] plugin: this,
})) keys: ["inputs", key],
})); label: this.defaults.inputs[key].description,
basis: "50%",
return settingsPanel = BDFDB.PluginUtils.createSettingsPanel(this, settingsItems); value: this.defaults.inputs[key]
}))
}));
return settingsItems;
}
});
} }
onSettingsClosed () { onSettingsClosed () {
@ -201,17 +217,14 @@ module.exports = (_ => {
} }
} }
forceUpdateAll () { forceUpdateAll () {
settings = BDFDB.DataUtils.get(this, "settings");
inputs = BDFDB.DataUtils.get(this, "inputs");
BDFDB.PatchUtils.forceAllUpdates(this); BDFDB.PatchUtils.forceAllUpdates(this);
BDFDB.MessageUtils.rerenderAll(); BDFDB.MessageUtils.rerenderAll();
} }
processMemberListItem (e) { processMemberListItem (e) {
let userType = this.getUserType(e.instance.props.user, e.instance.props.channel && e.instance.props.channel.id); let userType = this.getUserType(e.instance.props.user, e.instance.props.channel && e.instance.props.channel.id);
if (userType && settings.addInMemberList) { if (userType && this.settings.tagPlaces.memberList) {
this.injectOwnerTag(BDFDB.ObjectUtils.get(e.returnvalue, "props.decorators.props.children"), e.instance.props.user, userType, 1, { this.injectOwnerTag(BDFDB.ObjectUtils.get(e.returnvalue, "props.decorators.props.children"), e.instance.props.user, userType, 1, {
channelId: e.instance.props.channel && e.instance.props.channel.id, channelId: e.instance.props.channel && e.instance.props.channel.id,
tagClass: BDFDB.disCN.bottagmember tagClass: BDFDB.disCN.bottagmember
@ -220,7 +233,7 @@ module.exports = (_ => {
} }
processMessageUsername (e) { processMessageUsername (e) {
if (e.instance.props.message && settings.addInChatWindow) { if (e.instance.props.message && this.settings.tagPlaces.chat) {
let userType = this.getUserType(e.instance.props.message.author, e.instance.props.message.channel_id); let userType = this.getUserType(e.instance.props.message.author, e.instance.props.message.channel_id);
if (userType) this.injectOwnerTag(e.returnvalue.props.children, e.instance.props.message.author, userType, e.instance.props.compact ? 0 : 2, { if (userType) this.injectOwnerTag(e.returnvalue.props.children, e.instance.props.message.author, userType, e.instance.props.compact ? 0 : 2, {
channelId: e.instance.props.message.channel_id, channelId: e.instance.props.message.channel_id,
@ -231,7 +244,7 @@ module.exports = (_ => {
} }
processVoiceUser (e) { processVoiceUser (e) {
if (e.instance.props.user && settings.addInVoiceList) { if (e.instance.props.user && this.settings.tagPlaces.voiceList) {
let userType = this.getUserType(e.instance.props.user, e.instance.props.channel && e.instance.props.channel.id); let userType = this.getUserType(e.instance.props.user, e.instance.props.channel && e.instance.props.channel.id);
if (userType) { if (userType) {
let content = BDFDB.ReactUtils.findChild(e.returnvalue, {props: [["className", BDFDB.disCN.voicecontent]]}); let content = BDFDB.ReactUtils.findChild(e.returnvalue, {props: [["className", BDFDB.disCN.voicecontent]]});
@ -249,11 +262,11 @@ module.exports = (_ => {
let inject = false, tagClass = ""; let inject = false, tagClass = "";
switch (e.instance.props.className) { switch (e.instance.props.className) {
case BDFDB.disCN.userpopoutheadertagnonickname: case BDFDB.disCN.userpopoutheadertagnonickname:
inject = settings.addInUserPopout; inject = this.settings.tagPlaces.userPopout;
tagClass = BDFDB.disCN.bottagnametag; tagClass = BDFDB.disCN.bottagnametag;
break; break;
case BDFDB.disCN.userprofilenametag: case BDFDB.disCN.userprofilenametag:
inject = settings.addInUserProfile; inject = this.settings.tagPlaces.userProfile;
tagClass = BDFDB.disCNS.userprofilebottag + BDFDB.disCN.bottagnametag; tagClass = BDFDB.disCNS.userprofilebottag + BDFDB.disCN.bottagnametag;
break; break;
} }
@ -267,7 +280,7 @@ module.exports = (_ => {
} }
processUserPopout (e) { processUserPopout (e) {
if (e.instance.props.user && settings.addInUserPopout) { if (e.instance.props.user && this.settings.tagPlaces.userPopout) {
let userType = this.getUserType(e.instance.props.user, e.instance.props.channel && e.instance.props.channel.id); let userType = this.getUserType(e.instance.props.user, e.instance.props.channel && e.instance.props.channel.id);
if (userType) { if (userType) {
let [children, index] = BDFDB.ReactUtils.findParent(e.returnvalue, {props: [["className", BDFDB.disCN.userpopoutheadertagwithnickname]]}); let [children, index] = BDFDB.ReactUtils.findParent(e.returnvalue, {props: [["className", BDFDB.disCN.userpopoutheadertagwithnickname]]});
@ -281,14 +294,12 @@ module.exports = (_ => {
injectOwnerTag (children, user, userType, insertIndex, config = {}) { injectOwnerTag (children, user, userType, insertIndex, config = {}) {
if (!BDFDB.ArrayUtils.is(children) || !user) return; if (!BDFDB.ArrayUtils.is(children) || !user) return;
if (settings.useCrown || settings.hideNativeCrown) { let [_, index] = BDFDB.ReactUtils.findParent(children, {props: [["text", [BDFDB.LanguageUtils.LanguageStrings.GROUP_OWNER, BDFDB.LanguageUtils.LanguageStrings.GUILD_OWNER]]]});
let [_, index] = BDFDB.ReactUtils.findParent(children, {props: [["text",[BDFDB.LanguageUtils.LanguageStrings.GROUP_OWNER, BDFDB.LanguageUtils.LanguageStrings.GUILD_OWNER]]]}); if (index > -1) children[index] = null;
if (index > -1) children[index] = null;
}
let channel = BDFDB.LibraryModules.ChannelStore.getChannel(config.channelId || BDFDB.LibraryModules.LastChannelStore.getChannelId()); let channel = BDFDB.LibraryModules.ChannelStore.getChannel(config.channelId || BDFDB.LibraryModules.LastChannelStore.getChannelId());
let member = channel && settings.useRoleColor ? (BDFDB.LibraryModules.MemberStore.getMember(channel.guild_id, user.id) || {}) : {}; let member = channel && this.settings.general.useRoleColor ? (BDFDB.LibraryModules.MemberStore.getMember(channel.guild_id, user.id) || {}) : {};
let tag = null; let tag = null;
if (settings.useCrown) { if (this.settings.general.useCrown) {
let label, className; let label, className;
switch (userType) { switch (userType) {
case userTypes.OWNER: case userTypes.OWNER:
@ -300,7 +311,7 @@ module.exports = (_ => {
className = BDFDB.disCN._ownertagadminicon; className = BDFDB.disCN._ownertagadminicon;
break; break;
case userTypes.MANAGEMENT: case userTypes.MANAGEMENT:
label = `${this.labels.management} (${[BDFDB.UserUtils.can("MANAGE_GUILD", user.id) && BDFDB.LanguageUtils.LibraryStrings.server, BDFDB.UserUtils.can("MANAGE_CHANNELS", user.id) && BDFDB.LanguageUtils.LanguageStrings.CHANNELS, BDFDB.UserUtils.can("MANAGE_ROLES", user.id) && BDFDB.LanguageUtils.LanguageStrings.ROLES].filter(n => n).join(", ")})`; label = `${this.labels.management} (${this.getManagementLabel(user)})`;
className = BDFDB.disCN._ownertagmanagementicon; className = BDFDB.disCN._ownertagmanagementicon;
break; break;
} }
@ -317,28 +328,28 @@ module.exports = (_ => {
let input, label; let input, label;
switch (userType) { switch (userType) {
case userTypes.OWNER: case userTypes.OWNER:
input = "ownTagName"; input = "ownOwnerTagName";
break; break;
case userTypes.ADMIN: case userTypes.ADMIN:
input = "ownAdminTagName"; input = "ownAdminTagName";
break; break;
case userTypes.MANAGEMENT: case userTypes.MANAGEMENT:
input = "ownManagementTagName"; input = "ownManagementTagName";
label = [BDFDB.UserUtils.can("MANAGE_GUILD", user.id) && BDFDB.LanguageUtils.LibraryStrings.server, BDFDB.UserUtils.can("MANAGE_CHANNELS", user.id) && BDFDB.LanguageUtils.LanguageStrings.CHANNELS, BDFDB.UserUtils.can("MANAGE_ROLES", user.id) && BDFDB.LanguageUtils.LanguageStrings.ROLES].filter(n => n).join(", "); label = this.getManagementLabel(user);
break; break;
} }
let tagColor = BDFDB.ColorUtils.convert(member.colorString, "RGBA"); let tagColor = BDFDB.ColorUtils.convert(member.colorString, "RGBA");
let isBright = BDFDB.ColorUtils.isBright(tagColor); let isBright = BDFDB.ColorUtils.isBright(tagColor);
tagColor = isBright ? (settings.useBlackFont ? tagColor : BDFDB.ColorUtils.change(tagColor, -0.3)) : tagColor; tagColor = isBright ? (this.settings.general.useBlackFont ? tagColor : BDFDB.ColorUtils.change(tagColor, -0.3)) : tagColor;
tag = BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.BotTag, { tag = BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.BotTag, {
className: config.tagClass, className: config.tagClass,
useRemSizes: config.useRem, useRemSizes: config.useRem,
invertColor: config.inverted, invertColor: config.inverted,
style: { style: {
backgroundColor: config.inverted ? (isBright && settings.useBlackFont ? "black" : null) : tagColor, backgroundColor: config.inverted ? (isBright && this.settings.general.useBlackFont ? "black" : null) : tagColor,
color: !config.inverted ? (isBright && settings.useBlackFont ? "black" : null) : tagColor color: !config.inverted ? (isBright && this.settings.general.useBlackFont ? "black" : null) : tagColor
}, },
tag: inputs[input] tag: this.settings.inputs[input]
}); });
if (label) tag = BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.TooltipContainer, { if (label) tag = BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.TooltipContainer, {
text: label, text: label,
@ -348,15 +359,25 @@ module.exports = (_ => {
children.splice(insertIndex, 0, tag); children.splice(insertIndex, 0, tag);
} }
getManagementLabel (user) {
return [
this.settings.tagTypes.managementG && BDFDB.UserUtils.can("MANAGE_GUILD", user.id) && BDFDB.LanguageUtils.LibraryStrings.server,
this.settings.tagTypes.managementC && BDFDB.UserUtils.can("MANAGE_CHANNELS", user.id) && BDFDB.LanguageUtils.LanguageStrings.CHANNELS,
this.settings.tagTypes.managementR && BDFDB.UserUtils.can("MANAGE_ROLES", user.id) && BDFDB.LanguageUtils.LanguageStrings.ROLES,
this.settings.tagTypes.managementU && (BDFDB.UserUtils.can("BAN_MEMBERS", user.id) || BDFDB.UserUtils.can("KICK_MEMBERS", user.id)) && BDFDB.LanguageUtils.LanguageStrings.MEMBERS,
this.settings.tagTypes.managementM && BDFDB.UserUtils.can("MANAGE_MESSAGES", user.id) && BDFDB.LanguageUtils.LanguageStrings.MESSAGES
].filter(n => n).join(", ");
}
getUserType (user, channelId) { getUserType (user, channelId) {
if (!user) return userTypes.NONE; if (!user || this.settings.general.ignoreBots && user.bot) return userTypes.NONE;
let channel = BDFDB.LibraryModules.ChannelStore.getChannel(channelId || BDFDB.LibraryModules.LastChannelStore.getChannelId()); let channel = BDFDB.LibraryModules.ChannelStore.getChannel(channelId || BDFDB.LibraryModules.LastChannelStore.getChannelId());
if (!channel) return userTypes.NONE; if (!channel) return userTypes.NONE;
let guild = BDFDB.LibraryModules.GuildStore.getGuild(channel.guild_id); let guild = BDFDB.LibraryModules.GuildStore.getGuild(channel.guild_id);
let isOwner = channel.ownerId == user.id || guild && guild.ownerId == user.id; let isOwner = channel.ownerId == user.id || guild && guild.ownerId == user.id;
if (isOwner) return userTypes.OWNER; if (this.settings.tagTypes.owners && isOwner) return userTypes.OWNER;
else if (settings.addForAdmins && BDFDB.UserUtils.can("ADMINISTRATOR", user.id) && !(settings.ignoreBotAdmins && user.bot)) return userTypes.ADMIN; else if (this.settings.tagTypes.admins && BDFDB.UserUtils.can("ADMINISTRATOR", user.id)) return userTypes.ADMIN;
else if (settings.addForManagement && (BDFDB.UserUtils.can("MANAGE_GUILD", user.id) || BDFDB.UserUtils.can("MANAGE_CHANNELS", user.id) || BDFDB.UserUtils.can("MANAGE_ROLES", user.id)) && !(settings.ignoreBotAdmins && user.bot)) return userTypes.MANAGEMENT; else if (this.settings.tagTypes.managementG && BDFDB.UserUtils.can("MANAGE_GUILD", user.id) || this.settings.tagTypes.managementC && BDFDB.UserUtils.can("MANAGE_CHANNELS", user.id) || this.settings.tagTypes.managementR && BDFDB.UserUtils.can("MANAGE_ROLES", user.id) || this.settings.tagTypes.managementU && (BDFDB.UserUtils.can("BAN_MEMBERS", user.id) || BDFDB.UserUtils.can("KICK_MEMBERS", user.id)) || this.settings.tagTypes.managementM && BDFDB.UserUtils.can("MANAGE_MESSAGES", user.id)) return userTypes.MANAGEMENT;
return userTypes.NONE; return userTypes.NONE;
} }