web interface

This commit is contained in:
Axel Olausson Holtenäs 2022-03-14 22:56:45 +01:00
parent 9f42740390
commit 8554949e6a
No known key found for this signature in database
GPG key ID: E3AE7E194AE017ED
5 changed files with 272 additions and 1 deletions

View file

@ -20,6 +20,9 @@
"Timout",
"upsert",
"uuidv",
"Vermium",
"Xyter",
"Xyter's",
"Zyner"
],
"editor.fontFamily": "Cascadia Code",

View file

@ -2,7 +2,12 @@
"bot": {
"token": "required",
"clientId": "required",
"guildId": "required"
"guildId": "required",
"clientSecret": "required"
},
"dashboard": {
"port": 80,
"licenseKey": "required"
},
"colors": {
"success": "0x22bb33",

View file

@ -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",

257
src/dashboard/index.js Normal file
View file

@ -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();
};

View file

@ -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);