diff --git a/Commons/Data/Database.js b/Commons/Data/Database.js index d1fd406..d0c2476 100644 --- a/Commons/Data/Database.js +++ b/Commons/Data/Database.js @@ -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, diff --git a/Commons/Services/Reaction.js b/Commons/Services/Reaction.js index 26c3406..bebe5ba 100644 --- a/Commons/Services/Reaction.js +++ b/Commons/Services/Reaction.js @@ -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} \ No newline at end of file diff --git a/index.js b/index.js index 905c9e6..4739ea9 100644 --- a/index.js +++ b/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) \ No newline at end of file