From 8554949e6a72a9d286ab4d1beee2eb0f42b70965 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20Olausson=20Holten=C3=A4s?= Date: Mon, 14 Mar 2022 22:56:45 +0100 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20web=20interface?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .vscode/settings.json | 3 + config.json.example | 7 +- package.json | 3 + src/dashboard/index.js | 257 +++++++++++++++++++++++++++++++++++++++++ src/index.js | 3 + 5 files changed, 272 insertions(+), 1 deletion(-) create mode 100644 src/dashboard/index.js diff --git a/.vscode/settings.json b/.vscode/settings.json index 5a47d7e..fb1ea2a 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -20,6 +20,9 @@ "Timout", "upsert", "uuidv", + "Vermium", + "Xyter", + "Xyter's", "Zyner" ], "editor.fontFamily": "Cascadia Code", diff --git a/config.json.example b/config.json.example index 31b6f85..e9584bf 100644 --- a/config.json.example +++ b/config.json.example @@ -2,7 +2,12 @@ "bot": { "token": "required", "clientId": "required", - "guildId": "required" + "guildId": "required", + "clientSecret": "required" + }, + "dashboard": { + "port": 80, + "licenseKey": "required" }, "colors": { "success": "0x22bb33", diff --git a/package.json b/package.json index 471f10c..99e2ca0 100644 --- a/package.json +++ b/package.json @@ -28,7 +28,10 @@ "@discordjs/rest": "^0.3.0", "axios": "^0.26.0", "better-sqlite3": "^7.5.0", + "dbd-dark-dashboard": "^1.6.45", "discord-api-types": "^0.28.0", + "discord-dashboard": "^2.3.14", + "discord-easy-dashboard": "^1.2.1", "discord.js": "^13.6.0", "dotenv": "^16.0.0", "i18next": "^21.6.13", diff --git a/src/dashboard/index.js b/src/dashboard/index.js new file mode 100644 index 0000000..a037245 --- /dev/null +++ b/src/dashboard/index.js @@ -0,0 +1,257 @@ +let DBD = require('discord-dashboard'); +const config = require('../../config.json'); + +const DarkDashboard = require('dbd-dark-dashboard'); +const { guilds, apis } = require('../helpers/database/models'); + +module.exports = async (client) => { + await DBD.useLicense(config.dashboard.licenseKey); + + DBD.Dashboard = DBD.UpdatedClass(); + + const Dashboard = new DBD.Dashboard({ + port: config.dashboard.port, + client: { + id: config.bot.clientId, + secret: config.bot.clientSecret, + }, + acceptPrivacyPolicy: true, + redirectUri: 'http://localhost:3000/discord/callback', + domain: 'http://localhost', + bot: client, + theme: DarkDashboard({ + information: { + createdBy: 'Zyner', + websiteTitle: 'Xyter', + websiteName: 'Xyter', + websiteUrl: 'https://zyner.org', + dashboardUrl: 'http://localhost:3000/', + supporteMail: 'contact@zyner.org', + supportServer: 'https://discord.gg/Ve9ug2zkbt', + imageFavicon: + 'https://avatars.githubusercontent.com/u/83163073?s=200&v=4', + iconURL: 'https://avatars.githubusercontent.com/u/83163073?s=200&v=4', + pageBackGround: 'linear-gradient(#2CA8FF, #155b8d)', + loggedIn: 'Successfully signed in.', + mainColor: '#2CA8FF', + subColor: '#ebdbdb', + }, + index: { + card: { + category: 'Xyter Panel', + title: `Welcome to the Xyter panel.`, + image: 'https://i.imgur.com/axnP93g.png', + footer: 'Zyner', + }, + information: { + category: 'Self-host', + title: 'Open Source', + description: `The source code is available at https://github.com/ZynerOrg/xyter`, + footer: 'Zyner', + }, + feeds: { + category: 'Support', + title: 'Information', + description: `If you need help, contact me on discord: Vermium#9649.`, + footer: 'Zyner', + }, + }, + commands: [ + { + category: 'Commands', + subTitle: 'All helpful commands', + aliasesDisabled: false, + list: [], + }, + ], + }), + settings: [ + { + categoryId: 'credits', + categoryName: 'Credits', + categoryDescription: 'Setup your bot with credit settings!', + categoryOptionsList: [ + { + optionId: 'status', + optionName: 'Status', + optionDescription: 'Toggle credits', + optionType: DBD.formTypes.switch(), + getActualSet: async ({ guild, user }) => { + const guildData = await guilds.findOne({ guildId: guild.id }); + return guildData.credits.status; + }, + setNew: async ({ guild, newData }) => { + const guildData = await guilds.findOne({ guildId: guild.id }); + + guildData.credits.status = newData ? true : false; + + await guildData.save(); + return; + }, + }, + { + optionId: 'rate', + optionName: 'Rate', + optionDescription: 'Rate', + optionType: DBD.formTypes.input('1'), + getActualSet: async ({ guild, user }) => { + const guildData = await guilds.findOne({ guildId: guild.id }); + + return guildData.credits.rate; + }, + setNew: async ({ guild, newData }) => { + const guildData = await guilds.findOne({ guildId: guild.id }); + + if (newData.match(/^[0-9]+$/) == null) { + return { error: 'Needs to be a number.' }; + } + + guildData.credits.rate = newData; + await guildData.save(); + + return; + }, + }, + { + optionId: 'minimumLength', + optionName: 'Minimum Length', + optionDescription: 'Minimum length to earn credits', + optionType: DBD.formTypes.input('5'), + getActualSet: async ({ guild, user }) => { + const guildData = await guilds.findOne({ guildId: guild.id }); + + return guildData.credits.minimumLength; + }, + setNew: async ({ guild, newData }) => { + const guildData = await guilds.findOne({ guildId: guild.id }); + + if (newData.match(/^[0-9]+$/) == null) { + return { error: 'Needs to be a number.' }; + } + + guildData.credits.minimumLength = newData; + await guildData.save(); + + return; + }, + }, + { + optionId: 'timeout', + optionName: 'Timeout', + optionDescription: 'Timeout between earnings (milliseconds)', + optionType: DBD.formTypes.input('5000'), + getActualSet: async ({ guild, user }) => { + const guildData = await guilds.findOne({ guildId: guild.id }); + + return guildData.credits.timeout; + }, + setNew: async ({ guild, newData }) => { + const guildData = await guilds.findOne({ guildId: guild.id }); + + if (newData.match(/^[0-9]+$/) == null) { + return { error: 'Needs to be a number.' }; + } + + guildData.credits.timeout = newData; + await guildData.save(); + + return; + }, + }, + { + optionId: 'workRate', + optionName: 'Work Rate', + optionDescription: 'Work Rate', + optionType: DBD.formTypes.input('15'), + getActualSet: async ({ guild, user }) => { + const guildData = await guilds.findOne({ guildId: guild.id }); + + return guildData.credits.workRate; + }, + setNew: async ({ guild, newData }) => { + const guildData = await guilds.findOne({ guildId: guild.id }); + + if (newData.match(/^[0-9]+$/) == null) { + return { error: 'Needs to be a number.' }; + } + + guildData.credits.workRate = newData; + await guildData.save(); + + return; + }, + }, + { + optionId: 'workTimeout', + optionName: 'Work Timeout', + optionDescription: 'Work Timeout (milliseconds)', + optionType: DBD.formTypes.input('900000'), + getActualSet: async ({ guild, user }) => { + const guildData = await guilds.findOne({ guildId: guild.id }); + + return guildData.credits.workTimeout; + }, + setNew: async ({ guild, newData }) => { + const guildData = await guilds.findOne({ guildId: guild.id }); + + if (newData.match(/^[0-9]+$/) == null) { + return { error: 'Needs to be a number.' }; + } + + guildData.credits.workTimeout = newData; + await guildData.save(); + + return; + }, + }, + ], + }, + { + categoryId: 'pterodactyl', + categoryName: 'Pterodactyl', + categoryDescription: 'Setup your bot with pterodactyl settings!', + categoryOptionsList: [ + { + optionId: 'url', + optionName: 'URL', + optionDescription: 'Configure your controlpanel.gg URL', + optionType: DBD.formTypes.input('https://bg.zyner.org/api/'), + getActualSet: async ({ guild, user }) => { + const api = await apis.findOne({ guildId: guild.id }); + return api.url; + }, + setNew: async ({ guild, newData }) => { + const api = await apis.findOne({ guildId: guild.id }); + + api.url = newData || url; + + await api.save(); + + return; + }, + }, + { + optionId: 'token', + optionName: 'Token', + optionDescription: 'Configure your controlpanel.gg Token', + optionType: DBD.formTypes.input('1'), + getActualSet: async ({ guild, user }) => { + const api = await apis.findOne({ guildId: guild.id }); + return api.token; + }, + setNew: async ({ guild, newData }) => { + const api = await apis.findOne({ guildId: guild.id }); + + api.token = newData || token; + + await api.save(); + + return; + }, + }, + ], + }, + ], + }); + Dashboard.init(); +}; diff --git a/src/index.js b/src/index.js index a4e037c..88cf2a1 100644 --- a/src/index.js +++ b/src/index.js @@ -4,6 +4,8 @@ const { Client, Intents } = require('discord.js'); // discord.js const { database } = require('./helpers'); // helpers const { events, commands, locale, schedules } = require('./handlers'); // handlers +const dashboard = require('./dashboard'); + const config = require('../config.json'); // config.json (async () => { @@ -12,6 +14,7 @@ const config = require('../config.json'); // config.json intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES], }); + await dashboard(client); await database(); await locale(); await events(client);