final fix for possibly wrong .env values, structural changes to bot, bot supports sharding from now onwards
This commit is contained in:
@ -3,11 +3,11 @@ const sql = require('mysql');
|
|||||||
const Database = async (db) => {
|
const Database = async (db) => {
|
||||||
|
|
||||||
const server = sql.createConnection({
|
const server = sql.createConnection({
|
||||||
host : db.HOST,
|
host : db.DB_HOST,
|
||||||
user : db.USERNAME,
|
user : db.DB_USERNAME,
|
||||||
password : db.PASSWORD
|
password : db.DB_PASSWORD
|
||||||
,
|
,
|
||||||
database : db.DATABASE
|
database : db.DB_NAME
|
||||||
});
|
});
|
||||||
|
|
||||||
server.connect(function(err) {
|
server.connect(function(err) {
|
||||||
|
@ -21,10 +21,29 @@ const {Connection} = require("mysql")
|
|||||||
|
|
||||||
// Development dummy data
|
// Development dummy data
|
||||||
const DevData = {
|
const DevData = {
|
||||||
"1049942781579247627": {
|
"1056657249528987769": {
|
||||||
"👀":{
|
type: "reactionRole",
|
||||||
Role: "test",
|
reactions: {
|
||||||
Restriction: "AddOnly"
|
"👀":{
|
||||||
|
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
|
// Route Actions
|
||||||
switch (Action) {
|
switch (Action) {
|
||||||
case "add":
|
case "add":
|
||||||
console.log(DevData[message.id][reaction._emoji.name])
|
console.log(DevData[message.id].type)
|
||||||
break;
|
break;
|
||||||
case "remove":
|
case "remove":
|
||||||
|
// Reverses all actions
|
||||||
|
// at this point of development pointless to spend development time on
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}catch (e) {
|
}catch (e) {
|
||||||
|
16
index.js
16
index.js
@ -9,7 +9,6 @@ const bot = new Client({
|
|||||||
});
|
});
|
||||||
|
|
||||||
bot.commands = new Collection();
|
bot.commands = new Collection();
|
||||||
const commands = [];
|
|
||||||
|
|
||||||
const { HandleReaction } = require("./Commons/Services/Reaction");
|
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"));
|
const commandFiles = fs.readdirSync("./Commands/").filter((file) => file.endsWith(".js"));
|
||||||
for (const file of commandFiles) {
|
for (const file of commandFiles) {
|
||||||
const command = require(`./Commands/${file}`);
|
const command = require(`./Commands/${file}`);
|
||||||
console.log(command.CommandCreator())
|
|
||||||
bot.commands.set(command.name, command);
|
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 => {
|
bot.on(Events.InteractionCreate, async interaction => {
|
||||||
// TODO: Adde Rolebased Permission Tracking rather then relying on discord permission system
|
// TODO: Adde Rolebased Permission Tracking rather then relying on discord permission system
|
||||||
if (!interaction.isChatInputCommand()) return;
|
if (!interaction.isChatInputCommand()) return;
|
||||||
@ -54,6 +39,7 @@ bot.on(Events.MessageReactionAdd, async (reaction, user) => {
|
|||||||
HandleReaction(reaction, user, undefined, "add")
|
HandleReaction(reaction, user, undefined, "add")
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
bot.on(Events.MessageReactionRemove, async (reaction, user) => {
|
bot.on(Events.MessageReactionRemove, async (reaction, user) => {
|
||||||
HandleReaction(reaction, user, server, "remove")
|
HandleReaction(reaction, user, server, "remove")
|
||||||
})
|
})
|
||||||
|
@ -4,7 +4,8 @@
|
|||||||
"description": "",
|
"description": "",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "node ."
|
"start": "node sharding",
|
||||||
|
"test": "node ."
|
||||||
},
|
},
|
||||||
"author": "",
|
"author": "",
|
||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
|
42
sharding.js
Normal file
42
sharding.js
Normal file
@ -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();
|
Reference in New Issue
Block a user