Refactored Database Connection, Fixed JSDocs, initial steps for MessageReaction Handling
This commit is contained in:
@ -1,7 +1,7 @@
|
||||
const sql = require('mysql');
|
||||
|
||||
var Database = async (db) => {
|
||||
var server = sql.createConnection({
|
||||
const Database = async (db) => {
|
||||
const server = sql.createConnection({
|
||||
host : db.HOST,
|
||||
user : db.USER,
|
||||
password : db.PASSWORD,
|
||||
|
@ -1,4 +1,33 @@
|
||||
const HandleReaction = async (reaction, Database) => {
|
||||
const {MessageReaction, PartialMessageReaction, User} = require("discord.js")
|
||||
const {Connection} = require("mysql")
|
||||
|
||||
/**
|
||||
* handles reactions in both ways
|
||||
* @param {MessageReaction | PartialMessageReaction} reaction the message reaction
|
||||
* @param {User} user
|
||||
* @param {Connection} Database current databes instance
|
||||
* @param {string} Action string of current action happening
|
||||
*/
|
||||
const HandleReaction = async (reaction, user, database, Action) => {
|
||||
// Handle if reaction is partial and therefor might throw api errors
|
||||
if (reaction.partial()){
|
||||
try{
|
||||
// global values
|
||||
let react = await reaction.fetch()
|
||||
|
||||
// Route Actions
|
||||
switch (Action) {
|
||||
case "add":
|
||||
react.
|
||||
break;
|
||||
case "remove":
|
||||
break;
|
||||
}
|
||||
}catch (e) {
|
||||
console.log(e)
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {HandleReaction}
|
16
index.js
16
index.js
@ -7,12 +7,10 @@ const bot = new Client({ intents: [GatewayIntentBits.Guilds] });
|
||||
bot.commands = new Collection();
|
||||
const commands = [];
|
||||
|
||||
const server = sql.createConnection({
|
||||
host : process.env.HOST,
|
||||
user : process.env.USER,
|
||||
password : process.env.PASSWORD,
|
||||
database : process.env.DATABASE
|
||||
});
|
||||
const { HandleReaction } = require("./Commons/Services/Reaction");
|
||||
|
||||
const Database = require("./Commons/Data/Database");
|
||||
const server = Database(process.env)
|
||||
|
||||
server.connect(function(err) {
|
||||
if (err) {
|
||||
@ -37,7 +35,7 @@ const rest = new REST({ version: '10' }).setToken(process.env.TOKEN);
|
||||
(async () => {
|
||||
try {
|
||||
console.log('Started refreshing application (/) commands.');
|
||||
await rest.put(Routes.applicationCommands("1037320315186974771"), { body: commands });
|
||||
await rest.put(Routes.applicationCommands(process.env.APPID), { body: commands });
|
||||
console.log('Successfully reloaded application (/) commands.');
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
@ -52,6 +50,10 @@ bot.on(Events.InteractionCreate, async interaction => {
|
||||
|
||||
// Handles Reactions
|
||||
bot.on(Events.MessageReactionAdd, async reaction => {
|
||||
HandleReaction(reaction, Database, "add")
|
||||
})
|
||||
|
||||
bot.on(Events.MessageReactionRemove, reaction => {
|
||||
HandleReaction(reaction, async Database, "remove")
|
||||
})
|
||||
bot.login(process.env.TOKEN)
|
Reference in New Issue
Block a user