From 12c15fc62d5c64f3b8f0d2b262ddbd6bec7f2c45 Mon Sep 17 00:00:00 2001 From: ChrisChrome Date: Mon, 22 Jul 2024 16:40:48 -0600 Subject: [PATCH] Add stuff --- helpers.js | 18 +++++++++ index.js | 98 +++++++++++++++++++++++++++++++++++++++++++++++ package-lock.json | 17 +++++++- package.json | 4 +- 4 files changed, 135 insertions(+), 2 deletions(-) diff --git a/helpers.js b/helpers.js index 096d153..87b14dc 100644 --- a/helpers.js +++ b/helpers.js @@ -1,3 +1,5 @@ +const moment = require('moment'); +require('moment-duration-format'); module.exports = {} const change = 62167219200; // Subtract a year, whoops module.exports.convertSLTimestamp = (timestamp) => { @@ -69,6 +71,22 @@ module.exports.diff = (oldData, newData) => { return result; } +module.exports.generateBanFile = (bans) => { + let banFile = ""; + Object.keys(bans).forEach(key => { + ban = bans[key]; + banFile += `${ban.banned_username};${ban.banned_id};${module.exports.toSLTimestamp(ban.expires)};${ban.reason};${ban.moderator};${module.exports.toSLTimestamp(ban.banned_timestamp)}\n` + }) + return banFile; +}; +module.exports.generateBanLine = (ban) => { + return `${ban.banned_username};${ban.banned_id};${module.exports.toSLTimestamp(ban.expires)};${ban.reason};${ban.moderator};${module.exports.toSLTimestamp(ban.banned_timestamp)}` +} + +module.exports.removeBan = (bans, id) => { + delete bans[id]; + return bans; +} return module.exports \ No newline at end of file diff --git a/index.js b/index.js index 9c6ec7b..0bfcf6e 100644 --- a/index.js +++ b/index.js @@ -91,6 +91,104 @@ client.on('ready', async () => { watchFiles(); }); +client.on('interactionCreate', async interaction => { + if (!interaction.isCommand()) return; + switch (interaction.commandName) { + case "ban": + switch (interaction.options.getSubcommand()) { + case "lookup": + type = interaction.options.getString("type"); + value = interaction.options.getString("value"); + if (type == "ip") { + if (ipBans[value]) { + embed = { + fields: [ + { + name: "Banned Username", + value: ipBans[value].banned_username, + inline: true + }, + { + name: "Banned ID", + value: ipBans[value].banned_id, + inline: true + }, + { + name: "Banned", + value: ` `, + inline: true + }, + { + name: "Expires", + value: ` `, + inline: true + }, + { + name: "Reason", + value: ipBans[value].reason, + inline: true + }, + { + name: "Moderator", + value: ipBans[value].moderator, + inline: true + } + ] + } + embed.title = "IP Ban Lookup" + embed.color = 0xffff00 + interaction.reply({ embeds: [embed] }) + } else { + interaction.reply("No ban found for that IP") + } + } else if (type == "id") { + if (idBans[value]) { + embed = { + fields: [ + { + name: "Banned Username", + value: idBans[value].banned_username, + inline: true + }, + { + name: "Banned ID", + value: idBans[value].banned_id, + inline: true + }, + { + name: "Banned", + value: ` `, + inline: true + }, + { + name: "Expires", + value: ` `, + inline: true + }, + { + name: "Reason", + value: idBans[value].reason, + inline: true + }, + { + name: "Moderator", + value: idBans[value].moderator, + inline: true + } + ] + } + embed.title = "ID Ban Lookup" + embed.color = 0xffff00 + interaction.reply({ embeds: [embed] }) + } else { + interaction.reply("No ban found for that ID") + } + } + break; + } + break; + } +}); const sendMessages = async (data) => { diff --git a/package-lock.json b/package-lock.json index 74c68ec..579d0d3 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11,7 +11,9 @@ "dependencies": { "colors": "^1.4.0", "discord.js": "^14.15.3", - "dotenv": "^16.4.5" + "dotenv": "^16.4.5", + "moment": "^2.30.1", + "moment-duration-format": "^2.3.2" } }, "node_modules/@discordjs/builders": { @@ -257,6 +259,19 @@ "resolved": "https://registry.npmjs.org/magic-bytes.js/-/magic-bytes.js-1.10.0.tgz", "integrity": "sha512-/k20Lg2q8LE5xiaaSkMXk4sfvI+9EGEykFS4b0CHHGWqDYU0bGUFSwchNOMA56D7TCs9GwVTkqe9als1/ns8UQ==" }, + "node_modules/moment": { + "version": "2.30.1", + "resolved": "https://registry.npmjs.org/moment/-/moment-2.30.1.tgz", + "integrity": "sha512-uEmtNhbDOrWPFS+hdjFCBfy9f2YoyzRpwcl+DqpC6taX21FzsTLQVbMV/W7PzNSX6x/bhC1zA3c2UQ5NzH6how==", + "engines": { + "node": "*" + } + }, + "node_modules/moment-duration-format": { + "version": "2.3.2", + "resolved": "https://registry.npmjs.org/moment-duration-format/-/moment-duration-format-2.3.2.tgz", + "integrity": "sha512-cBMXjSW+fjOb4tyaVHuaVE/A5TqkukDWiOfxxAjY+PEqmmBQlLwn+8OzwPiG3brouXKY5Un4pBjAeB6UToXHaQ==" + }, "node_modules/ts-mixer": { "version": "6.0.4", "resolved": "https://registry.npmjs.org/ts-mixer/-/ts-mixer-6.0.4.tgz", diff --git a/package.json b/package.json index 40e2c55..7d02c3f 100644 --- a/package.json +++ b/package.json @@ -11,6 +11,8 @@ "dependencies": { "colors": "^1.4.0", "discord.js": "^14.15.3", - "dotenv": "^16.4.5" + "dotenv": "^16.4.5", + "moment": "^2.30.1", + "moment-duration-format": "^2.3.2" } }