mirror of
https://github.com/arthur-pbty/gestion.git
synced 2026-06-09 18:39:21 +02:00
grand commit que tutur attend ( marche pas le raidmode en dev)
sinon il y a pleins de truc comme les anti raid , des coorectif ect
This commit is contained in:
@@ -0,0 +1,152 @@
|
||||
const sqlite3 = require('sqlite3').verbose();
|
||||
const db = new sqlite3.Database('myDatabase.db');
|
||||
const { Events, AuditLogEvent, PermissionsBitField, EmbedBuilder } = require('discord.js');
|
||||
const { getPermissionLevel } = require('../../fonction/getPermissionLevel');
|
||||
module.exports = {
|
||||
name: Events.GuildUpdate,
|
||||
async execute(oldGuild, newGuild, client) {
|
||||
const botId = client.user.id;
|
||||
const guildId = oldGuild.id;
|
||||
const guild = oldGuild;
|
||||
const fetchedLogs = await guild.fetchAuditLogs({
|
||||
type: AuditLogEvent.GuildUpdate,
|
||||
limit: 1,
|
||||
});
|
||||
|
||||
const firstEntry = fetchedLogs.entries.first();
|
||||
const user = guild.members.cache.get(`${firstEntry.executor.id}`);
|
||||
if (user.id === client.user.id) return;
|
||||
|
||||
let data = await new Promise((resolve, reject) => {
|
||||
db.get('SELECT value FROM gestion WHERE id = ?', [botId], (err, row) => {
|
||||
if (err) {
|
||||
console.error(err.message);
|
||||
reject(err);
|
||||
}
|
||||
resolve(row ? JSON.parse(row.value) : {});
|
||||
});
|
||||
});
|
||||
|
||||
const antibotConfig = data[guildId]?.antiupdate;
|
||||
if (!antibotConfig || antibotConfig.type === 'off') {
|
||||
return;
|
||||
}
|
||||
data.whitelist = data.whitelist || {};
|
||||
data.whitelist[guildId] = data.whitelist[guildId] || {};
|
||||
const whitelist = data.whitelist[guildId];
|
||||
const type = antibotConfig.type;
|
||||
const permlevel = await getPermissionLevel(user, client)
|
||||
try {
|
||||
if (type === "whitelist") {
|
||||
if (permlevel >= 10) return;
|
||||
if (whitelist[user.id]) return;
|
||||
punish(user, antibotConfig.action, newGuild);
|
||||
await updateGuildSettings(oldGuild, newGuild);
|
||||
sendlog(user, antibotConfig.action, guild, data);
|
||||
} else if (type === "owner") {
|
||||
if (permlevel >= 10) return;
|
||||
punish(user, antibotConfig.action, newGuild);
|
||||
await updateGuildSettings(oldGuild, newGuild);
|
||||
sendlog(user, antibotConfig.action, guild, data);
|
||||
} else if (type === "buyer") {
|
||||
if (permlevel === 11) return;
|
||||
punish(user, antibotConfig.action, newGuild);
|
||||
await updateGuildSettings(oldGuild, newGuild);
|
||||
sendlog(user, antibotConfig.action, guild, data);
|
||||
}
|
||||
}catch(err) {
|
||||
console.log(err);
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
async function punish(user, action, guild) {
|
||||
switch (action) {
|
||||
case 'ban':
|
||||
await guild.members.ban(user, { reason: 'Anti-update protection' });
|
||||
break;
|
||||
case 'kick':
|
||||
await guild.members.kick(user, 'Anti-update protection');
|
||||
break;
|
||||
case 'derank':
|
||||
const dangerousPermissions = [
|
||||
PermissionsBitField.Flags.Administrator,
|
||||
PermissionsBitField.Flags.ManageGuild,
|
||||
PermissionsBitField.Flags.ManageRoles,
|
||||
PermissionsBitField.Flags.ManageChannels,
|
||||
PermissionsBitField.Flags.KickMembers,
|
||||
PermissionsBitField.Flags.BanMembers,
|
||||
PermissionsBitField.Flags.ManageWebhooks,
|
||||
PermissionsBitField.Flags.MuteMembers,
|
||||
PermissionsBitField.Flags.MentionEveryone,
|
||||
PermissionsBitField.Flags.ManageEvents,
|
||||
PermissionsBitField.Flags.ManageThreads,
|
||||
];
|
||||
const member = guild.members.cache.get(user.id);
|
||||
if (member) {
|
||||
const rolesToRemove = member.roles.cache.filter(role => dangerousPermissions.includes(role.permissions.bitfield));
|
||||
await member.roles.remove(rolesToRemove, 'Anti-update protection');
|
||||
}
|
||||
break;
|
||||
case 'nothing':
|
||||
break;
|
||||
}
|
||||
}
|
||||
async function updateGuildSettings(oldGuild, newGuild) {
|
||||
if (oldGuild.name !== newGuild.name) {
|
||||
await newGuild.setName(oldGuild.name);
|
||||
}
|
||||
if (oldGuild.iconURL({ dynamic: true }) !== newGuild.iconURL({ dynamic: true })) {
|
||||
await newGuild.setIcon(oldGuild.iconURL({ dynamic: true }));
|
||||
}
|
||||
if (oldGuild.bannerURL() !== newGuild.bannerURL()) {
|
||||
await newGuild.setBanner(oldGuild.bannerURL());
|
||||
}
|
||||
if (oldGuild.systemChannel !== newGuild.systemChannel) {
|
||||
await newGuild.setSystemChannel(oldGuild.systemChannel);
|
||||
}
|
||||
if (oldGuild.systemChannelFlags !== newGuild.systemChannelFlags) {
|
||||
await newGuild.setSystemChannelFlags(oldGuild.systemChannelFlags);
|
||||
}
|
||||
if (oldGuild.verificationLevel !== newGuild.verificationLevel) {
|
||||
await newGuild.setVerificationLevel(oldGuild.verificationLevel);
|
||||
}
|
||||
if (oldGuild.widget !== newGuild.widget) {
|
||||
await newGuild.setWidget(oldGuild.widget);
|
||||
}
|
||||
if (oldGuild.splashURL !== newGuild.splashURL) {
|
||||
await newGuild.setSplash(oldGuild.splashURL);
|
||||
}
|
||||
if (oldGuild.rulesChannel !== newGuild.rulesChannel) {
|
||||
await newGuild.setRulesChannel(oldGuild.rulesChannel);
|
||||
}
|
||||
if (oldGuild.publicUpdatesChannel !== newGuild.publicUpdatesChannel) {
|
||||
await newGuild.setPublicUpdatesChannel(oldGuild.publicUpdatesChannel);
|
||||
}
|
||||
if (oldGuild.defaultMessageNotifications !== newGuild.defaultMessageNotifications) {
|
||||
await newGuild.setDefaultMessageNotifications(oldGuild.defaultMessageNotifications);
|
||||
}
|
||||
if (oldGuild.afkChannel !== newGuild.afkChannel) {
|
||||
await newGuild.setAFKChannel(oldGuild.afkChannel);
|
||||
}
|
||||
if (oldGuild.region !== newGuild.region) {
|
||||
await newGuild.setRegion(oldGuild.region)
|
||||
}
|
||||
}
|
||||
async function sendlog(user, action, guild, data) {
|
||||
if (!data[guild.id]) {
|
||||
data[guild.id] = {};
|
||||
}
|
||||
const channelid = data[guild.id]?.raidlog;
|
||||
if(channelid) {
|
||||
const logChannel = guild.channels.cache.get(channelid);
|
||||
if (!logChannel) return ;
|
||||
|
||||
const embed = new EmbedBuilder()
|
||||
.setDescription(`L'utilisateur <@${user.id}> a modifiée le serveur et a été \`${action}\`.`)
|
||||
.setColor('#ADD8E6')
|
||||
.setTimestamp();
|
||||
|
||||
logChannel.send({ embeds: [embed] });
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user