chore: 🎉 initial commit
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
const activeAlerts = new Map();
|
||||
|
||||
|
||||
function scheduleTicketClosure(channel, duration, closeFn) {
|
||||
if (activeAlerts.has(channel.id)) {
|
||||
clearTimeout(activeAlerts.get(channel.id));
|
||||
}
|
||||
|
||||
const timeout = setTimeout(async () => {
|
||||
activeAlerts.delete(channel.id);
|
||||
|
||||
await closeFn();
|
||||
}, duration);
|
||||
|
||||
activeAlerts.set(channel.id, timeout);
|
||||
}
|
||||
|
||||
function cancelTicketClosure(channelId) {
|
||||
if (activeAlerts.has(channelId)) {
|
||||
clearTimeout(activeAlerts.get(channelId));
|
||||
activeAlerts.delete(channelId);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
module.exports = { scheduleTicketClosure, cancelTicketClosure };
|
||||
@@ -0,0 +1,36 @@
|
||||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
const { Collection } = require("discord.js");
|
||||
|
||||
function loadButtons(client) {
|
||||
const interactionsPath = path.join(__dirname, "../interactions");
|
||||
client.buttons = new Collection();
|
||||
|
||||
if (!fs.existsSync(interactionsPath)) return client.buttons;
|
||||
|
||||
const files = fs.readdirSync(interactionsPath).filter(f => f.endsWith(".js"));
|
||||
|
||||
for (const file of files) {
|
||||
const button = require(path.join(interactionsPath, file));
|
||||
|
||||
if (button.id) {
|
||||
client.buttons.set(button.id, button);
|
||||
}
|
||||
}
|
||||
|
||||
return client.buttons;
|
||||
}
|
||||
|
||||
async function handleButton(interaction, client) {
|
||||
const button = client.buttons.get(interaction.customId);
|
||||
|
||||
if (button) return button.execute(interaction, client);
|
||||
|
||||
for (const btn of client.buttons.values()) {
|
||||
if (btn.id instanceof RegExp && btn.id.test(interaction.customId)) {
|
||||
return btn.execute(interaction, client);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = { loadButtons, handleButton };
|
||||
@@ -0,0 +1,42 @@
|
||||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
const { Collection } = require("discord.js");
|
||||
|
||||
function walkCommands(dir, callback) {
|
||||
const files = fs.readdirSync(dir, { withFileTypes: true });
|
||||
|
||||
for (const file of files) {
|
||||
const filePath = path.join(dir, file.name);
|
||||
|
||||
if (file.isDirectory()) {
|
||||
walkCommands(filePath, callback);
|
||||
} else if (file.name.endsWith(".js")) {
|
||||
const command = require(filePath);
|
||||
callback(command);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function loadCommands(client) {
|
||||
const commandsPath = path.join(__dirname, "../SlashCommand");
|
||||
client.commands = new Collection();
|
||||
|
||||
walkCommands(commandsPath, (command) => {
|
||||
client.commands.set(command.data.name, command);
|
||||
});
|
||||
|
||||
return client.commands;
|
||||
}
|
||||
|
||||
function getCommandsJSON() {
|
||||
const commandsPath = path.join(__dirname, "../SlashCommand");
|
||||
const commands = [];
|
||||
|
||||
walkCommands(commandsPath, (command) => {
|
||||
commands.push(command.data.toJSON());
|
||||
});
|
||||
|
||||
return commands;
|
||||
}
|
||||
|
||||
module.exports = { loadCommands, getCommandsJSON };
|
||||
@@ -0,0 +1,14 @@
|
||||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
const YAML = require("yaml");
|
||||
|
||||
function loadYAML(file) {
|
||||
const filePath = path.join(__dirname, "..", file);
|
||||
const content = fs.readFileSync(filePath, "utf8");
|
||||
return YAML.parse(content);
|
||||
}
|
||||
|
||||
const config = loadYAML("config.yml");
|
||||
const lang = loadYAML("lang.yml");
|
||||
|
||||
module.exports = { config, lang };
|
||||
@@ -0,0 +1,59 @@
|
||||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
const initSqlJs = require("sql.js");
|
||||
|
||||
const dbPath = path.join(__dirname, "../tickets.db");
|
||||
|
||||
let db;
|
||||
|
||||
async function initDB() {
|
||||
const SQL = await initSqlJs();
|
||||
|
||||
if (fs.existsSync(dbPath)) {
|
||||
const fileBuffer = fs.readFileSync(dbPath);
|
||||
db = new SQL.Database(fileBuffer);
|
||||
} else {
|
||||
db = new SQL.Database();
|
||||
db.run(`
|
||||
CREATE TABLE IF NOT EXISTS tickets (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
userId TEXT NOT NULL,
|
||||
channelId TEXT NOT NULL,
|
||||
status TEXT NOT NULL DEFAULT 'open'
|
||||
)
|
||||
`);
|
||||
saveDB();
|
||||
}
|
||||
}
|
||||
|
||||
function saveDB() {
|
||||
const data = db.export();
|
||||
fs.writeFileSync(dbPath, Buffer.from(data));
|
||||
}
|
||||
|
||||
function createTicket(userId, channelId) {
|
||||
db.run(
|
||||
"INSERT INTO tickets (userId, channelId, status) VALUES (?, ?, 'open')",
|
||||
[String(userId), String(channelId)]
|
||||
);
|
||||
saveDB();
|
||||
}
|
||||
|
||||
function getTicketByChannel(channelId) {
|
||||
const stmt = db.prepare(
|
||||
"SELECT * FROM tickets WHERE channelId = ? AND status = 'open'"
|
||||
);
|
||||
stmt.bind([String(channelId)]);
|
||||
const row = stmt.step() ? stmt.getAsObject() : null;
|
||||
stmt.free();
|
||||
return row;
|
||||
}
|
||||
|
||||
function closeTicket(channelId) {
|
||||
db.run("UPDATE tickets SET status = 'closed' WHERE channelId = ?", [
|
||||
String(channelId),
|
||||
]);
|
||||
saveDB();
|
||||
}
|
||||
|
||||
module.exports = { initDB, createTicket, getTicketByChannel, closeTicket };
|
||||
@@ -0,0 +1,30 @@
|
||||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
|
||||
function loadEvents(client) {
|
||||
const eventsPath = path.join(__dirname, "../events");
|
||||
|
||||
function walk(dir) {
|
||||
const files = fs.readdirSync(dir, { withFileTypes: true });
|
||||
|
||||
for (const file of files) {
|
||||
const filePath = path.join(dir, file.name);
|
||||
|
||||
if (file.isDirectory()) {
|
||||
walk(filePath);
|
||||
} else if (file.name.endsWith(".js")) {
|
||||
const event = require(filePath);
|
||||
|
||||
if (event.once) {
|
||||
client.once(event.name, (...args) => event.execute(...args, client));
|
||||
} else {
|
||||
client.on(event.name, (...args) => event.execute(...args, client));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
walk(eventsPath);
|
||||
}
|
||||
|
||||
module.exports = { loadEvents };
|
||||
@@ -0,0 +1,27 @@
|
||||
const chalk = require("chalk");
|
||||
|
||||
function timestamp() {
|
||||
return chalk.gray(`[${new Date().toLocaleTimeString("fr-FR")}]`);
|
||||
}
|
||||
|
||||
const logger = {
|
||||
info: (msg) => {
|
||||
console.log(`${timestamp()} ${chalk.blue("[INFO]")} ${msg}`);
|
||||
},
|
||||
success: (msg) => {
|
||||
console.log(`${timestamp()} ${chalk.green("[SUCCESS]")} ${msg}`);
|
||||
},
|
||||
warn: (msg) => {
|
||||
console.warn(`${timestamp()} ${chalk.yellow("[WARN]")} ${msg}`);
|
||||
},
|
||||
error: (msg) => {
|
||||
console.error(`${timestamp()} ${chalk.red("[ERROR]")} ${msg}`);
|
||||
},
|
||||
debug: (msg) => {
|
||||
if (process.env.DEBUG === "true") {
|
||||
console.log(`${timestamp()} ${chalk.magenta("[DEBUG]")} ${msg}`);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = logger;
|
||||
@@ -0,0 +1,32 @@
|
||||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
const { Collection } = require("discord.js");
|
||||
|
||||
function loadMenus(client) {
|
||||
const interactionsPath = path.join(__dirname, "../interactions");
|
||||
client.menus = new Collection();
|
||||
|
||||
if (!fs.existsSync(interactionsPath)) return client.menus;
|
||||
|
||||
const files = fs.readdirSync(interactionsPath).filter(f => f.toLowerCase().includes("menu") && f.endsWith(".js"));
|
||||
|
||||
for (const file of files) {
|
||||
const menu = require(path.join(interactionsPath, file));
|
||||
client.menus.set(menu.id, menu);
|
||||
}
|
||||
|
||||
return client.menus;
|
||||
}
|
||||
|
||||
async function handleMenu(interaction, client) {
|
||||
for (const menu of client.menus.values()) {
|
||||
if (typeof menu.id === "string" && menu.id === interaction.customId) {
|
||||
return menu.execute(interaction, client);
|
||||
}
|
||||
if (menu.id instanceof RegExp && menu.id.test(interaction.customId)) {
|
||||
return menu.execute(interaction, client);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = { loadMenus, handleMenu };
|
||||
@@ -0,0 +1,24 @@
|
||||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
const { Collection } = require("discord.js");
|
||||
const { config } = require("./configLoader");
|
||||
|
||||
function loadModals(client) {
|
||||
const interactionsPath = path.join(__dirname, "../interactions");
|
||||
client.modals = new Collection();
|
||||
|
||||
const files = fs.readdirSync(interactionsPath).filter(f => f.toLowerCase().includes("modal") && f.endsWith(".js"));
|
||||
|
||||
for (const file of files) {
|
||||
const modal = require(path.join(interactionsPath, file));
|
||||
client.modals.set(modal.id, modal);
|
||||
}
|
||||
|
||||
return client.modals;
|
||||
}
|
||||
|
||||
function getModal(customId) {
|
||||
return config.TicketPanel?.Modals?.[customId] || null;
|
||||
}
|
||||
|
||||
module.exports = { loadModals, getModal };
|
||||
Reference in New Issue
Block a user