mirror of
https://github.com/arthur-pbty/gestion.git
synced 2026-06-05 08:11:57 +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,112 @@
|
||||
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.ThreadCreate,
|
||||
async execute(thread, okman ,client) {
|
||||
const botId = client.user.id;
|
||||
const guildId = thread.guild.id;
|
||||
const guild = thread.guild;
|
||||
const fetchedLogs = await guild.fetchAuditLogs({
|
||||
type: AuditLogEvent.ThreadCreate,
|
||||
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 antiThreadConfig = data[guildId]?.antiThread;
|
||||
if (!antiThreadConfig || antiThreadConfig.type === 'off') {
|
||||
return;
|
||||
}
|
||||
data.whitelist = data.whitelist || {};
|
||||
data.whitelist[guildId] = data.whitelist[guildId] || {};
|
||||
const whitelist = data.whitelist[guildId];
|
||||
const type = antiThreadConfig.type;
|
||||
const permlevel = await getPermissionLevel(user, client)
|
||||
try {
|
||||
if (type === "whitelist") {
|
||||
if (permlevel >= 10) return;
|
||||
if (whitelist[user.id]) return;
|
||||
punish(user, antiThreadConfig.action, guild);
|
||||
await thread.delete('Anti-thread protection');
|
||||
await sendlog(user, antiThreadConfig.action, guild, data);
|
||||
} else if (type === "owner") {
|
||||
if (permlevel >= 10) return;
|
||||
punish(user, antiThreadConfig.action, guild);
|
||||
await thread.delete('Anti-thread protection');
|
||||
await sendlog(user, antiThreadConfig.action, guild, data);
|
||||
} else if (type === "buyer") {
|
||||
if (permlevel === 11) return;
|
||||
punish(user, antiThreadConfig.action, guild);
|
||||
await thread.delete('Anti-thread protection');
|
||||
await sendlog(user, antiThreadConfig.action, guild, data);
|
||||
}
|
||||
} catch(err) {
|
||||
console.error(err);
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
async function punish(user, action, guild) {
|
||||
switch (action) {
|
||||
case 'ban':
|
||||
await guild.members.ban(user, { reason: 'Anti-thread protection' });
|
||||
break;
|
||||
case 'kick':
|
||||
await guild.members.kick(user, 'Anti-thread 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-thread protection');
|
||||
}
|
||||
break;
|
||||
case 'nothing':
|
||||
break;
|
||||
}
|
||||
}
|
||||
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 crée un fil et a été \`${action}\`.`)
|
||||
.setColor('#ADD8E6')
|
||||
.setTimestamp();
|
||||
|
||||
logChannel.send({ embeds: [embed] });
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user