From 51e90dee8ab7520e390a46eca708ca44596c0284 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Gro=C3=9F?= Date: Fri, 19 Aug 2022 14:14:24 +0200 Subject: [PATCH] Add helper function for bot settings and fix registration check always returning true --- events/interactionCreate.js | 5 ++++- migrations/20220817100736-create-bot.js | 4 ++-- models/bot.js | 6 ++++-- seeders/20220819111700-core-bot-config.js | 17 +++++++++++++++++ util/general.js | 9 +++++++++ 5 files changed, 36 insertions(+), 5 deletions(-) create mode 100644 seeders/20220819111700-core-bot-config.js create mode 100644 util/general.js diff --git a/events/interactionCreate.js b/events/interactionCreate.js index 7a5b1f0..e1e5ae0 100644 --- a/events/interactionCreate.js +++ b/events/interactionCreate.js @@ -7,8 +7,11 @@ const { UserUtils } = require("../util"); module.exports = { name: "interactionCreate", async execute (interaction) { - if (!UserUtils.registrationCheck(interaction)) return; + let isRegistered = await UserUtils.registrationCheck(interaction); + if (!isRegistered) return; + console.log("User is registered"); if (!interaction.isCommand()) return; + console.log("Interaction is a command"); const guild = await interaction.guild; //check if guild exists in database diff --git a/migrations/20220817100736-create-bot.js b/migrations/20220817100736-create-bot.js index fbf5a9e..2826a97 100644 --- a/migrations/20220817100736-create-bot.js +++ b/migrations/20220817100736-create-bot.js @@ -2,7 +2,7 @@ module.exports = { async up (queryInterface, Sequelize) { - await queryInterface.createTable('Bot', { + await queryInterface.createTable('Bots', { id: { allowNull: false, autoIncrement: true, @@ -31,6 +31,6 @@ module.exports = { }, async down (queryInterface, Sequelize) { - await queryInterface.dropTable('Bot'); + await queryInterface.dropTable('Bots'); } }; diff --git a/models/bot.js b/models/bot.js index b489f9a..e075d20 100644 --- a/models/bot.js +++ b/models/bot.js @@ -15,10 +15,12 @@ module.exports = (sequelize, DataTypes) => { } Bot.init({ maintenance: DataTypes.BOOLEAN, - adminIDs: DataTypes.STRING + adminIDs: DataTypes.STRING, + pullTimeout: DataTypes.INTEGER, + dropTimeout: DataTypes.INTEGER }, { sequelize, - modelName: 'Guild', + modelName: 'Bot', }); return Bot; }; \ No newline at end of file diff --git a/seeders/20220819111700-core-bot-config.js b/seeders/20220819111700-core-bot-config.js new file mode 100644 index 0000000..c05f696 --- /dev/null +++ b/seeders/20220819111700-core-bot-config.js @@ -0,0 +1,17 @@ +'use strict'; + +module.exports = { + async up (queryInterface, Sequelize) { + await queryInterface.bulkInsert('Bots', [{ + id: 1, + maintenance: 0, + adminIDs: '["222457277708369928"]', + pullTimeout: 300000, + dropTimeout: 900000 + }]); + }, + + async down (queryInterface, Sequelize) { + await queryInterface.bulkDelete('Bots', null, {}); + } +}; diff --git a/util/general.js b/util/general.js new file mode 100644 index 0000000..f9a218f --- /dev/null +++ b/util/general.js @@ -0,0 +1,9 @@ +const { Bot } = require("../models"); + +module.exports = { + name: "GeneralUtils", + getBotProperty: async function(property) { + let bot = await Bot.findOne(); + return property ? bot[property] : bot; + } +}