Compare commits
4 Commits
e2d3881cce
...
1f504ae0c4
Author | SHA1 | Date |
---|---|---|
baz | 1f504ae0c4 | |
baz | 590ca18f18 | |
baz | 2e4e68a82b | |
baz | 7c27191202 |
|
@ -0,0 +1,25 @@
|
|||
const { SlashCommandBuilder } = require('discord.js');
|
||||
const { Users } = require ('../../dbObjects.js');
|
||||
|
||||
module.exports = {
|
||||
data: new SlashCommandBuilder()
|
||||
.setName('register')
|
||||
.setDescription('Manually registers the user into the user database.'),
|
||||
|
||||
async execute(interaction) {
|
||||
// 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`);
|
||||
|
||||
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);
|
||||
});
|
||||
},
|
||||
};
|
|
@ -9,7 +9,7 @@ const sequelize = new Sequelize('database', 'username', 'password', {
|
|||
|
||||
const db = require('./models/games.js')(sequelize, Sequelize.DataTypes);
|
||||
require('./models/users.js')(sequelize, Sequelize.DataTypes);
|
||||
require('models/beatenGames.js')(sequelize, Sequelize.DataTypes);
|
||||
require('./models/beatenGames.js')(sequelize, Sequelize.DataTypes);
|
||||
|
||||
const force = process.argv.includes('--force') || process.argv.includes('-f');
|
||||
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
const Sequelize = require('sequelize');
|
||||
|
||||
const sequelize = new Sequelize('database', 'username', 'password', {
|
||||
host: 'localhost',
|
||||
dialect: 'sqlite',
|
||||
logging: false,
|
||||
storage: 'database.sqlite',
|
||||
});
|
||||
|
||||
const Users = require('./models/users.js')(sequelize, Sequelize.DataTypes);
|
||||
const Games = require('./models/games.js')(sequelize, Sequelize.DataTypes);
|
||||
const BeatenGames = require('./models/beatenGames.js')(sequelize, Sequelize.DataTypes);
|
||||
|
||||
// Create userId foreignKey
|
||||
Users.hasMany(BeatenGames);
|
||||
BeatenGames.belongsTo(Users);
|
||||
|
||||
// Create gameId foreignKey
|
||||
Games.hasMany(BeatenGames);
|
||||
BeatenGames.belongsTo(Games);
|
||||
|
||||
module.exports = { Users, Games, BeatenGames };
|
29
index.js
29
index.js
|
@ -50,30 +50,9 @@ for (const file of eventFiles) {
|
|||
|
||||
client.login(process.env.token);
|
||||
|
||||
const { Sequelize } = require('sequelize');
|
||||
|
||||
const sequelize = new Sequelize('database', 'user', 'password', {
|
||||
host: 'localhost',
|
||||
dialect: 'sqlite',
|
||||
logging: false,
|
||||
storage: 'database.sqlite',
|
||||
});
|
||||
|
||||
const Tags = sequelize.define('tags', {
|
||||
name: {
|
||||
type: Sequelize.STRING,
|
||||
unique: true,
|
||||
},
|
||||
description: Sequelize.TEXT,
|
||||
username: Sequelize.STRING,
|
||||
usage_count: {
|
||||
type: Sequelize.INTEGER,
|
||||
defaultValue: 0,
|
||||
allowNull: false,
|
||||
},
|
||||
});
|
||||
|
||||
client.once(Events.ClientReady, () => {
|
||||
Tags.sync({ force: true });
|
||||
console.log(`Logged in as ${client.user.tag}!`);
|
||||
});
|
||||
});
|
||||
|
||||
require('sequelize');
|
||||
require('./dbObjects.js');
|
|
@ -1,16 +1,7 @@
|
|||
module.exports = (sequelize, DataTypes) => {
|
||||
return sequelize.define('beatenGames', {
|
||||
id: {
|
||||
type: DataTypes.INTEGER,
|
||||
primaryKey: true,
|
||||
autoIncrement: true,
|
||||
},
|
||||
user_id: DataTypes.INTEGER,
|
||||
game_id: DataTypes.STRING,
|
||||
date_created: DataTypes.DATE,
|
||||
date_last_modified: DataTypes.DATE,
|
||||
}, {
|
||||
timestamps: false,
|
||||
timestamps: true,
|
||||
});
|
||||
};
|
||||
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
module.exports = (sequelize, DataTypes) => {
|
||||
return sequelize.define('games', {
|
||||
id: {
|
||||
igdb_id: {
|
||||
type: DataTypes.INTEGER,
|
||||
primaryKey: true,
|
||||
},
|
||||
name: {
|
||||
type: DataTypes.STRING,
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
module.exports = (sequelize, DataTypes) => {
|
||||
return sequelize.define('users', {
|
||||
user_id: {
|
||||
discord_id: {
|
||||
type: DataTypes.STRING,
|
||||
primaryKey: true,
|
||||
},
|
||||
username: {
|
||||
type: DataTypes.STRING,
|
||||
|
|
Loading…
Reference in New Issue