can now store users in database + database file

This commit is contained in:
2023-04-24 00:40:34 +02:00
parent 16dac26a2c
commit e428ce388c
9 changed files with 264 additions and 22 deletions

View File

@ -2,18 +2,28 @@ require("dotenv").config();
const { Client, GatewayIntentBits, Collection, REST, Routes, Events, Partials } = require('discord.js');
const fs = require('fs');
const sql = require('mysql');
const {CreateUser} = require('./Commons/Data/User')
const bot = new Client({
intents: [ GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages, GatewayIntentBits.GuildMessageReactions ],
intents: [ GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages, GatewayIntentBits.GuildMessageReactions, GatewayIntentBits.GuildMembers ],
partials: [Partials.Message, Partials.Channel, Partials.Reaction],
});
bot.commands = new Collection();
const { HandleReaction } = require("./Commons/Services/Reaction");
const server = sql.createConnection({
host : process.env.DB_HOST,
user : process.env.DB_USERNAME,
password : process.env.DB_PASSWORD,
database : process.env.DB_NAME
});
const Database = require("./Commons/Data/Database");
const server = Database(process.env)
server.connect(function(err) {
if (err) {
console.error('error connecting Database in Data.Database: ' + err.stack);
process.exit(1)
}
});
/* ===============
* File Import *
@ -24,6 +34,11 @@ for (const file of commandFiles) {
bot.commands.set(command.name, command);
}
bot.on(Events.GuildMemberAdd, async user => {
console.log(`new user found`, user.guild.id.toString(), user.user.id.toString(), user.user.username, false)
await CreateUser(server, user.guild.id.toString(), user.user.id.toString(), user.user.username, false);
})
bot.on(Events.InteractionCreate, async interaction => {
// TODO: Adde Rolebased Permission Tracking rather then relying on discord permission system
if (!interaction.isChatInputCommand()) return;
@ -37,7 +52,6 @@ bot.on(Events.MessageReactionAdd, async (reaction, user) => {
HandleReaction(reaction, user, undefined, "add", bot)
})
bot.on(Events.MessageReactionRemove, async (reaction, user) => {
if (user.bot) return;
HandleReaction(reaction, user, server, "remove", bot)