-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
111 lines (96 loc) · 4.01 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
const { Client, GatewayIntentBits, Collection } = require('discord.js');
const { token, logChannelId, giveawayChannelId } = require('./config/config.json');
const { readDB, writeDB } = require('./utils/db');
const fs = require('fs');
const path = require('path');
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent,
GatewayIntentBits.GuildMembers,
],
});
client.commands = new Collection();
const commandFolders = fs.readdirSync('./commands');
for (const folder of commandFolders) {
const commandFiles = fs.readdirSync(`./commands/${folder}`).filter(file => file.endsWith('.js'));
for (const file of commandFiles) {
const command = require(`./commands/${folder}/${file}`);
client.commands.set(command.data.name, command);
}
}
const eventFiles = fs.readdirSync('./events').filter(file => file.endsWith('.js'));
for (const file of eventFiles) {
const event = require(`./events/${file}`);
if (event.once) {
client.once(event.name, (...args) => event.execute(...args));
} else {
client.on(event.name, (...args) => event.execute(...args));
}
}
client.once('ready', () => {
console.log(`Logged in as ${client.user.tag}!`);
checkMutes(client);
});
client.on('interactionCreate', async interaction => {
if (interaction.isCommand()) {
const command = client.commands.get(interaction.commandName);
if (!command) return;
try {
await command.execute(interaction);
} catch (error) {
console.error(error);
await interaction.reply({ content: 'There was an error while executing this command!', ephemeral: true });
}
} else if (interaction.isButton()) {
const db = readDB();
const giveaway = db.giveaways.find(g => g.id === interaction.message.id);
if (!giveaway) {
return interaction.reply({ content: 'Giveaway introuvable.', ephemeral: true });
}
if (giveaway.participants.includes(interaction.user.id)) {
return interaction.reply({ content: 'Vous participez déjà à ce giveaway.', ephemeral: true });
}
giveaway.participants.push(interaction.user.id);
writeDB(db);
return interaction.reply({ content: 'Vous participez maintenant au giveaway.', ephemeral: true });
}
});
client.login(token);
function checkMutes(client) {
setInterval(async () => {
const db = readDB();
const now = Date.now();
const logChannel = client.channels.cache.get(logChannelId);
if (!logChannel) {
console.error(`Log channel not found with ID: ${logChannelId}`);
return;
}
if (db.moderation_logs) {
for (const log of db.moderation_logs) {
if (log.action === 'mute' && log.muteUntil <= now) {
const guild = client.guilds.cache.get(log.guildId);
if (guild) {
const member = guild.members.cache.get(log.userId);
if (member) {
try {
await member.timeout(null);
logChannel.send(`${member.user.tag} a été démute automatiquement.`);
console.log(`Unmuted ${member.user.tag} and sent log message.`);
} catch (error) {
console.error(`Failed to unmute ${member.user.tag}:`, error);
}
} else {
console.error(`Member not found with ID: ${log.userId}`);
}
} else {
console.error(`Guild not found with ID: ${log.guildId}`);
}
}
}
db.moderation_logs = db.moderation_logs.filter(log => log.action !== 'mute' || log.muteUntil > now);
writeDB(db);
}
}, 60000);
}