diff --git a/.gitignore b/.gitignore index 3f756f6..900c846 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ config.json node_modules/ -jsconfig.json \ No newline at end of file +jsconfig.json +database.sqlite \ No newline at end of file diff --git a/Util/Models sequalize.js b/Util/Models sequalize.js deleted file mode 100644 index 0975269..0000000 --- a/Util/Models sequalize.js +++ /dev/null @@ -1,23 +0,0 @@ -const Sequelize = require('sequelize'); - -const sequelize = new Sequelize('database', 'user', 'password', { - host: 'localhost', - dialect: 'sqlite', - logging: false, - storage: 'database.sqlite' -}) - -const Ban = sequelize.define('ban', { - userID:{ - type: Sequelize.NUMBER, - }, - raison: { - type: Sequelize.TEXT, - defaultValue: "No raison provided" - }, - Executor: Sequelize.STRING, - type: { - type: Sequelize.STRING, - }, - ID: Sequelize.NUMBER -}); \ No newline at end of file diff --git a/Util/database.js b/Util/database.js new file mode 100644 index 0000000..c102373 --- /dev/null +++ b/Util/database.js @@ -0,0 +1,37 @@ +const Sequelize = require('sequelize'); + +const sequelize = new Sequelize('database', 'user', 'password', { + host: 'localhost', + dialect: 'sqlite', + logging: false, + storage: 'database.sqlite' +}) + +const Bans = sequelize.define('bans', { + userID:{ + type: Sequelize.NUMBER, + }, + reason: { + type: Sequelize.TEXT, + defaultValue: "No reason provided" + }, + Executor: Sequelize.STRING, + type: { + type: Sequelize.STRING, + }//, + //ID: Sequelize.NUMBER +}); + +const Warns = sequelize.define('warns', { + userID:{ + type: Sequelize.NUMBER, + }, + reason: { + type: Sequelize.TEXT, + defaultValue: "No reason provided" + }, + Executor: Sequelize.STRING//, + // ID: Sequelize.NUMBER +}); + +module.exports = { Bans, Warns } \ No newline at end of file diff --git a/commands/ban.js b/commands/ban.js index b04147b..8d877c0 100644 --- a/commands/ban.js +++ b/commands/ban.js @@ -15,18 +15,23 @@ module.exports = { .setName("time") .setDescription("How long to ban this user?")), async execute(interaction) { - let member = interaction.options.getMember("user") + let member = await interaction.client.users.fetch(interaction.options.getMember("user")) let reason = interaction.options.getString("reason") - + const db = interaction.client.db.Bans if (!reason) reason = "No reason provided" if (interaction.options.getNumber("time") !== undefined) {let days = interaction.options.getNumber("time")} else {let days = null} - + if (member.bannable) await member.ban({ days: days, reason: reason }).then(console.log).catch(error => {console.error(error);interaction.reply({ content: 'There was an error while executing this command!', ephemeral: true });return}); - else if (!user.bannable) {interaction.reply("I can't ban this member");return} + else if (!member.bannable) {interaction.reply("I can't ban this member");return} if (reason === String) interaction.reply(`${user.tag} has been banned with the reason ${reason}`) else if (reason !== String) interaction.reply(`${user.tag} has been banned`) + db.create({ + reason: reason, + Executor: interaction.member.user.tag, + userID: user.id + }) }, }; \ No newline at end of file diff --git a/commands/warn.js b/commands/warn.js index d5d01cd..8466cbb 100644 --- a/commands/warn.js +++ b/commands/warn.js @@ -11,13 +11,20 @@ module.exports = { .setRequired(true)) .addStringOption(o => o .setName("reason") - .setDescription("Why should this user be warned?")), + .setDescription("Why should this user be warned?") + .setRequired(true)) +, async execute(interaction) { - const user = interaction.options.getUser("user") - const reason = interaction.options.getString("reason") - //interaction.reply({ content: "This command is not out yet!", ephemeral: true}) - interaction.reply({ content: `Warned ${user.tag}: ${reason}`}) - user.send(`You have been warned for: ${reason}`) + const user = interaction.options.getUser("user") + const reason = interaction.options.getString("reason") + const db = interaction.client.db.Warns + interaction.reply({ content: `Warned ${user.tag}: ${reason}`}) + user.send(`You have been warned for: ${reason}`) + db.create({ + reason: reason, + Executor: interaction.member.user.tag, + userID: user.id + }) //if (!reason) reason = "No reason provided" } } diff --git a/config.json.template b/config.json.template index dc01aed..bcfc624 100644 --- a/config.json.template +++ b/config.json.template @@ -1,5 +1,6 @@ { "token":"", "clientId":"", - "guildId":"" + "guildId":"", + "sqlPass":"" } \ No newline at end of file diff --git a/main.js b/main.js index 86073ca..b1c7067 100644 --- a/main.js +++ b/main.js @@ -1,10 +1,19 @@ const fs = require('node:fs'); const path = require('node:path'); +const Sequelize = require('sequelize') const { Client, Collection } = require('discord.js'); -const { token } = require('./config.json'); +const { token, sqlPass } = require('./config.json'); client = new Client({intents: 0}); +const sequelize = new Sequelize('database', 'user', sqlPass, { + host: 'localhost', + dialect: 'sqlite', + logging: false, + storage: 'database.sqlite', +}); +client.db = require('./Util/database') + client.commands = new Collection(); const commandsPath = path.join(__dirname, 'commands'); const commandFiles = fs.readdirSync(commandsPath).filter(file => file.endsWith('.js')); @@ -17,6 +26,8 @@ for (const file of commandFiles) { client.once('ready', () => { + client.db.Bans.sync() + client.db.Warns.sync() console.log(`Login as ${client.user.tag}`); })