Compare commits
No commits in common. "1f504ae0c449b848f51c37f4739df88767539585" and "e2d3881cce22d10d86893cf6b4195d84dda9724c" have entirely different histories.
1f504ae0c4
...
e2d3881cce
|
@ -1,25 +0,0 @@
|
|||
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');
|
||||
|
||||
|
|
22
dbObjects.js
22
dbObjects.js
|
@ -1,22 +0,0 @@
|
|||
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,9 +50,30 @@ for (const file of eventFiles) {
|
|||
|
||||
client.login(process.env.token);
|
||||
|
||||
client.once(Events.ClientReady, () => {
|
||||
console.log(`Logged in as ${client.user.tag}!`);
|
||||
const { Sequelize } = require('sequelize');
|
||||
|
||||
const sequelize = new Sequelize('database', 'user', 'password', {
|
||||
host: 'localhost',
|
||||
dialect: 'sqlite',
|
||||
logging: false,
|
||||
storage: 'database.sqlite',
|
||||
});
|
||||
|
||||
require('sequelize');
|
||||
require('./dbObjects.js');
|
||||
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}!`);
|
||||
});
|
|
@ -1,7 +1,16 @@
|
|||
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: true,
|
||||
timestamps: false,
|
||||
});
|
||||
};
|
||||
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
module.exports = (sequelize, DataTypes) => {
|
||||
return sequelize.define('games', {
|
||||
igdb_id: {
|
||||
id: {
|
||||
type: DataTypes.INTEGER,
|
||||
primaryKey: true,
|
||||
},
|
||||
name: {
|
||||
type: DataTypes.STRING,
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
module.exports = (sequelize, DataTypes) => {
|
||||
return sequelize.define('users', {
|
||||
discord_id: {
|
||||
user_id: {
|
||||
type: DataTypes.STRING,
|
||||
primaryKey: true,
|
||||
},
|
||||
username: {
|
||||
type: DataTypes.STRING,
|
||||
|
|
Loading…
Reference in New Issue