diff --git a/.eslintrc.json b/.eslintrc.json new file mode 100644 index 0000000..e2056c4 --- /dev/null +++ b/.eslintrc.json @@ -0,0 +1,45 @@ +{ + "extends": "eslint:recommended", + "env": { + "node": true, + "es6": true + }, + "parserOptions": { + "ecmaVersion": 2019 + }, + "rules": { + "brace-style": ["error", "stroustrup", { "allowSingleLine": true }], + "comma-dangle": ["error", "always-multiline"], + "comma-spacing": "error", + "comma-style": "error", + "curly": ["error", "multi-line", "consistent"], + "dot-location": ["error", "property"], + "handle-callback-err": "off", + "indent": ["error", "tab"], + "no-console": "off", + "no-empty-function": "error", + "no-floating-decimal": "error", + "no-inline-comments": "error", + "no-lonely-if": "error", + "no-multi-spaces": "error", + "no-multiple-empty-lines": ["error", { "max": 2, "maxEOF": 1, "maxBOF": 0 }], + "no-shadow": ["error", { "allow": ["err", "resolve", "reject"] }], + "no-trailing-spaces": ["error"], + "no-var": "error", + "object-curly-spacing": ["error", "always"], + "prefer-const": "error", + "quotes": ["error", "single"], + "semi": ["error", "always"], + "space-before-blocks": "error", + "space-before-function-paren": ["error", { + "anonymous": "never", + "named": "never", + "asyncArrow": "always" + }], + "space-in-parens": "error", + "space-infix-ops": "error", + "space-unary-ops": "error", + "spaced-comment": "error", + "yoda": "error" + } +} \ No newline at end of file diff --git a/commands/credentials.js b/commands/credentials.js index 44195a1..ae4280b 100644 --- a/commands/credentials.js +++ b/commands/credentials.js @@ -1,49 +1,42 @@ -exports.run = (client, message, args) => { - const Discord = require("discord.js"); - const mysql = require('mysql') +exports.run = (client, message) => { + const Discord = require('discord.js'); + const con = require('../utils/dbConnector'); -const con = mysql.createConnection({ - connectionLimit: 20, - host: client.config.mysqlHOST, - port: "3306", - user: client.config.mysqlUSER, - password: client.config.mysqlPASS, - database: client.config.mysqlDB, -}); - -var userid = message.author.id; -con.query(`SELECT * FROM users WHERE discord_id = '${userid}'`, function (err, result, fields) { -let noCon = new Discord.MessageEmbed() - .setAuthor("CloudServer ¦ Credentials", client.user.avatarURL()) - .setColor("FF0009") - .setFooter(`💕CloudServer Alpha | CodeCannibals\nRequested By ➤ ${message.author.tag}`, client.user.avatarURL()) - .setDescription("```There was an error connecting to the database. Please report this issue to a member of the staffteam```") + const userid = message.author.id; + con.query(`SELECT * FROM users WHERE discord_id = '${userid}'`, (err, result) => { -if (err) return message.channel.send(noCon); - -if (result.length == 0) { - let noReg = new Discord.MessageEmbed() - .setAuthor("CloudServer ¦ Credentials", client.user.avatarURL()) - .setColor("FF0009") - .setFooter(`💕CloudServer Alpha | CodeCannibals\nRequested By ➤ ${message.author.tag}`, client.user.avatarURL()) - .setDescription("```You are not a registered user. Please register yourself with "+client.config.prefix+"register to unlock this command```") - message.channel.send(noReg); -} else { - var Database = JSON.parse(JSON.stringify(result[0])); - let sent = new Discord.MessageEmbed() - .setAuthor("CloudServer ¦ Credentials", client.user.avatarURL()) - .setColor("DE4BFF") - .setFooter(`💕CloudServer Alpha | CodeCannibals\nRequested By ➤ ${message.author.tag}`, client.user.avatarURL()) - .setDescription("```Your credentials has been sent to you```") - message.channel.send(sent); - - let embed = new Discord.MessageEmbed() - .setAuthor("CloudServer ¦ Credentials", client.user.avatarURL()) - .setColor("DE4BFF") - .setFooter(`💕CloudServer Alpha | CodeCannibals\nRequested By ➤ ${message.author.tag}`, client.user.avatarURL()) - .setDescription("**__User Credentials For CloudServer__**```Email: "+Database.email+"\nUsername: "+Database.pterodactyl_username+"\nPassword: "+Database.pterodactyl_password+"```") - message.author.send(embed); -} - }); -} + const noCon = new Discord.MessageEmbed() + .setAuthor('CloudServer ¦ Credentials', client.user.avatarURL()) + .setColor('FF0009') + .setFooter(`💕CloudServer Alpha | CodeCannibals\nRequested By ➤ ${message.author.tag}`, client.user.avatarURL()) + .setDescription('```There was an error connecting to the database. Please report this issue to a member of the staffteam```'); + + if (err) return message.channel.send(noCon); + + if (result.length == 0) { + const noReg = new Discord.MessageEmbed() + .setAuthor('CloudServer ¦ Credentials', client.user.avatarURL()) + .setColor('FF0009') + .setFooter(`💕CloudServer Alpha | CodeCannibals\nRequested By ➤ ${message.author.tag}`, client.user.avatarURL()) + .setDescription('```You are not a registered user. Please register yourself with ' + client.config.prefix + 'register to unlock this command```'); + message.channel.send(noReg); + } + else { + const Database = JSON.parse(JSON.stringify(result[0])); + const sent = new Discord.MessageEmbed() + .setAuthor('CloudServer ¦ Credentials', client.user.avatarURL()) + .setColor('DE4BFF') + .setFooter(`💕CloudServer Alpha | CodeCannibals\nRequested By ➤ ${message.author.tag}`, client.user.avatarURL()) + .setDescription('```Your credentials has been sent to you```'); + message.channel.send(sent); + + const embed = new Discord.MessageEmbed() + .setAuthor('CloudServer ¦ Credentials', client.user.avatarURL()) + .setColor('DE4BFF') + .setFooter(`💕CloudServer Alpha | CodeCannibals\nRequested By ➤ ${message.author.tag}`, client.user.avatarURL()) + .setDescription('**__User Credentials For CloudServer__**```Email: ' + Database.email + '\nUsername: ' + Database.pterodactyl_username + '\nPassword: ' + Database.pterodactyl_password + '```'); + message.author.send(embed); + } + }); +}; diff --git a/commands/deploy.js b/commands/deploy.js index a9150de..f356b71 100644 --- a/commands/deploy.js +++ b/commands/deploy.js @@ -1,199 +1,198 @@ -exports.run = (client, message, args) => { - -const node = require('nodeactyl'); -const Application = node.Application; -const mysql = require('mysql'); -const Discord = require("discord.js"); -const randomWords = require('random-words'); -let ram = {}; -let disk = {}; -let software = {}; -let randname = (randomWords({ exactly: 3, join: '' })); - -const con = mysql.createConnection({ - connectionLimit: 20, - host: client.config.mysqlHOST, - port: "3306", - user: client.config.mysqlUSER, - password: client.config.mysqlPASS, - database: client.config.mysqlDB, -}) - -Application.login(client.config.panelURL, client.config.panelAPI, (logged_in, err) => { - console.log("[CloudServer] Logged In To The Panel") -}) -var userid = message.author.id; -con.query(`SELECT * FROM users WHERE discord_id = '${userid}'`, function (err, result, fields) { -let NoCon = new Discord.MessageEmbed() - .setColor("FF0009") - .setAuthor("CloudServer ¦ Creation", client.user.avatarURL()) - .setDescription("```There was an error connecting to the database. Please report this issue to a member of the staffteam```") - .setFooter(`💕CloudServer Alpha| CodeCannibals\nRequested By ➤ ${message.author.tag}`, client.user.avatarURL()) - -if (err) return message.channel.send(NoCon); - -if (result.length == 1) { -var user = JSON.parse(JSON.stringify(result[0])); -con.query(`SELECT * FROM levels WHERE level = '${user.level}'`, function(err, results, fields) { -var level = JSON.parse(JSON.stringify(results[0])); - -let totsrvs = (user.extra_servers + level.servers_balance); -let totram = (user.extra_ram + level.ram_balance); -let totdisk = (user.extra_disk + level.disk_balance); - -if (user.current_servers >= totsrvs) { - let MaxReached = new Discord.MessageEmbed() - .setColor("#FFD500") - .setAuthor("CloudServer ¦ Creation", client.user.avatarURL()) - .setDescription("```You have already reached your maximum servers limit. Please upgrade to a donator plan for more resources```") - .setFooter(`💕CloudServer Alpha | CodeCannibals\nRequested By ➤ ${message.author.tag}`, client.user.avatarURL()) -return message.channel.send(MaxReached); -} - -let UserStats = new Discord.MessageEmbed() - .setColor("#FF00BD") - .setAuthor("CloudServer ¦ Creation", client.user.avatarURL()) - .setDescription(`**__Your Current Statistics Is:__**`+"```"+`User Plan: ${level.plan}\nTotal Servers: ${user.current_servers}/${totsrvs}\nTotal Ram: ${user.current_ram}/${user.totram}\nTotal Disk: ${user.current_disk}/${user.totdisk}`+"```") - .setFooter(`💕CloudServer Alpha | CodeCannibals\nRequested By ➤ ${message.author.tag}`, client.user.avatarURL()) - message.channel.send(UserStats); - -let NumRam = new Discord.MessageEmbed() - .setColor("#00FFA8") - .setAuthor("CloudServer ¦ Creation", client.user.avatarURL()) - .setDescription("```1️⃣¦ How much Ram do you want to allocate to the server (MB)```") - .setFooter(`💕CloudServer Alpha | CodeCannibals\nRequested By ➤ ${message.author.tag}`, client.user.avatarURL()) -message.channel.send(NumRam).then(async function() { - -message.channel.awaitMessages(m => m.author.id == message.author.id, - {max: 1, time: 30000}).then(async collected => { - ram = collected.first().content; -}).then(async function() { - -let NumDisk = new Discord.MessageEmbed() - .setColor("#FF8100") - .setAuthor("CloudServer ¦ Creation", client.user.avatarURL()) - .setDescription("```2️⃣¦ How much Disk space do you want to allocate to the server (MB)```") - .setFooter(`💕CloudServer Alpha| CodeCannibals\nRequested By ➤ ${message.author.tag}`, client.user.avatarURL()) -message.channel.send(NumDisk).then(async function() { - -message.channel.awaitMessages(m => m.author.id == message.author.id, - {max: 1, time: 30000}).then(async collected => { - disk = collected.first().content; -}).then(async function() { - -let ServerSelector = new Discord.MessageEmbed() - .setColor("#0084FF") - .setAuthor("CloudServer ¦ Creation", client.user.avatarURL()) - .setDescription("**__Please Choose A Server Software To Install__**```1) Paper Spigot\n2) NukkitX\n3) Pocketmine-MP\n4) Bedrock Dedicated Server```**__Reply With A Number To Continue__**") - .setFooter(`💕CloudServer Alpha| CodeCannibals\nRequested By ➤ ${message.author.tag}`, client.user.avatarURL()) -message.channel.send(ServerSelector).then(async function() { - -message.channel.awaitMessages(m => m.author.id == message.author.id, - {max: 1, time: 30000}).then(async collected => { - software = collected.first().content; - }).then(async function() { - -let ramleft = (totram - user.current_ram); -let NoRamLeft = new Discord.MessageEmbed() - .setColor("FF0009") - .setAuthor("CloudServer ¦ Creation", client.user.avatarURL()) - .setDescription("```You don't have enough Ram in your balance to make this server```") - .setFooter(`💕CloudServer Alpha | CodeCannibals\nRequested By ➤ ${message.author.tag}`, client.user.avatarURL()) -if(ram > ramleft) return message.channel.send(NoRamLeft); - -let InvalidRam = new Discord.MessageEmbed() - .setColor("FF0009") - .setAuthor("CloudServer ¦ Creation", client.user.avatarURL()) - .setDescription("```To avoid abuse, The Minimum Ram allocation per server is set to 512MB```") - .setFooter(`💕CloudServer Alpha | CodeCannibals\nRequested By ➤ ${message.author.tag}`, client.user.avatarURL()) -if(ram < 512) return message.channel.send(InvalidRam); - -let diskleft = (totdisk - user.current_disk); -let NoDiskLeft = new Discord.MessageEmbed() - .setColor("FF0009") - .setAuthor("CloudServer ¦ Creation", client.user.avatarURL()) - .setDescription("```You don't have enough Disk Space in your balance to make this server```") - .setFooter(`💕CloudServer Alpha | CodeCannibals\nRequested By ➤ ${message.author.tag}`, client.user.avatarURL()) -if(disk > diskleft) return message.channel.send(NoDiskLeft); - -let InvalidDisk = new Discord.MessageEmbed() - .setColor("FF0009") - .setAuthor("CloudServer ¦ Creation", client.user.avatarURL()) - .setDescription("```To avoid abuse, The Minimum Disk allocation per server is set to 512MB```") - .setFooter(`💕CloudServer Alpha | CodeCannibals\nRequested By ➤ ${message.author.tag}`, client.user.avatarURL()) -if(disk < 512) return message.channel.send(InvalidDisk); - -let Servers = (user.current_servers + 1); -let RamCount = (Number(user.current_ram) + Number(ram)); -let DiskCount = (Number(user.current_disk) + Number(disk)); - -if (software === "1"){ - Application.createServer("1.12.2", randname, user.pterodactyl_userID, null, client.config.paperEGG, "quay.io/pterodactyl/core:java", "java -Xms128M -Xmx{{SERVER_MEMORY}}M -Dterminal.jline=false -Dterminal.ansi=true -jar {{SERVER_JARFILE}}", ram, "0", disk, "500", "100", "0", "1").then(res => { - con.query(`UPDATE users SET current_ram = '${RamCount}', current_disk = '${DiskCount}', current_servers = '${Servers}' WHERE discord_id = '${message.author.id}'`); - con.query(`INSERT INTO servers (discord_id, pterodactyl_serverID, pterodactyl_userID) VALUES ('${message.author.id}', '${res.id}', '${user.pterodactyl_userID}')`); - let Deployed = new Discord.MessageEmbed() - .setColor("#CB00FF") - .setAuthor("CloudServer ¦ Creation", client.user.avatarURL()) - .setDescription("```Your Server Has Been Deployed```") - .setFooter(`💕CloudServer Alpha| CodeCannibals\nRequested By ➤ ${message.author.tag}`, client.user.avatarURL()) - message.channel.send(Deployed); - }) - } else if (software === "2"){ - Application.createServer("latest", randname, user.pterodactyl_userID, null, client.config.nukkitEGG, "quay.io/pterodactyl/core:java-glibc", "java -Xms128M -Xmx{{SERVER_MEMORY}}M -jar {{SERVER_JARFILE}}", ram, "0", disk, "500", "100", "0", "1").then(res => { - con.query(`UPDATE users SET current_ram = '${RamCount}', current_disk = '${DiskCount}', current_servers = '${Servers}' WHERE discord_id = '${message.author.id}'`); - con.query(`INSERT INTO servers (discord_id, pterodactyl_serverID, pterodactyl_userID) VALUES ('${message.author.id}', '${res.id}', '${user.pterodactyl_userID}')`); - let Deployed = new Discord.MessageEmbed() - .setColor("#EC00FF") - .setAuthor("CloudServer ¦ Creation", client.user.avatarURL()) - .setDescription("```Your Server Has Been Deployed```") - .setFooter(`💕CloudServer Alpha | CodeCannibals\nRequested By ➤ ${message.author.tag}`, client.user.avatarURL()) - message.channel.send(Deployed); - }) - } else if (software === "3"){ - Application.createServer("latest", randname, user.pterodactyl_userID, null, client.config.pocketmineEGG, "quay.io/parkervcp/pterodactyl-images:base_ubuntu", "./bin/php7/bin/php ./PocketMine-MP.phar --no-wizard --disable-ansi", ram, "0", disk, "500", "100", "0", "1").then(res => { - con.query(`UPDATE users SET current_ram = '${RamCount}', current_disk = '${DiskCount}', current_servers = '${Servers}' WHERE discord_id = '${message.author.id}'`); - con.query(`INSERT INTO servers (discord_id, pterodactyl_serverID, pterodactyl_userID) VALUES ('${message.author.id}', '${res.id}', '${user.pterodactyl_userID}')`); - let Deployed = new Discord.MessageEmbed() - .setColor("#FF00B3") - .setAuthor("CloudServer ¦ Creation", client.user.avatarURL()) - .setDescription("```Your Server Has Been Deployed```") - .setFooter(`💕CloudServer Alpha| CodeCannibals\nRequested By ➤ ${message.author.tag}`, client.user.avatarURL()) - message.channel.send(Deployed); - }) - } else if (software === "4"){ - Application.createServer("latest", randname, user.pterodactyl_userID, null, client.config.bedrockEGG, "quay.io/parkervcp/pterodactyl-images:base_ubuntu", "./bedrock_server", ram, "0", disk, "500", "100", "0", "1").then(res => { - con.query(`UPDATE users SET current_ram = '${RamCount}', current_disk = '${DiskCount}', current_servers = '${Servers}' WHERE discord_id = '${message.author.id}'`); - con.query(`INSERT INTO servers (discord_id, pterodactyl_serverID, pterodactyl_userID) VALUES ('${message.author.id}', '${res.id}', '${user.pterodactyl_userID}')`); - let Deployed = new Discord.MessageEmbed() - .setColor("#B100FF") - .setAuthor("CloudServer¦ Creation", client.user.avatarURL()) - .setDescription("```Your Server Has Been Deployed```") - .setFooter(`💕CloudServer Alpha| CodeCannibals\nRequested By ➤ ${message.author.tag}`, client.user.avatarURL()) - message.channel.send(Deployed); - }) - } else { - let Deployed = new Discord.MessageEmbed() - .setColor("FF0009") - .setAuthor("CloudServer ¦ Creation", client.user.avatarURL()) - .setDescription("```Your selected server software was not found```") - .setFooter(`💕CloudServer Alpha| CodeCannibals\nRequested By ➤ ${message.author.tag}`, client.user.avatarURL()) - message.channel.send(Deployed); -} - - }) - }) - }) - }) - }) -}) -}) -} else { - let Glitched = new Discord.MessageEmbed() - .setColor("FF0009") - .setAuthor("CloudServer¦ Creation", message.guild.iconURL()) - .setDescription("```You are not registered on our systems. You can do so by doing "+client.config.prefix+"register```") - .setFooter(`💕CloudServer Alpha | CodeCannibals\nRequested By ➤ ${message.author.tag}`, client.user.avatarURL()) - message.channel.send(Glitched); - } -}) -} +exports.run = (client, message) => { + const node = require('nodeactyl'); + const Application = node.Application; + const Discord = require('discord.js'); + const randomWords = require('random-words'); + let ram = {}; + let disk = {}; + let software = {}; + const randname = (randomWords({ exactly: 3, join: '' })); + + const con = require('../utils/dbConnector'); + + + Application.login(client.config.panelURL, client.config.panelAPI, (logged_in, err) => { + if(!err) console.log('[CloudServer] Logged In To The Panel'); + }); + + const userid = message.author.id; + + con.query(`SELECT * FROM users WHERE discord_id = '${userid}'`, function(err, result) { + const NoCon = new Discord.MessageEmbed() + .setColor('FF0009') + .setAuthor('CloudServer ¦ Creation', client.user.avatarURL()) + .setDescription('```There was an error connecting to the database. Please report this issue to a member of the staffteam```') + .setFooter(`💕CloudServer Alpha| CodeCannibals\nRequested By ➤ ${message.author.tag}`, client.user.avatarURL()); + + if (err) return message.channel.send(NoCon); + + if (result.length == 1) { + const user = JSON.parse(JSON.stringify(result[0])); + con.query(`SELECT * FROM levels WHERE level = '${user.level}'`, function(err, results) { + const level = JSON.parse(JSON.stringify(results[0])); + + const totsrvs = (user.extra_servers + level.servers_balance); + const totram = (user.extra_ram + level.ram_balance); + const totdisk = (user.extra_disk + level.disk_balance); + + if (user.current_servers >= totsrvs) { + const MaxReached = new Discord.MessageEmbed() + .setColor('#FFD500') + .setAuthor('CloudServer ¦ Creation', client.user.avatarURL()) + .setDescription('```You have already reached your maximum servers limit. Please upgrade to a donator plan for more resources```') + .setFooter(`💕CloudServer Alpha | CodeCannibals\nRequested By ➤ ${message.author.tag}`, client.user.avatarURL()); + return message.channel.send(MaxReached); + } + + const UserStats = new Discord.MessageEmbed() + .setColor('#FF00BD') + .setAuthor('CloudServer ¦ Creation', client.user.avatarURL()) + .setDescription('**__Your Current Statistics Is:__**' + '```' + `User Plan: ${level.plan}\nTotal Servers: ${user.current_servers}/${totsrvs}\nTotal Ram: ${user.current_ram}/${user.totram}\nTotal Disk: ${user.current_disk}/${user.totdisk}` + '```') + .setFooter(`💕CloudServer Alpha | CodeCannibals\nRequested By ➤ ${message.author.tag}`, client.user.avatarURL()); + message.channel.send(UserStats); + + const NumRam = new Discord.MessageEmbed() + .setColor('#00FFA8') + .setAuthor('CloudServer ¦ Creation', client.user.avatarURL()) + .setDescription('```1️⃣¦ How much Ram do you want to allocate to the server (MB)```') + .setFooter(`💕CloudServer Alpha | CodeCannibals\nRequested By ➤ ${message.author.tag}`, client.user.avatarURL()); + message.channel.send(NumRam).then(async function() { + + message.channel.awaitMessages(m => m.author.id == message.author.id, + { max: 1, time: 30000 }).then(async collected => { + ram = collected.first().content; + }).then(async function() { + + const NumDisk = new Discord.MessageEmbed() + .setColor('#FF8100') + .setAuthor('CloudServer ¦ Creation', client.user.avatarURL()) + .setDescription('```2️⃣¦ How much Disk space do you want to allocate to the server (MB)```') + .setFooter(`💕CloudServer Alpha| CodeCannibals\nRequested By ➤ ${message.author.tag}`, client.user.avatarURL()); + message.channel.send(NumDisk).then(async function() { + + message.channel.awaitMessages(m => m.author.id == message.author.id, + { max: 1, time: 30000 }).then(async collected => { + disk = collected.first().content; + }).then(async function() { + + const ServerSelector = new Discord.MessageEmbed() + .setColor('#0084FF') + .setAuthor('CloudServer ¦ Creation', client.user.avatarURL()) + .setDescription('**__Please Choose A Server Software To Install__**```1) Paper Spigot\n2) NukkitX\n3) Pocketmine-MP\n4) Bedrock Dedicated Server```**__Reply With A Number To Continue__**') + .setFooter(`💕CloudServer Alpha| CodeCannibals\nRequested By ➤ ${message.author.tag}`, client.user.avatarURL()); + message.channel.send(ServerSelector).then(async function() { + + message.channel.awaitMessages(m => m.author.id == message.author.id, + { max: 1, time: 30000 }).then(async collected => { + software = collected.first().content; + }).then(async function() { + + const ramleft = (totram - user.current_ram); + const NoRamLeft = new Discord.MessageEmbed() + .setColor('FF0009') + .setAuthor('CloudServer ¦ Creation', client.user.avatarURL()) + .setDescription('```You don\'t have enough Ram in your balance to make this server```') + .setFooter(`💕CloudServer Alpha | CodeCannibals\nRequested By ➤ ${message.author.tag}`, client.user.avatarURL()); + if(ram > ramleft) return message.channel.send(NoRamLeft); + + const InvalidRam = new Discord.MessageEmbed() + .setColor('FF0009') + .setAuthor('CloudServer ¦ Creation', client.user.avatarURL()) + .setDescription('```To avoid abuse, The Minimum Ram allocation per server is set to 512MB```') + .setFooter(`💕CloudServer Alpha | CodeCannibals\nRequested By ➤ ${message.author.tag}`, client.user.avatarURL()); + if(ram < 512) return message.channel.send(InvalidRam); + + const diskleft = (totdisk - user.current_disk); + const NoDiskLeft = new Discord.MessageEmbed() + .setColor('FF0009') + .setAuthor('CloudServer ¦ Creation', client.user.avatarURL()) + .setDescription('```You don\'t have enough Disk Space in your balance to make this server```') + .setFooter(`💕CloudServer Alpha | CodeCannibals\nRequested By ➤ ${message.author.tag}`, client.user.avatarURL()); + if(disk > diskleft) return message.channel.send(NoDiskLeft); + + const InvalidDisk = new Discord.MessageEmbed() + .setColor('FF0009') + .setAuthor('CloudServer ¦ Creation', client.user.avatarURL()) + .setDescription('```To avoid abuse, The Minimum Disk allocation per server is set to 512MB```') + .setFooter(`💕CloudServer Alpha | CodeCannibals\nRequested By ➤ ${message.author.tag}`, client.user.avatarURL()); + if(disk < 512) return message.channel.send(InvalidDisk); + + const Servers = (user.current_servers + 1); + const RamCount = (Number(user.current_ram) + Number(ram)); + const DiskCount = (Number(user.current_disk) + Number(disk)); + + if (software === '1') { + Application.createServer('1.12.2', randname, user.pterodactyl_userID, null, client.config.paperEGG, 'quay.io/pterodactyl/core:java', 'java -Xms128M -Xmx{{SERVER_MEMORY}}M -Dterminal.jline=false -Dterminal.ansi=true -jar {{SERVER_JARFILE}}', ram, '0', disk, '500', '100', '0', '1').then(res => { + con.query(`UPDATE users SET current_ram = '${RamCount}', current_disk = '${DiskCount}', current_servers = '${Servers}' WHERE discord_id = '${message.author.id}'`); + con.query(`INSERT INTO servers (discord_id, pterodactyl_serverID, pterodactyl_userID) VALUES ('${message.author.id}', '${res.id}', '${user.pterodactyl_userID}')`); + const Deployed = new Discord.MessageEmbed() + .setColor('#CB00FF') + .setAuthor('CloudServer ¦ Creation', client.user.avatarURL()) + .setDescription('```Your Server Has Been Deployed```') + .setFooter(`💕CloudServer Alpha| CodeCannibals\nRequested By ➤ ${message.author.tag}`, client.user.avatarURL()); + message.channel.send(Deployed); + }); + } + else if (software === '2') { + Application.createServer('latest', randname, user.pterodactyl_userID, null, client.config.nukkitEGG, 'quay.io/pterodactyl/core:java-glibc', 'java -Xms128M -Xmx{{SERVER_MEMORY}}M -jar {{SERVER_JARFILE}}', ram, '0', disk, '500', '100', '0', '1').then(res => { + con.query(`UPDATE users SET current_ram = '${RamCount}', current_disk = '${DiskCount}', current_servers = '${Servers}' WHERE discord_id = '${message.author.id}'`); + con.query(`INSERT INTO servers (discord_id, pterodactyl_serverID, pterodactyl_userID) VALUES ('${message.author.id}', '${res.id}', '${user.pterodactyl_userID}')`); + const Deployed = new Discord.MessageEmbed() + .setColor('#EC00FF') + .setAuthor('CloudServer ¦ Creation', client.user.avatarURL()) + .setDescription('```Your Server Has Been Deployed```') + .setFooter(`💕CloudServer Alpha | CodeCannibals\nRequested By ➤ ${message.author.tag}`, client.user.avatarURL()); + message.channel.send(Deployed); + }); + } + else if (software === '3') { + Application.createServer('latest', randname, user.pterodactyl_userID, null, client.config.pocketmineEGG, 'quay.io/parkervcp/pterodactyl-images:base_ubuntu', './bin/php7/bin/php ./PocketMine-MP.phar --no-wizard --disable-ansi', ram, '0', disk, '500', '100', '0', '1').then(res => { + con.query(`UPDATE users SET current_ram = '${RamCount}', current_disk = '${DiskCount}', current_servers = '${Servers}' WHERE discord_id = '${message.author.id}'`); + con.query(`INSERT INTO servers (discord_id, pterodactyl_serverID, pterodactyl_userID) VALUES ('${message.author.id}', '${res.id}', '${user.pterodactyl_userID}')`); + const Deployed = new Discord.MessageEmbed() + .setColor('#FF00B3') + .setAuthor('CloudServer ¦ Creation', client.user.avatarURL()) + .setDescription('```Your Server Has Been Deployed```') + .setFooter(`💕CloudServer Alpha| CodeCannibals\nRequested By ➤ ${message.author.tag}`, client.user.avatarURL()); + message.channel.send(Deployed); + }); + } + else if (software === '4') { + Application.createServer('latest', randname, user.pterodactyl_userID, null, client.config.bedrockEGG, 'quay.io/parkervcp/pterodactyl-images:base_ubuntu', './bedrock_server', ram, '0', disk, '500', '100', '0', '1').then(res => { + con.query(`UPDATE users SET current_ram = '${RamCount}', current_disk = '${DiskCount}', current_servers = '${Servers}' WHERE discord_id = '${message.author.id}'`); + con.query(`INSERT INTO servers (discord_id, pterodactyl_serverID, pterodactyl_userID) VALUES ('${message.author.id}', '${res.id}', '${user.pterodactyl_userID}')`); + const Deployed = new Discord.MessageEmbed() + .setColor('#B100FF') + .setAuthor('CloudServer¦ Creation', client.user.avatarURL()) + .setDescription('```Your Server Has Been Deployed```') + .setFooter(`💕CloudServer Alpha| CodeCannibals\nRequested By ➤ ${message.author.tag}`, client.user.avatarURL()); + message.channel.send(Deployed); + }); + } + else { + const Deployed = new Discord.MessageEmbed() + .setColor('FF0009') + .setAuthor('CloudServer ¦ Creation', client.user.avatarURL()) + .setDescription('```Your selected server software was not found```') + .setFooter(`💕CloudServer Alpha| CodeCannibals\nRequested By ➤ ${message.author.tag}`, client.user.avatarURL()); + message.channel.send(Deployed); + } + + }); + }); + }); + }); + }); + }); + }); + } + else { + const Glitched = new Discord.MessageEmbed() + .setColor('FF0009') + .setAuthor('CloudServer¦ Creation', message.guild.iconURL()) + .setDescription('```You are not registered on our systems. You can do so by doing ' + client.config.prefix + 'register```') + .setFooter(`💕CloudServer Alpha | CodeCannibals\nRequested By ➤ ${message.author.tag}`, client.user.avatarURL()); + message.channel.send(Glitched); + } + }); +}; diff --git a/commands/info.js b/commands/info.js index 79606d4..4ab8961 100644 --- a/commands/info.js +++ b/commands/info.js @@ -1,49 +1,41 @@ -exports.run = async (client, message, args) => { -const mysql = require("mysql"); -const Discord = require("discord.js"); +exports.run = async (client, message) => { + const Discord = require('discord.js'); + const con = require('../utils/dbConnector'); -const con = mysql.createConnection({ - connectionLimit: 20, - host: client.config.mysqlHOST, - port: "3306", - user: client.config.mysqlUSER, - password: client.config.mysqlPASS, - database: client.config.mysqlDB -}) + const userid = message.author.id; + con.query(`SELECT * FROM users WHERE discord_id = '${userid}'`, function(err, result) { -var userid = message.author.id; -con.query(`SELECT * FROM users WHERE discord_id = '${userid}'`, function(err, result, fields) { + const NoCon = new Discord.MessageEmbed() + .setColor('FF0009') + .setAuthor('CloudServer ¦ Info', client.user.avatarURL()) + .setDescription('```There was an error connecting to the database. Please report this issue to a member of the staffteam```') + .setFooter(`💕CloudServer Alpha| CodeCannibals\nRequested By ➤ ${message.author.tag}`, client.user.avatarURL()); + if (err) return message.channel.send(NoCon); -let NoCon = new Discord.MessageEmbed() - .setColor("FF0009") - .setAuthor("CloudServer ¦ Info", client.user.avatarURL()) - .setDescription("```There was an error connecting to the database. Please report this issue to a member of the staffteam```") - .setFooter(`💕CloudServer Alpha| CodeCannibals\nRequested By ➤ ${message.author.tag}`, client.user.avatarURL()) -if (err) return message.channel.send(NoCon); + if (result.length === 1) { + const user = JSON.parse(JSON.stringify(result[0])); + con.query(`SELECT * FROM levels WHERE level = '${user.level}'`, (err, results) => { + const level = JSON.parse(JSON.stringify(results[0])); -if (result.length == 1){ -var user = JSON.parse(JSON.stringify(result[0])); -con.query(`SELECT * FROM levels WHERE level = '${user.level}'`, function(err, results, fields) { -var level = JSON.parse(JSON.stringify(results[0])); + const totsrvs = (user.extra_servers + level.servers_balance); + const totram = (user.extra_ram + level.ram_balance); + const totdisk = (user.extra_disk + level.disk_balance); -let totsrvs = (user.extra_servers + level.servers_balance); -let totram = (user.extra_ram + level.ram_balance); -let totdisk = (user.extra_disk + level.disk_balance); - -let embed = new Discord.MessageEmbed() - .setAuthor("CloudServer ¦ Info", client.user.avatarURL()) - .setFooter(`💕CloudServer Alpha | CodeCannibals\nRequested By ➤ ${message.author.tag}`, client.user.avatarURL()) - .setDescription(`**__Viewing Informations Of (${message.author.tag})__**`+"```"+`Panel Username: ${user.pterodactyl_username}\nUser Plan: ${level.plan}\nTotal Servers: ${user.current_servers}/${totsrvs}\nTotal Ram: ${user.current_ram}/${totram}\nTotal Disk: ${user.current_disk}/${totdisk}`+"```") - .setColor("#D500FF") -message.channel.send(embed); -}) -} else { -let NoReg = new Discord.MessageEmbed() - .setColor("#99FF00") - .setAuthor("CloudServer ¦ Info", client.user.avatarURL()) - .setDescription("```There was an error trying to fetch the user data```") - .setFooter(`💕CloudServer Alpha | CodeCannibals\nRequested By ➤ ${message.author.tag}`, client.user.avatarURL()) - message.channel.send(NoReg); -} -}) -} + const embed = new Discord.MessageEmbed() + .setAuthor('CloudServer ¦ Info', client.user.avatarURL()) + .setFooter(`💕CloudServer Alpha | CodeCannibals\nRequested By ➤ ${message.author.tag}`, client.user.avatarURL()) + .setDescription(`**__Viewing Informations Of (${message.author.tag})__**` + '```' + `Panel Username: ${user.pterodactyl_username}\nUser Plan: ${level.plan}\nTotal Servers: ${user.current_servers}/${totsrvs}\nTotal Ram: ${user.current_ram}/${totram}\nTotal Disk: ${user.current_disk}/${totdisk}` + '```') + .setColor('#D500FF'); + message.channel.send(embed); + }); + } + else { + const NoReg = new Discord.MessageEmbed() + .setColor('#99FF00') + .setAuthor('CloudServer ¦ Info', client.user.avatarURL()) + .setDescription('```There was an error trying to fetch the user data```') + .setFooter(`💕CloudServer Alpha | CodeCannibals\nRequested By ➤ ${message.author.tag}`, client.user.avatarURL()); + message.channel.send(NoReg); + } + }); +}; diff --git a/commands/register.js b/commands/register.js index 24ccc8b..66c7828 100644 --- a/commands/register.js +++ b/commands/register.js @@ -1,102 +1,95 @@ -exports.run = (client, message, args) => { - const node = require('nodeactyl'); - const Application = node.Application; - const mysql = require('mysql'); - const Discord = require("discord.js"); - const randomWords = require('random-words'); - let email = {}; - let password = {}; - - const con = mysql.createConnection({ - connectionLimit: 20, - host: client.config.mysqlHOST, - port: "3306", - user: client.config.mysqlUSER, - password: client.config.mysqlPASS, - database: client.config.mysqlDB, -}); - -var userid = message.author.id; -con.query(`SELECT * FROM users WHERE discord_id = '${userid}'`, function (err, result, fields) { -let NoCon = new Discord.MessageEmbed() - .setColor("FF0009") - .setAuthor("CloudServer ¦ Registration", client.user.avatarURL()) - .setDescription("```There was an error connecting to the database. Please report this issue to a member of the staffteam```") - .setFooter(`💕CloudServer Alpha | AcktarOfficial.com\nRequested By ➤ ${message.author.tag}`, client.user.avatarURL()) - -if (err) return message.channel.send(NoCon); - -if (result.length == 0) { -let embed = new Discord.MessageEmbed() - .setColor("56FF5B") - .setFooter(`💕CloudServer Alpha | AcktarOfficial.com\nRequested By ➤ ${message.author.tag}`, client.user.avatarURL()) - .setAuthor("CloudServer ¦ Registration", client.user.avatarURL()) - .setDescription("```Due to privacy reasons, the registration will take place in your DMS. Please ensure than you are allowed to received DMS from this server```") -message.channel.send(embed); - -let embed1 = new Discord.MessageEmbed() - .setColor("3768FF") - .setFooter(`💕CloudServer Alpha | AcktarOfficial.com\nRequested By ➤ ${message.author.tag}`, client.user.avatarURL()) - .setAuthor("CloudServer ¦ Registration", client.user.avatarURL()) - .setDescription("**__What Is CloudServer__**```CloudServer is an easy to modify Advanced discord bot which aims to help small hosts or other peoples get a better control of their servers```**__Bug Fixes ¦¦ Contributions__**```CloudServer is a project which is part of the OpenSource Collaboration Community and welcomes contributors to improve / fix bugs and send their pr for review```**__Support Links__**\n**[Youtube](https://m.youtube.com/channel/UChjN4G3gnyn8F7FUo-WRQpA)**\n**[Github](https://github.com/AcktarOfficial)**\n**[Support Server](https://discord.gg/WQvGtXk)**") -message.author.send(embed1).then(m =>{ -let c = m.channel; - -let embed2 = new Discord.MessageEmbed() - .setColor("#FFDC00") - .setFooter(`💕CloudServer Alpha | AcktarOfficial.com\nRequested By ➤ ${message.author.tag}`, client.user.avatarURL()) - .setDescription("```1️⃣| What Is your email```") -c.send(embed2).then(async function() { - -c.awaitMessages(m => m.author.id == message.author.id, - {max: 1, time: 300000}).then(async collected => { - email = (collected.first().content); -}).then(async function() { - -let embed = new Discord.MessageEmbed() - .setColor("#FFE900") - .setDescription("```2️⃣| What Do You Want Your Panel Password To Be```") - .setFooter(`💕CloudServer Alpha | AcktarOfficial.com\nRequested By ➤ ${message.author.tag}`, client.user.avatarURL()) -c.send(embed).then(async function() { - -c.awaitMessages(m => m.author.id == message.author.id, - {max: 1, time: 300000}).then(async collected =>{ - password = (collected.first().content); - -Application.login(client.config.panelURL, client.config.panelAPI, (logged_in, err) => { - console.log("[CloudServer] Logged In To Panel Succesfully"); -}) - -let randname = (randomWords({ exactly: 2, join: '' })); -Application.createUser(randname, password, email, randname, "@CloudServer", false, "en").then(pan => { -let embed = new Discord.MessageEmbed() - .setAuthor("CloudServer ¦ Registration", client.user.avatarURL()) - .setFooter(`💕CloudServer Alpha | AcktarOfficial.com\nRequested By ➤ ${message.author.tag}`, client.user.avatarURL()) - .setDescription("```You have been successfully registered on our systems. You can see your balance with "+client.config.prefix+"info and create servers with "+client.config.prefix+"deploy```") - .setColor("56FF5B") -c.send(embed); - -con.query(`INSERT INTO users (discord_id, email, level, pterodactyl_userid, pterodactyl_password, pterodactyl_username, extra_disk, extra_ram, extra_servers, current_ram, current_disk, current_servers) VALUES ('${message.author.id}', '${email}', '1', '${pan.id}', '${password}', '${randname}', '0', '0', '0', '0', '0', '0')`); -}).catch(err => { -let embed = new Discord.MessageEmbed() - .setAuthor("CloudServer ¦ Registration", client.user.avatarURL()) - .setFooter(`💕CloudServer Alpha | AcktarOfficial.com\nRequested By ➤ ${message.author.tag}`, client.user.avatarURL()) - .setDescription("```There was an error creating your account. Most probably the email address that you used is already registered on our systems. If this is your email and you didnt register it, Please contact a member of the staffteam```") - .setColor("FF0009") -c.send(embed); -}) - }) - }) - }) - }) - }) -} else { -let embed = new Discord.MessageEmbed() - .setAuthor("CloudServer ¦ Registration", client.user.avatarURL()) - .setFooter(`💕CloudServer Alpha | AcktarOfficial.con\nRequested By ➤ ${message.author.tag}`, client.user.avatarURL()) - .setColor("FF0009") - .setDescription("```You cannot create multiple accounts on the panel. If you lost your password, do "+client.config.prefix+"credentials to obtain them```") -message.channel.send(embed); - } - }) -} +exports.run = (client, message) => { + const node = require('nodeactyl'); + const Application = node.Application; + const Discord = require('discord.js'); + const randomWords = require('random-words'); + const con = require('../utils/dbConnector'); + let email = {}; + let password = {}; + + + const userid = message.author.id; + con.query(`SELECT * FROM users WHERE discord_id = '${userid}'`, (err, result) => { + const NoCon = new Discord.MessageEmbed() + .setColor('FF0009') + .setAuthor('CloudServer ¦ Registration', client.user.avatarURL()) + .setDescription('```There was an error connecting to the database. Please report this issue to a member of the staffteam```') + .setFooter(`💕CloudServer Alpha | AcktarOfficial.com\nRequested By ➤ ${message.author.tag}`, client.user.avatarURL()); + + if (err) return message.channel.send(NoCon); + + if (result.length == 0) { + const embed = new Discord.MessageEmbed() + .setColor('56FF5B') + .setFooter(`💕CloudServer Alpha | AcktarOfficial.com\nRequested By ➤ ${message.author.tag}`, client.user.avatarURL()) + .setAuthor('CloudServer ¦ Registration', client.user.avatarURL()) + .setDescription('```Due to privacy reasons, the registration will take place in your DMS. Please ensure than you are allowed to received DMS from this server```'); + message.channel.send(embed); + + const embed1 = new Discord.MessageEmbed() + .setColor('3768FF') + .setFooter(`💕CloudServer Alpha | AcktarOfficial.com\nRequested By ➤ ${message.author.tag}`, client.user.avatarURL()) + .setAuthor('CloudServer ¦ Registration', client.user.avatarURL()) + .setDescription('**__What Is CloudServer__**```CloudServer is an easy to modify Advanced discord bot which aims to help small hosts or other peoples get a better control of their servers```**__Bug Fixes ¦¦ Contributions__**```CloudServer is a project which is part of the OpenSource Collaboration Community and welcomes contributors to improve / fix bugs and send their pr for review```**__Support Links__**\n**[Youtube](https://m.youtube.com/channel/UChjN4G3gnyn8F7FUo-WRQpA)**\n**[Github](https://github.com/AcktarOfficial)**\n**[Support Server](https://discord.gg/WQvGtXk)**'); + message.author.send(embed1).then(m =>{ + const c = m.channel; + + const embed2 = new Discord.MessageEmbed() + .setColor('#FFDC00') + .setFooter(`💕CloudServer Alpha | AcktarOfficial.com\nRequested By ➤ ${message.author.tag}`, client.user.avatarURL()) + .setDescription('```1️⃣| What Is your email```'); + c.send(embed2).then(async () => { + + c.awaitMessages(ms => ms.author.id == message.author.id, + { max: 1, time: 300000 }).then(async collected => { + email = (collected.first().content); + }).then(async () => { + + const embed3 = new Discord.MessageEmbed() + .setColor('#FFE900') + .setDescription('```2️⃣| What Do You Want Your Panel Password To Be```') + .setFooter(`💕CloudServer Alpha | AcktarOfficial.com\nRequested By ➤ ${message.author.tag}`, client.user.avatarURL()); + c.send(embed3).then(async () => { + + c.awaitMessages(ms => ms.author.id == message.author.id, + { max: 1, time: 300000 }).then(async collected =>{ + password = (collected.first().content); + + Application.login(client.config.panelURL, client.config.panelAPI, (logged_in, err) => { + if(!err) console.log('[CloudServer] Logged In To Panel Succesfully'); + }); + + const randname = (randomWords({ exactly: 2, join: '' })); + Application.createUser(randname, password, email, randname, '@CloudServer', false, 'en').then(pan => { + const embed4 = new Discord.MessageEmbed() + .setAuthor('CloudServer ¦ Registration', client.user.avatarURL()) + .setFooter(`💕CloudServer Alpha | AcktarOfficial.com\nRequested By ➤ ${message.author.tag}`, client.user.avatarURL()) + .setDescription('```You have been successfully registered on our systems. You can see your balance with ' + client.config.prefix + 'info and create servers with ' + client.config.prefix + 'deploy```') + .setColor('56FF5B'); + c.send(embed4); + + con.query(`INSERT INTO users (discord_id, email, level, pterodactyl_userid, pterodactyl_password, pterodactyl_username, extra_disk, extra_ram, extra_servers, current_ram, current_disk, current_servers) VALUES ('${message.author.id}', '${email}', '1', '${pan.id}', '${password}', '${randname}', '0', '0', '0', '0', '0', '0')`); + }).catch(() => { + const embed4 = new Discord.MessageEmbed() + .setAuthor('CloudServer ¦ Registration', client.user.avatarURL()) + .setFooter(`💕CloudServer Alpha | AcktarOfficial.com\nRequested By ➤ ${message.author.tag}`, client.user.avatarURL()) + .setDescription('```There was an error creating your account. Most probably the email address that you used is already registered on our systems. If this is your email and you didnt register it, Please contact a member of the staffteam```') + .setColor('FF0009'); + c.send(embed4); + }); + }); + }); + }); + }); + }); + } + else { + const embed = new Discord.MessageEmbed() + .setAuthor('CloudServer ¦ Registration', client.user.avatarURL()) + .setFooter(`💕CloudServer Alpha | AcktarOfficial.con\nRequested By ➤ ${message.author.tag}`, client.user.avatarURL()) + .setColor('FF0009') + .setDescription('```You cannot create multiple accounts on the panel. If you lost your password, do ' + client.config.prefix + 'credentials to obtain them```'); + message.channel.send(embed); + } + }); +}; diff --git a/index.js b/index.js index a022291..3e096a6 100644 --- a/index.js +++ b/index.js @@ -1,29 +1,29 @@ -const Discord = require("discord.js"); -const Enmap = require("enmap"); -const fs = require("fs"); +const Discord = require('discord.js'); +const Enmap = require('enmap'); +const fs = require('fs'); const client = new Discord.Client(); -const config = require("./config.json"); +const config = require('./config.json'); client.config = config; -fs.readdir("./events/", (err, files) => { - if (err) return console.error(err); - files.forEach(file => { - const event = require(`./events/${file}`); - let eventName = file.split(".")[0]; - client.on(eventName, event.bind(null, client)); - }); +fs.readdir('./events/', (err, files) => { + if (err) return console.error(err); + files.forEach(file => { + const event = require(`./events/${file}`); + const eventName = file.split('.')[0]; + client.on(eventName, event.bind(null, client)); + }); }); client.commands = new Enmap(); -fs.readdir("./commands/", (err, files) => { - if (err) return console.error(err); - files.forEach(file => { - if (!file.endsWith(".js")) return; - let props = require(`./commands/${file}`); - let commandName = file.split(".")[0]; - client.commands.set(commandName, props); - }); +fs.readdir('./commands/', (err, files) => { + if (err) return console.error(err); + files.forEach(file => { + if (!file.endsWith('.js')) return; + const props = require(`./commands/${file}`); + const commandName = file.split('.')[0]; + client.commands.set(commandName, props); + }); }); -client.login(config.token); +client.login(config.token); \ No newline at end of file diff --git a/utils/dbConnector.js b/utils/dbConnector.js new file mode 100644 index 0000000..dc8ce79 --- /dev/null +++ b/utils/dbConnector.js @@ -0,0 +1,13 @@ +const { createConnection } = require('mysql'); +const config = require('../config.json'); + +const connection = createConnection({ + connectionLimit: 20, + host: config.mysqlHOST, + port: '3306', + user: config.mysqlUSER, + password: config.mysqlPASS, + database: config.mysqlDB, +}); + +module.exports = connection; \ No newline at end of file