Compare commits

...

2 Commits

Author SHA1 Message Date
baz 91bffb65c7 Move user user existance checking to databaseHelperFunctions file 2023-12-18 22:49:33 +00:00
baz 7d4ca51aa4 Remove comment 2023-12-18 22:49:02 +00:00
3 changed files with 31 additions and 12 deletions

View File

@ -1,5 +1,5 @@
const { SlashCommandBuilder } = require('discord.js'); const { SlashCommandBuilder } = require('discord.js');
const { Users } = require ('../../dbObjects.js'); const { checkUserRegistration } = require('../../databaseHelperFunctions.js');
module.exports = { module.exports = {
data: new SlashCommandBuilder() data: new SlashCommandBuilder()
@ -10,16 +10,8 @@ module.exports = {
// interaction.user is the object representing the user who ran the command // interaction.user is the object representing the user who ran the command
// interaction.member is the GuildMember object, which represents the user in the specific guild // interaction.member is the GuildMember object, which represents the user in the specific guild
const user = await Users.findOne({ where: { discord_id: interaction.user.id } }) if (checkUserRegistration(interaction.user)) return interaction.reply(`User "${interaction.user.username}" is registered`);
.catch((err) => {
console.log(err);
});
if (user) return interaction.reply(`User "${interaction.user.username}" is already registered`);
await Users.create({ discord_id: interaction.user.id, username: interaction.user.username }) return interaction.reply(`Issue checking registration with "${interaction.user.username}".`);
.then(await interaction.reply(`${interaction.user.username} was manually registered.`))
.catch((err) => {
console.log(err);
});
}, },
}; };

View File

@ -0,0 +1,28 @@
const { SlashCommandBuilder } = require('discord.js');
const { Users } = require ('./dbObjects.js');
async function checkUserRegistration(user) {
let u = await Users.findOne({ where: { discord_id: user.id } })
.catch((err) => {
console.log(err);
});
if (u) return true;
await Users.create({ discord_id: user.id, username: user.username })
.then((data) => {
u = data;
})
.catch((err) => {
console.log(err);
});
if (u) return true;
return false;
}
module.exports = {
checkUserRegistration,
};

View File

@ -14,7 +14,6 @@ require('./models/beatenGames.js')(sequelize, Sequelize.DataTypes);
const force = process.argv.includes('--force') || process.argv.includes('-f'); const force = process.argv.includes('--force') || process.argv.includes('-f');
sequelize.sync({ force }).then(async () => { sequelize.sync({ force }).then(async () => {
// await Promise.all();
console.log('Database synced'); console.log('Database synced');
sequelize.close(); sequelize.close();
}).catch(console.error); }).catch(console.error);