From f3d151a9cab4d6795eba5d5c84fb2d932ab8e8cd Mon Sep 17 00:00:00 2001 From: luihum <23081124+luihum@users.noreply.github.com> Date: Sun, 22 May 2022 10:47:04 -0300 Subject: [PATCH 1/8] base Sequelize code --- .gitignore | 3 ++- Util/{Models sequalize.js => database.js} | 18 +++++++++++++++--- config.json.template | 3 ++- main.js | 13 ++++++++++++- 4 files changed, 31 insertions(+), 6 deletions(-) rename Util/{Models sequalize.js => database.js} (54%) 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/database.js similarity index 54% rename from Util/Models sequalize.js rename to Util/database.js index 0975269..2b64988 100644 --- a/Util/Models sequalize.js +++ b/Util/database.js @@ -7,17 +7,29 @@ const sequelize = new Sequelize('database', 'user', 'password', { storage: 'database.sqlite' }) -const Ban = sequelize.define('ban', { +const Bans = sequelize.define('bans', { userID:{ type: Sequelize.NUMBER, }, - raison: { + reason: { type: Sequelize.TEXT, - defaultValue: "No raison provided" + 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 }); \ No newline at end of file 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}`); }) From cf7aac4fe3b8a3d823e38fc484020cf6164ba85e Mon Sep 17 00:00:00 2001 From: luihum <23081124+luihum@users.noreply.github.com> Date: Sun, 22 May 2022 11:24:57 -0300 Subject: [PATCH 2/8] database stuff --- Util/database.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Util/database.js b/Util/database.js index 2b64988..24a02ad 100644 --- a/Util/database.js +++ b/Util/database.js @@ -32,4 +32,6 @@ const Warns = sequelize.define('warns', { }, Executor: Sequelize.STRING, ID: Sequelize.NUMBER -}); \ No newline at end of file +}); + +module.exports = { Bans, Warns } \ No newline at end of file From 4d90ff3f769665e412fdc93dafb6ac183a78dc27 Mon Sep 17 00:00:00 2001 From: luihum <23081124+luihum@users.noreply.github.com> Date: Sun, 22 May 2022 11:25:38 -0300 Subject: [PATCH 3/8] test warn command --- commands/warn.js | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/commands/warn.js b/commands/warn.js index d5d01cd..0e859e5 100644 --- a/commands/warn.js +++ b/commands/warn.js @@ -11,13 +11,21 @@ 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, + ID: 6969, + Executor: interaction.member.user.tag, + userID: user.id + }) //if (!reason) reason = "No reason provided" } } From 44161c460500680a12ff03a07c9cf89489d99f2e Mon Sep 17 00:00:00 2001 From: luihum <23081124+luihum@users.noreply.github.com> Date: Sun, 22 May 2022 11:30:46 -0300 Subject: [PATCH 4/8] oops --- Util/database.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Util/database.js b/Util/database.js index 24a02ad..aeabc9d 100644 --- a/Util/database.js +++ b/Util/database.js @@ -30,8 +30,8 @@ const Warns = sequelize.define('warns', { type: Sequelize.TEXT, defaultValue: "No reason provided" }, - Executor: Sequelize.STRING, - ID: Sequelize.NUMBER + Executor: Sequelize.STRING//, + // ID: Sequelize.NUMBER }); module.exports = { Bans, Warns } \ No newline at end of file From 6fa9a1299039fb0beb5d7df71ed9621c66f0173d Mon Sep 17 00:00:00 2001 From: luihum <23081124+luihum@users.noreply.github.com> Date: Sun, 22 May 2022 11:34:51 -0300 Subject: [PATCH 5/8] oops 2 electric boogaloo --- Util/database.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Util/database.js b/Util/database.js index aeabc9d..c102373 100644 --- a/Util/database.js +++ b/Util/database.js @@ -18,8 +18,8 @@ const Bans = sequelize.define('bans', { Executor: Sequelize.STRING, type: { type: Sequelize.STRING, - }, - ID: Sequelize.NUMBER + }//, + //ID: Sequelize.NUMBER }); const Warns = sequelize.define('warns', { From 3dcbdfc7afab237e92a675c869b4a634c56a4ce0 Mon Sep 17 00:00:00 2001 From: luihum <23081124+luihum@users.noreply.github.com> Date: Sun, 22 May 2022 12:00:18 -0300 Subject: [PATCH 6/8] ban database + small fix --- commands/ban.js | 7 ++++++- commands/warn.js | 1 - 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/commands/ban.js b/commands/ban.js index b04147b..88f9879 100644 --- a/commands/ban.js +++ b/commands/ban.js @@ -17,7 +17,7 @@ module.exports = { async execute(interaction) { let member = 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")} @@ -28,5 +28,10 @@ module.exports = { else if (!user.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 0e859e5..8466cbb 100644 --- a/commands/warn.js +++ b/commands/warn.js @@ -22,7 +22,6 @@ module.exports = { user.send(`You have been warned for: ${reason}`) db.create({ reason: reason, - ID: 6969, Executor: interaction.member.user.tag, userID: user.id }) From 8a43211207740670eafdf1c6e843e6b3c72c225d Mon Sep 17 00:00:00 2001 From: luihum <23081124+luihum@users.noreply.github.com> Date: Mon, 23 May 2022 08:07:34 -0300 Subject: [PATCH 7/8] fixed cache errors --- commands/ban.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/commands/ban.js b/commands/ban.js index 88f9879..2f9a2cd 100644 --- a/commands/ban.js +++ b/commands/ban.js @@ -15,14 +15,14 @@ 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} From ffb4bd01176fc23a3f7520e983a1341fe32a7430 Mon Sep 17 00:00:00 2001 From: luihum <23081124+luihum@users.noreply.github.com> Date: Mon, 23 May 2022 08:10:44 -0300 Subject: [PATCH 8/8] fixed ban command --- commands/ban.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/commands/ban.js b/commands/ban.js index 2f9a2cd..8d877c0 100644 --- a/commands/ban.js +++ b/commands/ban.js @@ -25,7 +25,7 @@ module.exports = { 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({