Update bot
This commit is contained in:
48
functions/database/db.js
Normal file
48
functions/database/db.js
Normal file
@@ -0,0 +1,48 @@
|
||||
const mysql = require('mysql2/promise');
|
||||
|
||||
|
||||
const pool = mysql.createPool({
|
||||
host: '192.168.1.6',
|
||||
user: 'bot',
|
||||
password: 'NxKr63LJB65pHv%t7E$JqgxKRsZMw%VIHEZAjq%^O0KYKjW#cRc^ebIH@%S9kaTh*GIg^D3ai4KBjMeXEh6xwv#9afQIR2$!2UB8C3ToXjnYFmzR%$lfpshnf8g@8229',
|
||||
database: 'bot',
|
||||
waitForConnections: true,
|
||||
connectionLimit: 10,
|
||||
queueLimit: 0
|
||||
});
|
||||
|
||||
async function initDB() {
|
||||
const conn = await pool.getConnection();
|
||||
try {
|
||||
await conn.query(`
|
||||
CREATE TABLE IF NOT EXISTS bans (
|
||||
userId VARCHAR(32) PRIMARY KEY,
|
||||
reason TEXT,
|
||||
modId VARCHAR(32),
|
||||
timestamp BIGINT,
|
||||
type VARCHAR(20) NOT NULL,
|
||||
unbanDate BIGINT
|
||||
)
|
||||
`);
|
||||
|
||||
await conn.query(`
|
||||
CREATE TABLE IF NOT EXISTS logs (
|
||||
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||
userId VARCHAR(32),
|
||||
userTag VARCHAR(100),
|
||||
modId VARCHAR(32),
|
||||
modTag VARCHAR(100),
|
||||
action VARCHAR(20),
|
||||
reason TEXT,
|
||||
type ENUM('Permanent','Temporary') DEFAULT 'Permanent',
|
||||
timestamp BIGINT
|
||||
)
|
||||
`);
|
||||
} finally {
|
||||
conn.release();
|
||||
}
|
||||
}
|
||||
|
||||
initDB().catch(console.error);
|
||||
|
||||
module.exports = pool;
|
||||
42
functions/moderation/autoUnban.js
Normal file
42
functions/moderation/autoUnban.js
Normal file
@@ -0,0 +1,42 @@
|
||||
module.exports = (client, db) => {
|
||||
setInterval(async () => {
|
||||
try {
|
||||
const now = Date.now();
|
||||
const [expiredBans] = await db.query(
|
||||
'SELECT * FROM bans WHERE type = ? AND unbanDate <= ?',
|
||||
['Temporary', now]
|
||||
);
|
||||
|
||||
if (!expiredBans.length) return; // rien à faire
|
||||
|
||||
for (const ban of expiredBans) {
|
||||
const guild = client.guilds.cache.get(ban.guildId);
|
||||
if (!guild) {
|
||||
console.warn(`Cannot unban ${ban.userId}: bot is not in guild ${ban.guildId}`);
|
||||
continue;
|
||||
}
|
||||
|
||||
try {
|
||||
await guild.members.unban(ban.userId, 'Temporary ban expired');
|
||||
console.log(`Auto-unbanned ${ban.userId} from guild ${guild.id}`);
|
||||
} catch (err) {
|
||||
// Si l’utilisateur n’est pas ban ou autre erreur
|
||||
console.error(`Failed to unban ${ban.userId} from guild ${guild.id}:`, err.message);
|
||||
}
|
||||
|
||||
// Supprime uniquement le ban correspondant à cette guild
|
||||
await db.query('DELETE FROM bans WHERE userId = ? AND guildId = ?', [ban.userId, ban.guildId]);
|
||||
|
||||
// Log automatique
|
||||
await db.query(
|
||||
`INSERT INTO logs (userId, userTag, modId, modTag, action, reason, type, timestamp, guildId)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)`,
|
||||
[ban.userId, null, client.user.id, 'Fembot', 'auto-unban', 'Temporary ban expired', 'Temporary', Date.now(), ban.guildId]
|
||||
);
|
||||
}
|
||||
|
||||
} catch (err) {
|
||||
console.error('Error during auto-unban:', err);
|
||||
}
|
||||
}, 60_000);
|
||||
};
|
||||
Reference in New Issue
Block a user