Tojikimado
Tojikimado
DIAdiscord.js - Imagine an app
Created by Tojikimado on 2/7/2024 in #djs-questions
Log channel's permissions update
Here’s my code: https://starb.in/KTwWnt.typescript I still can’t manage when I update the perms of two channel'sroles, the channelUpdate event is fired twice and I got 2 logs but I only want one log with all the changes.
44 replies
DIAdiscord.js - Imagine an app
Created by Tojikimado on 2/7/2024 in #djs-questions
Log channel's permissions update
I haven’t changed anything and it works fine when I change the perms of a role. It still doesn’t work when I was editing multiple roles, but it’s normal because I still haven’t managed it
44 replies
DIAdiscord.js - Imagine an app
Created by Tojikimado on 2/7/2024 in #djs-questions
Log channel's permissions update
I clean my code : https://starb.in/0C8Rmd.typescript But now when i'm updating channel's perms, it doesn't work anymore. For example if i edit only one perm of everyone role, i got this log : Modification des permissions d'un salon Les permissions du salon ⁠aaaaa ont été modifiées ! everyone ✅ | ViewChannel Tojikimado ✅ | ViewChannel A ✅ | ViewChannel K ✅ | ViewChannel Channel modifié par Tojikimado•Aujourd’hui à 16:26 If i edit one perm in 2 roles (everyone & K), i got this logs : Modification des permissions d'un salon Les permissions du salon ⁠aaaaa ont été modifiées ! K ❌ | ViewChannel Tojikimado ❌ | ViewChannel everyone ❌ | ViewChannel ❌ | ViewChannel Channel modifié par Tojikimado•Aujourd’hui à 16:27 Modification des permissions d'un salon Les permissions du salon ⁠aaaaa ont été modifiées ! K ❌ | ViewChannel Tojikimado ❌ | ViewChannel everyone ❌ | ViewChannel Channel modifié par Tojikimado•Aujourd’hui à 16:27 Am I missing something ?
44 replies
DIAdiscord.js - Imagine an app
Created by Tojikimado on 2/7/2024 in #djs-questions
Log channel's permissions update
Yeah it's not broken but i only want one log
44 replies
DIAdiscord.js - Imagine an app
Created by Tojikimado on 2/7/2024 in #djs-questions
Log channel's permissions update
By "fix", i mean only have one log with all changes
44 replies
DIAdiscord.js - Imagine an app
Created by Tojikimado on 2/7/2024 in #djs-questions
Log channel's permissions update
How can i "fix" this ?
44 replies
DIAdiscord.js - Imagine an app
Created by Tojikimado on 2/7/2024 in #djs-questions
Log channel's permissions update
No description
44 replies
DIAdiscord.js - Imagine an app
Created by Tojikimado on 2/7/2024 in #djs-questions
Log channel's permissions update
missingAllowInNew.forEach(permission => {
if (!missingDenyInOld.includes(permission) && !missingDenyInNew.includes(permission))
rolePermissions.default.push(`🔳 | ${permission}`);
else if (!missingAllowInOld.includes(permission))
rolePermissions.allowed.push(`✅ | ${permission}`);
});

missingAllowInOld.forEach(permission => {
if (newPermissions.allow.has(permission))
rolePermissions.allowed.push(`✅ | ${permission}`);
});

missingDenyInNew.forEach(permission => {
if (!missingAllowInOld.includes(permission) && !missingAllowInNew.includes(permission))
rolePermissions.default.push(`🔳 | ${permission}`);
else if (!missingDenyInOld.includes(permission))
rolePermissions.denied.push(`❌ | ${permission}`);
});

missingDenyInOld.forEach(permission => {
if (newPermissions.deny.has(permission))
rolePermissions.denied.push(`❌ | ${permission}`);
});
missingAllowInNew.forEach(permission => {
if (!missingDenyInOld.includes(permission) && !missingDenyInNew.includes(permission))
rolePermissions.default.push(`🔳 | ${permission}`);
else if (!missingAllowInOld.includes(permission))
rolePermissions.allowed.push(`✅ | ${permission}`);
});

missingAllowInOld.forEach(permission => {
if (newPermissions.allow.has(permission))
rolePermissions.allowed.push(`✅ | ${permission}`);
});

missingDenyInNew.forEach(permission => {
if (!missingAllowInOld.includes(permission) && !missingAllowInNew.includes(permission))
rolePermissions.default.push(`🔳 | ${permission}`);
else if (!missingDenyInOld.includes(permission))
rolePermissions.denied.push(`❌ | ${permission}`);
});

missingDenyInOld.forEach(permission => {
if (newPermissions.deny.has(permission))
rolePermissions.denied.push(`❌ | ${permission}`);
});
I just added the default perm detection, and now when I change a allow perm to deny or deny to allow, it logs me this and I don’t understand why because it worked before: ✅ | ManageChannels ❌ | ManageChannels
44 replies
DIAdiscord.js - Imagine an app
Created by Tojikimado on 2/7/2024 in #djs-questions
Log channel's permissions update
After multiple tries, i still can't catch when a perm switch to default
44 replies
DIAdiscord.js - Imagine an app
Created by Tojikimado on 2/7/2024 in #djs-questions
Log channel's permissions update
I quickly checked what we discussed. I don’t understand how to set the perm to and do this rolePermissions.default.push(“🔳 | ${permission}”) Everything else is correct? Here is my code :
else {
embed.setTitle("Modification des permissions d'un salon");
embed.setDescription(`Les permissions du salon ${newChannel.toString()} ont été modifiées ! \n`)

for (const [key, newPermissions] of newPermissionsOverwrites.cache) {
const oldPermissions = oldPermissionsOverWrites.cache.get(key);

const missingAllowInNew = newPermissions.allow.missing(oldPermissions.allow);
const missingAllowInOld = oldPermissions.allow.missing(newPermissions.allow);
const missingDenyInNew = newPermissions.deny.missing(oldPermissions.deny);
const missingDenyInOld = oldPermissions.deny.missing(newPermissions.deny);

const rolePermissions = {
allowed: [],
denied: [],
default: []
};
//rolePermissions.default.push(`🔳 | ${permission}`);
missingAllowInNew.forEach(permission => {
if (!missingAllowInOld.includes(permission))
rolePermissions.allowed.push(`✅ | ${permission}`);
});

missingAllowInOld.forEach(permission => {
if (newPermissions.allow.has(permission))
rolePermissions.allowed.push(`✅ | ${permission}`);
});

missingDenyInNew.forEach(permission => {
if (!missingDenyInOld.includes(permission))
rolePermissions.denied.push(`❌ | ${permission}`);
});

missingDenyInOld.forEach(permission => {
if (newPermissions.deny.has(permission))
rolePermissions.denied.push(`❌ | ${permission}`);
});

if (rolePermissions.allowed.length > 0 || rolePermissions.denied.length > 0 || rolePermissions.default.length > 0) {
let roleName = newChannel.guild.roles.cache.get(key)?.name ?? await newChannel.guild.members.fetch(key);
if (roleName?.user?.globalName)
roleName = roleName.user.globalName;
else if (roleName?.user?.username)
roleName = roleName.user.username;
embed.data.description += `\n**${roleName}**\n`;
if (rolePermissions.allowed.length > 0)
embed.data.description += rolePermissions.allowed.join('\n') + '\n';
if (rolePermissions.default.length > 0)
embed.data.description += rolePermissions.default.join('\n') + '\n';
if (rolePermissions.denied.length > 0)
embed.data.description += rolePermissions.denied.join('\n') + '\n';
}
};
}
else {
embed.setTitle("Modification des permissions d'un salon");
embed.setDescription(`Les permissions du salon ${newChannel.toString()} ont été modifiées ! \n`)

for (const [key, newPermissions] of newPermissionsOverwrites.cache) {
const oldPermissions = oldPermissionsOverWrites.cache.get(key);

const missingAllowInNew = newPermissions.allow.missing(oldPermissions.allow);
const missingAllowInOld = oldPermissions.allow.missing(newPermissions.allow);
const missingDenyInNew = newPermissions.deny.missing(oldPermissions.deny);
const missingDenyInOld = oldPermissions.deny.missing(newPermissions.deny);

const rolePermissions = {
allowed: [],
denied: [],
default: []
};
//rolePermissions.default.push(`🔳 | ${permission}`);
missingAllowInNew.forEach(permission => {
if (!missingAllowInOld.includes(permission))
rolePermissions.allowed.push(`✅ | ${permission}`);
});

missingAllowInOld.forEach(permission => {
if (newPermissions.allow.has(permission))
rolePermissions.allowed.push(`✅ | ${permission}`);
});

missingDenyInNew.forEach(permission => {
if (!missingDenyInOld.includes(permission))
rolePermissions.denied.push(`❌ | ${permission}`);
});

missingDenyInOld.forEach(permission => {
if (newPermissions.deny.has(permission))
rolePermissions.denied.push(`❌ | ${permission}`);
});

if (rolePermissions.allowed.length > 0 || rolePermissions.denied.length > 0 || rolePermissions.default.length > 0) {
let roleName = newChannel.guild.roles.cache.get(key)?.name ?? await newChannel.guild.members.fetch(key);
if (roleName?.user?.globalName)
roleName = roleName.user.globalName;
else if (roleName?.user?.username)
roleName = roleName.user.username;
embed.data.description += `\n**${roleName}**\n`;
if (rolePermissions.allowed.length > 0)
embed.data.description += rolePermissions.allowed.join('\n') + '\n';
if (rolePermissions.default.length > 0)
embed.data.description += rolePermissions.default.join('\n') + '\n';
if (rolePermissions.denied.length > 0)
embed.data.description += rolePermissions.denied.join('\n') + '\n';
}
};
}
44 replies
DIAdiscord.js - Imagine an app
Created by Tojikimado on 2/7/2024 in #djs-questions
Log channel's permissions update
The state before is not really important. I want to see if it's now default. For the role name i can do this ? : const roleName = newChannel.guild.roles.cache.get(key) |.| (search member with id) || "@everyone"; I will test after when I’m back on my pc
44 replies
DIAdiscord.js - Imagine an app
Created by Tojikimado on 2/7/2024 in #djs-questions
Log channel's permissions update
Oh yeah mb, i forget this basic thing
44 replies
DIAdiscord.js - Imagine an app
Created by Tojikimado on 2/7/2024 in #djs-questions
Log channel's permissions update
Same for missingAllowInOld inside the loop of missingAllowInNew ? With this system how can i know when perm = default ?
44 replies
DIAdiscord.js - Imagine an app
Created by Tojikimado on 2/7/2024 in #djs-questions
Log channel's permissions update
And if it's a member how can i get him ? 🤔
44 replies
DIAdiscord.js - Imagine an app
Created by Tojikimado on 2/7/2024 in #djs-questions
Log channel's permissions update
Thank you. Do you have any idea for when i switch to default ? I didn’t have much time so I did this quickly without testing. I’ll see a little later
44 replies
DIAdiscord.js - Imagine an app
Created by Tojikimado on 2/7/2024 in #djs-questions
Log channel's permissions update
@Qjuh It's not working at 100% for now roleName is always = everyone if perm is allowed or denied and i switch it to default, it's not working
newPermissionsOverwrites.cache.forEach((newPermissions, key) => {
const oldPermissions = oldPermissionsOverWrites.cache.get(key);

const missingAllowInNew = newPermissions.allow.missing(oldPermissions.allow);
const missingAllowInOld = oldPermissions.allow.missing(newPermissions.allow);
const missingDenyInNew = newPermissions.deny.missing(oldPermissions.deny);
const missingDenyInOld = oldPermissions.deny.missing(newPermissions.deny);

const rolePermissions = {
allowed: [],
denied: [],
default: []
};

missingAllowInNew.forEach(permission => {
if (!missingAllowInOld.includes(permission)) {
rolePermissions.allowed.push(`✅ | ${permission}`);
} else if (oldPermissions.allow.hasDefault(permission)) {
rolePermissions.default.push(`🔳 | ${permission}`);
}
});

missingAllowInOld.forEach(permission => {
if (!missingAllowInNew.includes(permission)) {
if (newPermissions.allow.has(permission)) {
rolePermissions.allowed.push(`✅ | ${permission}`);
} else {
rolePermissions.default.push(`🔳 | ${permission}`);
}
}
});

missingDenyInNew.forEach(permission => {
if (!missingDenyInOld.includes(permission)) {
rolePermissions.denied.push(`❌ | ${permission}`);
} else if (oldPermissions.deny.hasDefault(permission)) {
rolePermissions.default.push(`🔳 | ${permission}`);
}
});

missingDenyInOld.forEach(permission => {
if (!missingDenyInNew.includes(permission)) {
if (newPermissions.deny.has(permission)) {
rolePermissions.denied.push(`❌ | ${permission}`);
} else {
rolePermissions.default.push(`🔳 | ${permission}`);
}
}
});

if (rolePermissions.allowed.length > 0 || rolePermissions.denied.length > 0 || rolePermissions.default.length > 0) {
const roleName = newPermissionsOverwrites.cache.get(key).name || "@everyone";
embed.data.description += `\n**${roleName}**\n`;
if (rolePermissions.allowed.length > 0)
embed.data.description += rolePermissions.allowed.join('\n') + '\n';
if (rolePermissions.default.length > 0)
embed.data.description += rolePermissions.default.join('\n') + '\n';
if (rolePermissions.denied.length > 0)
embed.data.description += rolePermissions.denied.join('\n') + '\n';
}
});
newPermissionsOverwrites.cache.forEach((newPermissions, key) => {
const oldPermissions = oldPermissionsOverWrites.cache.get(key);

const missingAllowInNew = newPermissions.allow.missing(oldPermissions.allow);
const missingAllowInOld = oldPermissions.allow.missing(newPermissions.allow);
const missingDenyInNew = newPermissions.deny.missing(oldPermissions.deny);
const missingDenyInOld = oldPermissions.deny.missing(newPermissions.deny);

const rolePermissions = {
allowed: [],
denied: [],
default: []
};

missingAllowInNew.forEach(permission => {
if (!missingAllowInOld.includes(permission)) {
rolePermissions.allowed.push(`✅ | ${permission}`);
} else if (oldPermissions.allow.hasDefault(permission)) {
rolePermissions.default.push(`🔳 | ${permission}`);
}
});

missingAllowInOld.forEach(permission => {
if (!missingAllowInNew.includes(permission)) {
if (newPermissions.allow.has(permission)) {
rolePermissions.allowed.push(`✅ | ${permission}`);
} else {
rolePermissions.default.push(`🔳 | ${permission}`);
}
}
});

missingDenyInNew.forEach(permission => {
if (!missingDenyInOld.includes(permission)) {
rolePermissions.denied.push(`❌ | ${permission}`);
} else if (oldPermissions.deny.hasDefault(permission)) {
rolePermissions.default.push(`🔳 | ${permission}`);
}
});

missingDenyInOld.forEach(permission => {
if (!missingDenyInNew.includes(permission)) {
if (newPermissions.deny.has(permission)) {
rolePermissions.denied.push(`❌ | ${permission}`);
} else {
rolePermissions.default.push(`🔳 | ${permission}`);
}
}
});

if (rolePermissions.allowed.length > 0 || rolePermissions.denied.length > 0 || rolePermissions.default.length > 0) {
const roleName = newPermissionsOverwrites.cache.get(key).name || "@everyone";
embed.data.description += `\n**${roleName}**\n`;
if (rolePermissions.allowed.length > 0)
embed.data.description += rolePermissions.allowed.join('\n') + '\n';
if (rolePermissions.default.length > 0)
embed.data.description += rolePermissions.default.join('\n') + '\n';
if (rolePermissions.denied.length > 0)
embed.data.description += rolePermissions.denied.join('\n') + '\n';
}
});
44 replies
DIAdiscord.js - Imagine an app
Created by Tojikimado on 2/7/2024 in #djs-questions
Log channel's permissions update
So now, i only have this :
newPermissionsOverwrites.cache.forEach((newPermissions, key) => {
const oldPermissions = oldPermissionsOverWrites.cache.get(key);

const missingAllowInNew = newPermissions.allow.missing(oldPermissions.allow);
const missingAllowInOld = oldPermissions.allow.missing(newPermissions.allow);
const missingDenyInNew = newPermissions.deny.missing(oldPermissions.deny);
const missingDenyInOld = oldPermissions.deny.missing(newPermissions.deny);

missingAllowInNew.forEach(permission => {
if (!missingAllowInOld.includes(permission)) {
console.log(`New permission added or changed from default: ${permission}`);
}
});
missingAllowInOld.forEach(permission => {
if (!missingAllowInNew.includes(permission)) {
console.log(`Permission removed or changed to default: ${permission}`);
}
});
missingDenyInNew.forEach(permission => {
if (!missingDenyInOld.includes(permission)) {
console.log(`New deny permission added or changed from default: ${permission}`);
}
});
missingDenyInOld.forEach(permission => {
if (!missingDenyInNew.includes(permission)) {
console.log(`Deny permission removed or changed to default: ${permission}`);
}
});
});
newPermissionsOverwrites.cache.forEach((newPermissions, key) => {
const oldPermissions = oldPermissionsOverWrites.cache.get(key);

const missingAllowInNew = newPermissions.allow.missing(oldPermissions.allow);
const missingAllowInOld = oldPermissions.allow.missing(newPermissions.allow);
const missingDenyInNew = newPermissions.deny.missing(oldPermissions.deny);
const missingDenyInOld = oldPermissions.deny.missing(newPermissions.deny);

missingAllowInNew.forEach(permission => {
if (!missingAllowInOld.includes(permission)) {
console.log(`New permission added or changed from default: ${permission}`);
}
});
missingAllowInOld.forEach(permission => {
if (!missingAllowInNew.includes(permission)) {
console.log(`Permission removed or changed to default: ${permission}`);
}
});
missingDenyInNew.forEach(permission => {
if (!missingDenyInOld.includes(permission)) {
console.log(`New deny permission added or changed from default: ${permission}`);
}
});
missingDenyInOld.forEach(permission => {
if (!missingDenyInNew.includes(permission)) {
console.log(`Deny permission removed or changed to default: ${permission}`);
}
});
});
Is that what you said ? But i don't see what i can do whith this
44 replies
DIAdiscord.js - Imagine an app
Created by Tojikimado on 2/7/2024 in #djs-questions
Log channel's permissions update
I don't really see how can i only loop over all changed permissions before updating log description with the state of the permission (allow, deny or default)
44 replies
DIAdiscord.js - Imagine an app
Created by Tojikimado on 2/7/2024 in #djs-questions
Log channel's permissions update
Hmm I’ll check how to do this, I hope it won’t take me long
44 replies
DIAdiscord.js - Imagine an app
Created by Tojikimado on 2/7/2024 in #djs-questions
Log channel's permissions update
I'm a bit confused here 😅 If i look at my last version of the code. I have to only have one for each on the roles that have overwrites and remove this one newPermissionsOverwrites.cache.forEach((newPermissions, key) => { ? And remove the 6 forEach and use something like this const newPermissions = newPermissionsOverwrites.cache.get(role.id) ?
44 replies