mirror of
https://github.com/Art-Portal/April.git
synced 2025-01-27 13:23:54 +01:00
Move the database loading part into functions.js
This commit is contained in:
parent
04fc7a9136
commit
515b012019
50
functions.js
50
functions.js
@ -1,9 +1,10 @@
|
||||
const { REST } = require('@discordjs/rest');
|
||||
const { Routes } = require('discord-api-types/v10');
|
||||
const { token, clientId, guildId } = require('./config.json');
|
||||
const { token, clientId, guildId, sequelizeCredentials } = require('./config.json');
|
||||
const { Collection, SlashCommandBuilder } = require('discord.js');
|
||||
const fs = require('fs');
|
||||
const rest = new REST({ version: '10' }).setToken(token);
|
||||
const Sequelize = require('sequelize');
|
||||
|
||||
|
||||
|
||||
@ -36,6 +37,7 @@ function deploy_commands(client, loadcommands) {
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
async function slashCommandLoad(client, commands) {
|
||||
try {
|
||||
console.log('Je commence à actualiser les commandes slash.');
|
||||
@ -50,4 +52,48 @@ async function slashCommandLoad(client, commands) {
|
||||
return client.commands;
|
||||
};
|
||||
|
||||
module.exports = { deploy_commands }
|
||||
|
||||
function loadDatabase(client) {
|
||||
const sequelize = new Sequelize('database', sequelizeCredentials.username, sequelizeCredentials.password, {
|
||||
host: 'localhost',
|
||||
dialect: 'sqlite',
|
||||
logging: false,
|
||||
storage: 'database.sqlite',
|
||||
});
|
||||
const blacklistdb = sequelize.define('blacklist', {
|
||||
name: {//id
|
||||
type: Sequelize.STRING,
|
||||
unique: true,
|
||||
},
|
||||
username: Sequelize.STRING,
|
||||
reason: Sequelize.TEXT,
|
||||
timestamp: Sequelize.STRING,
|
||||
moderatorid: Sequelize.STRING
|
||||
});
|
||||
|
||||
const modlog = sequelize.define('sanctions', {
|
||||
name: Sequelize.STRING,//id
|
||||
username: Sequelize.STRING,
|
||||
type: Sequelize.STRING,
|
||||
reason: Sequelize.TEXT,
|
||||
timestamp: Sequelize.STRING,
|
||||
moderatorid: Sequelize.STRING
|
||||
});
|
||||
|
||||
const artists = sequelize.define('artists', {
|
||||
name: Sequelize.STRING,//id
|
||||
emoji: Sequelize.STRING,
|
||||
});
|
||||
|
||||
client.database = {
|
||||
sequelize: sequelize,
|
||||
modlog: modlog,
|
||||
blacklistdb: blacklistdb,
|
||||
artists: artists,
|
||||
};
|
||||
blacklistdb.sync();
|
||||
modlog.sync();
|
||||
artists.sync();
|
||||
}
|
||||
|
||||
module.exports = { deploy_commands, loadDatabase }
|
||||
|
46
index.js
46
index.js
@ -1,8 +1,7 @@
|
||||
const fs = require('fs');
|
||||
const Sequelize = require('sequelize');
|
||||
const { Client, GatewayIntentBits } = require("discord.js");
|
||||
const { token, sequelizeCredentials } = require('./config.json');
|
||||
const { deploy_commands } = require('./functions.js');
|
||||
const { token } = require('./config.json');
|
||||
const { deploy_commands, loadDatabase } = require('./functions.js');
|
||||
|
||||
const client = new Client({
|
||||
intents: [
|
||||
@ -13,46 +12,7 @@ const client = new Client({
|
||||
]
|
||||
});
|
||||
|
||||
const sequelize = new Sequelize('database', sequelizeCredentials.username, sequelizeCredentials.password, {
|
||||
host: 'localhost',
|
||||
dialect: 'sqlite',
|
||||
logging: false,
|
||||
storage: 'database.sqlite',
|
||||
});
|
||||
const blacklistdb = sequelize.define('blacklist', {
|
||||
name: {//id
|
||||
type: Sequelize.STRING,
|
||||
unique: true,
|
||||
},
|
||||
username: Sequelize.STRING,
|
||||
reason: Sequelize.TEXT,
|
||||
timestamp: Sequelize.STRING,
|
||||
moderatorid: Sequelize.STRING
|
||||
});
|
||||
|
||||
const modlog = sequelize.define('sanctions', {
|
||||
name: Sequelize.STRING,//id
|
||||
username: Sequelize.STRING,
|
||||
type: Sequelize.STRING,
|
||||
reason: Sequelize.TEXT,
|
||||
timestamp: Sequelize.STRING,
|
||||
moderatorid: Sequelize.STRING
|
||||
});
|
||||
|
||||
const artists = sequelize.define('artists', {
|
||||
name: Sequelize.STRING,//id
|
||||
emoji: Sequelize.STRING,
|
||||
});
|
||||
|
||||
client.database = {
|
||||
sequelize: sequelize,
|
||||
modlog: modlog,
|
||||
blacklistdb: blacklistdb,
|
||||
artists: artists,
|
||||
};
|
||||
blacklistdb.sync();
|
||||
modlog.sync();
|
||||
artists.sync();
|
||||
loadDatabase(client)
|
||||
|
||||
const eventFiles = fs.readdirSync('./events').filter(file => file.endsWith('.js'));
|
||||
for (const file of eventFiles) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user