Add files via upload

This commit is contained in:
2025-08-30 18:05:01 +02:00
committed by GitHub
commit f22d04aa81
15 changed files with 2066 additions and 0 deletions

48
functions/database/db.js Normal file
View 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;

View File

@@ -0,0 +1,33 @@
// functions/moderation/autoUnban.js
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]
);
for (const ban of expiredBans) {
for (const guild of client.guilds.cache.values()) {
try {
await guild.members.unban(ban.userId, 'Temporary ban expired');
console.log(`Auto-unbanned ${ban.userId} from guild ${guild.id}`);
} catch (err) {
console.error(`Failed to unban ${ban.userId} from guild ${guild.id}`, err);
}
}
await db.query('DELETE FROM bans WHERE userId = ?', [ban.userId]);
await db.query(
`INSERT INTO logs (userId, userTag, modId, modTag, action, reason, type, timestamp)
VALUES (?, ?, ?, ?, ?, ?, ?, ?)`,
[ban.userId, null, null, null, 'auto-unban', 'Temporary ban expired', null, Date.now()]
);
}
} catch (err) {
console.error('Error during auto-unban:', err);
}
}, 60_000);
};