diff --git a/Commons/Data/Database.js b/Commons/Data/Database.js index 213f39b..6a405c3 100644 --- a/Commons/Data/Database.js +++ b/Commons/Data/Database.js @@ -3,11 +3,11 @@ const sql = require('mysql'); const Database = async (db) => { const server = sql.createConnection({ - host : db.HOST, - user : db.USERNAME, - password : db.PASSWORD + host : db.DB_HOST, + user : db.DB_USERNAME, + password : db.DB_PASSWORD , - database : db.DATABASE + database : db.DB_NAME }); server.connect(function(err) { diff --git a/Commons/Services/Reaction.js b/Commons/Services/Reaction.js index d49981e..a10b2a6 100644 --- a/Commons/Services/Reaction.js +++ b/Commons/Services/Reaction.js @@ -21,10 +21,29 @@ const {Connection} = require("mysql") // Development dummy data const DevData = { - "1049942781579247627": { - "👀":{ - Role: "test", - Restriction: "AddOnly" + "1056657249528987769": { + type: "reactionRole", + reactions: { + "👀":{ + Action: "role", + Role: "test", + Restriction: "AddOnly" + } + } + }, + "1056657695207329823": { + type: "vote", + reactions: { + "✅":{ + Action: "vote-yes", + Role: "null", + Restriction: "null" + }, + "🚫":{ + Action: "vote-no", + Role: "null", + Restriction: "null" + } } } } @@ -46,9 +65,11 @@ const HandleReaction = async (reaction, user, database, Action) => { // Route Actions switch (Action) { case "add": - console.log(DevData[message.id][reaction._emoji.name]) + console.log(DevData[message.id].type) break; case "remove": + // Reverses all actions + // at this point of development pointless to spend development time on break; } }catch (e) { diff --git a/index.js b/index.js index 88f99d2..35dadf2 100644 --- a/index.js +++ b/index.js @@ -9,7 +9,6 @@ const bot = new Client({ }); bot.commands = new Collection(); -const commands = []; const { HandleReaction } = require("./Commons/Services/Reaction"); @@ -22,23 +21,9 @@ const server = Database(process.env) const commandFiles = fs.readdirSync("./Commands/").filter((file) => file.endsWith(".js")); for (const file of commandFiles) { const command = require(`./Commands/${file}`); - console.log(command.CommandCreator()) bot.commands.set(command.name, command); - commands.push(command.CommandCreator()); } -console.log(commands) -const rest = new REST({ version: '10' }).setToken(process.env.TOKEN); -(async () => { - try { - console.log('Started refreshing application (/) commands.'); - await rest.put(Routes.applicationCommands(process.env.APPID), { body: commands }); - console.log('Successfully reloaded application (/) commands.'); - } catch (error) { - console.error(error); - } -})(); - bot.on(Events.InteractionCreate, async interaction => { // TODO: Adde Rolebased Permission Tracking rather then relying on discord permission system if (!interaction.isChatInputCommand()) return; @@ -54,6 +39,7 @@ bot.on(Events.MessageReactionAdd, async (reaction, user) => { HandleReaction(reaction, user, undefined, "add") }) + bot.on(Events.MessageReactionRemove, async (reaction, user) => { HandleReaction(reaction, user, server, "remove") }) diff --git a/package.json b/package.json index 5995921..2dc1cc3 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,8 @@ "description": "", "main": "index.js", "scripts": { - "start": "node ." + "start": "node sharding", + "test": "node ." }, "author": "", "license": "ISC", diff --git a/sharding.js b/sharding.js new file mode 100644 index 0000000..e878dbe --- /dev/null +++ b/sharding.js @@ -0,0 +1,42 @@ +// Include discord.js ShardingMana +const { ShardingManager, REST, Routes, Events } = require('discord.js'); +const fs = require('fs'); + +require("dotenv").config(); +const commands = []; + +// Create your ShardingManager instance +const manager = new ShardingManager("./index.js", { + // for ShardingManager options see: + // https://discord.js.org/#/docs/main/stable/class/ShardingManager + totalShards: "auto", + token: process.env.TOKEN +}); + +/* =============== +* File Import * +=============== */ +const commandFiles = fs.readdirSync("./Commands/").filter((file) => file.endsWith(".js")); +for (const file of commandFiles) { + const command = require(`./Commands/${file}`); + console.log(command.CommandCreator()) + commands.push(command.CommandCreator()); +} + +console.log(commands) +const rest = new REST({ version: '10' }).setToken(process.env.TOKEN); +(async () => { + try { + console.log('Started refreshing application (/) commands.'); + await rest.put(Routes.applicationCommands(process.env.APPID), { body: commands }); + console.log('Successfully reloaded application (/) commands.'); + } catch (error) { + console.error(error); + } +})(); + +// Emitted when a shard is created +manager.on("shardCreate", shard => console.log(`Shard ${shard.id} launched`)); + +// Spawn your shards +manager.spawn(); \ No newline at end of file