Update EditRoles.plugin.js
This commit is contained in:
parent
9911cbddc9
commit
ab7b87eb03
|
@ -2,7 +2,7 @@
|
|||
* @name EditRoles
|
||||
* @author DevilBro
|
||||
* @authorId 278543574059057154
|
||||
* @version 1.1.7
|
||||
* @version 1.1.8
|
||||
* @description Allows you to locally edit Roles
|
||||
* @invite Jx3TjNS
|
||||
* @donate https://www.paypal.me/MircoWittrien
|
||||
|
@ -61,7 +61,7 @@ module.exports = (_ => {
|
|||
return template.content.firstElementChild;
|
||||
}
|
||||
} : (([Plugin, BDFDB]) => {
|
||||
var changedRoles = {}, cachedRoles = {};
|
||||
var changedRoles = {};
|
||||
|
||||
return class EditRoles extends Plugin {
|
||||
onLoad () {
|
||||
|
@ -70,8 +70,7 @@ module.exports = (_ => {
|
|||
"AutocompleteRoleResult",
|
||||
"ChannelMembers",
|
||||
"MemberListItem",
|
||||
"MessageContent",
|
||||
"UserPopoutBody"
|
||||
"MessageContent"
|
||||
],
|
||||
after: [
|
||||
"RichRoleMention"
|
||||
|
@ -96,8 +95,9 @@ module.exports = (_ => {
|
|||
if (guild) {
|
||||
let colorRole, iconRole;
|
||||
for (let id of e.returnValue.roles) {
|
||||
if (guild.roles[id] && (guild.roles[id].colorString || changedRoles[id] && changedRoles[id].color) && (!colorRole || colorRole.position < guild.roles[id].position)) colorRole = guild.roles[id];
|
||||
if (guild.roles[id] && (guild.roles[id].icon || changedRoles[id] && changedRoles[id].icon) && (!iconRole || iconRole.position < guild.roles[id].position)) iconRole = guild.roles[id];
|
||||
let roles = guild.roles || BDFDB.LibraryStores.GuildStore.getRoles(guild.id);
|
||||
if (roles && [id] && (roles[id].colorString || changedRoles[id] && changedRoles[id].color) && (!colorRole || colorRole.position < roles[id].position)) colorRole = roles[id];
|
||||
if (roles && roles[id] && (roles[id].icon || changedRoles[id] && changedRoles[id].icon) && (!iconRole || iconRole.position < roles[id].position)) iconRole = roles[id];
|
||||
}
|
||||
let color = colorRole && changedRoles[colorRole.id] && changedRoles[colorRole.id].color;
|
||||
if (color) e.returnValue = Object.assign({}, e.returnValue, {colorString: BDFDB.ColorUtils.convert(color, "HEX")});
|
||||
|
@ -105,6 +105,23 @@ module.exports = (_ => {
|
|||
}
|
||||
}
|
||||
}});
|
||||
BDFDB.PatchUtils.patch(this, BDFDB.LibraryStores.GuildStore, "getRoles", {after: e => {
|
||||
if (e.returnValue) {
|
||||
let roles = Object.assign({}, e.returnValue);
|
||||
for (let id in roles) {
|
||||
let data = changedRoles[id];
|
||||
if (data) {
|
||||
roles[id] = Object.assign({}, roles[id], {
|
||||
name: data.name || roles[id].name,
|
||||
icon: data.icon || roles[id].icon,
|
||||
color: data.color ? BDFDB.ColorUtils.convert(data.color, "INT") : roles[id].color,
|
||||
colorString: data.color ? BDFDB.ColorUtils.convert(data.color, "HEX") : roles[id].colorString
|
||||
});
|
||||
}
|
||||
}
|
||||
e.returnValue = roles;
|
||||
}
|
||||
}});
|
||||
BDFDB.PatchUtils.patch(this, BDFDB.LibraryModules.RoleIconUtils, "getRoleIconData", {after: e => {
|
||||
if (e.returnValue && e.methodArguments[0].id && changedRoles[e.methodArguments[0].id]) {
|
||||
if (changedRoles[e.methodArguments[0].id].icon) return {customIconSrc: changedRoles[e.methodArguments[0].id].icon};
|
||||
|
@ -112,7 +129,9 @@ module.exports = (_ => {
|
|||
}
|
||||
}});
|
||||
BDFDB.PatchUtils.patch(this, BDFDB.LibraryModules.RoleIconUtils, "canGuildUseRoleIcons", {after: e => {
|
||||
if (e.returnValue === false && Object.keys(e.methodArguments[0].roles).some(roleId => changedRoles[roleId] && changedRoles[roleId].icon)) return true;
|
||||
if (e.returnValue !== false) return e.returnValue;
|
||||
let roles = e.methodArguments[0].roles || BDFDB.LibraryStores.GuildStore.getRoles(e.methodArguments[0].id);
|
||||
if (Object.keys(roles).some(roleId => changedRoles[roleId] && changedRoles[roleId].icon)) return true;
|
||||
}});
|
||||
|
||||
this.forceUpdateAll();
|
||||
|
@ -177,10 +196,6 @@ module.exports = (_ => {
|
|||
}
|
||||
}
|
||||
|
||||
onGuildContextMenu (e) {
|
||||
if (e.instance.props.guild) e.instance.props.guild = this.changeRolesInGuild(e.instance.props.guild);
|
||||
}
|
||||
|
||||
onDeveloperContextMenu (e) {
|
||||
if (e.instance.props.label != BDFDB.LanguageUtils.LanguageStrings.COPY_ID_ROLE) return;
|
||||
let guild = this.getGuildFromRoleId(e.instance.props.id);
|
||||
|
@ -194,9 +209,7 @@ module.exports = (_ => {
|
|||
BDFDB.ContextMenuUtils.createItem(BDFDB.LibraryComponents.MenuItems.MenuItem, {
|
||||
label: this.labels.submenu_rolesettings,
|
||||
id: BDFDB.ContextMenuUtils.createItemId(this.name, "settings-change"),
|
||||
action: _ => {
|
||||
this.openRoleSettingsModal(guild.roles[e.instance.props.id]);
|
||||
}
|
||||
action: _ => this.openRoleSettingsModal((guild.roles || BDFDB.LibraryStores.GuildStore.getRoles(guild.id) || [])[e.instance.props.id])
|
||||
}),
|
||||
BDFDB.ContextMenuUtils.createItem(BDFDB.LibraryComponents.MenuItems.MenuItem, {
|
||||
label: this.labels.submenu_resetsettings,
|
||||
|
@ -261,44 +274,13 @@ module.exports = (_ => {
|
|||
if (member) e.instance.props.colorString = member.colorString;
|
||||
}
|
||||
|
||||
processUserPopoutBody (e) {
|
||||
if (e.instance.props.guild) e.instance.props.guild = this.changeRolesInGuild(e.instance.props.guild);
|
||||
}
|
||||
|
||||
getGuildFromRoleId (roleId) {
|
||||
return BDFDB.LibraryStores.SortedGuildStore.getFlattenedGuildIds().map(BDFDB.LibraryStores.GuildStore.getGuild).find(g => g.roles[roleId]);
|
||||
}
|
||||
|
||||
changeRolesInGuild (guild, useNative) {
|
||||
let changed = false, roles = Object.assign({}, guild.roles);
|
||||
for (let id in guild.roles) {
|
||||
let data = changedRoles[id];
|
||||
if (data) {
|
||||
changed = true;
|
||||
roles[id] = Object.assign({}, roles[id], {
|
||||
name: data.name || roles[id].name,
|
||||
icon: data.icon || roles[id].icon,
|
||||
color: data.color ? BDFDB.ColorUtils.convert(data.color, "INT") : roles[id].color,
|
||||
colorString: data.color ? BDFDB.ColorUtils.convert(data.color, "HEX") : roles[id].colorString
|
||||
});
|
||||
}
|
||||
}
|
||||
if (useNative && changed && !cachedRoles[guild.id]) cachedRoles[guild.id] = guild.roles;
|
||||
if (useNative) guild.roles = roles;
|
||||
return !changed || useNative ? guild : (new BDFDB.DiscordObjects.Guild(Object.assign({}, guild, {roles})));
|
||||
}
|
||||
|
||||
resetRoles (id) {
|
||||
if (id) {
|
||||
let guild = this.getGuildFromRoleId(id);
|
||||
if (guild && cachedRoles[guild.id]) guild.roles = Object.assign({}, guild.roles, {[id]: cachedRoles[guild.id][id]});
|
||||
BDFDB.DataUtils.remove(this, "roles", id);
|
||||
}
|
||||
else {
|
||||
for (let guild of BDFDB.LibraryStores.SortedGuildStore.getFlattenedGuildIds().map(BDFDB.LibraryStores.GuildStore.getGuild)) if (cachedRoles[guild.id]) guild.roles = cachedRoles[guild.id];
|
||||
cachedRoles = {};
|
||||
BDFDB.DataUtils.remove(this, "roles");
|
||||
}
|
||||
if (id) BDFDB.DataUtils.remove(this, "roles", id);
|
||||
else BDFDB.DataUtils.remove(this, "roles");
|
||||
}
|
||||
|
||||
openRoleSettingsModal (role) {
|
||||
|
|
Loading…
Reference in New Issue