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 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) {
|
||||
|
@ -21,12 +21,31 @@ const {Connection} = require("mysql")
|
||||
|
||||
// Development dummy data
|
||||
const DevData = {
|
||||
"1049942781579247627": {
|
||||
"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) {
|
||||
|
16
index.js
16
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")
|
||||
})
|
||||
|
@ -4,7 +4,8 @@
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"start": "node ."
|
||||
"start": "node sharding",
|
||||
"test": "node ."
|
||||
},
|
||||
"author": "",
|
||||
"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