Refactored Database Connection, Fixed JSDocs, initial steps for MessageReaction Handling
This commit is contained in:
@ -1,7 +1,7 @@
|
|||||||
const sql = require('mysql');
|
const sql = require('mysql');
|
||||||
|
|
||||||
var Database = async (db) => {
|
const Database = async (db) => {
|
||||||
var server = sql.createConnection({
|
const server = sql.createConnection({
|
||||||
host : db.HOST,
|
host : db.HOST,
|
||||||
user : db.USER,
|
user : db.USER,
|
||||||
password : db.PASSWORD,
|
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}
|
module.exports = {HandleReaction}
|
16
index.js
16
index.js
@ -7,12 +7,10 @@ const bot = new Client({ intents: [GatewayIntentBits.Guilds] });
|
|||||||
bot.commands = new Collection();
|
bot.commands = new Collection();
|
||||||
const commands = [];
|
const commands = [];
|
||||||
|
|
||||||
const server = sql.createConnection({
|
const { HandleReaction } = require("./Commons/Services/Reaction");
|
||||||
host : process.env.HOST,
|
|
||||||
user : process.env.USER,
|
const Database = require("./Commons/Data/Database");
|
||||||
password : process.env.PASSWORD,
|
const server = Database(process.env)
|
||||||
database : process.env.DATABASE
|
|
||||||
});
|
|
||||||
|
|
||||||
server.connect(function(err) {
|
server.connect(function(err) {
|
||||||
if (err) {
|
if (err) {
|
||||||
@ -37,7 +35,7 @@ const rest = new REST({ version: '10' }).setToken(process.env.TOKEN);
|
|||||||
(async () => {
|
(async () => {
|
||||||
try {
|
try {
|
||||||
console.log('Started refreshing application (/) commands.');
|
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.');
|
console.log('Successfully reloaded application (/) commands.');
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
@ -52,6 +50,10 @@ bot.on(Events.InteractionCreate, async interaction => {
|
|||||||
|
|
||||||
// Handles Reactions
|
// Handles Reactions
|
||||||
bot.on(Events.MessageReactionAdd, async reaction => {
|
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)
|
bot.login(process.env.TOKEN)
|
Reference in New Issue
Block a user