Compare commits
2 Commits
1f504ae0c4
...
91bffb65c7
Author | SHA1 | Date |
---|---|---|
baz | 91bffb65c7 | |
baz | 7d4ca51aa4 |
|
@ -1,5 +1,5 @@
|
|||
const { SlashCommandBuilder } = require('discord.js');
|
||||
const { Users } = require ('../../dbObjects.js');
|
||||
const { checkUserRegistration } = require('../../databaseHelperFunctions.js');
|
||||
|
||||
module.exports = {
|
||||
data: new SlashCommandBuilder()
|
||||
|
@ -10,16 +10,8 @@ module.exports = {
|
|||
// 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
|
||||
|
||||
const user = await Users.findOne({ where: { discord_id: interaction.user.id } })
|
||||
.catch((err) => {
|
||||
console.log(err);
|
||||
});
|
||||
if (user) return interaction.reply(`User "${interaction.user.username}" is already registered`);
|
||||
if (checkUserRegistration(interaction.user)) return interaction.reply(`User "${interaction.user.username}" is registered`);
|
||||
|
||||
await Users.create({ discord_id: interaction.user.id, username: interaction.user.username })
|
||||
.then(await interaction.reply(`${interaction.user.username} was manually registered.`))
|
||||
.catch((err) => {
|
||||
console.log(err);
|
||||
});
|
||||
return interaction.reply(`Issue checking registration with "${interaction.user.username}".`);
|
||||
},
|
||||
};
|
|
@ -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,
|
||||
};
|
|
@ -14,7 +14,6 @@ require('./models/beatenGames.js')(sequelize, Sequelize.DataTypes);
|
|||
const force = process.argv.includes('--force') || process.argv.includes('-f');
|
||||
|
||||
sequelize.sync({ force }).then(async () => {
|
||||
// await Promise.all();
|
||||
console.log('Database synced');
|
||||
sequelize.close();
|
||||
}).catch(console.error);
|
||||
|
|
Loading…
Reference in New Issue