JaBa/dashboard/dashboard.js

225 lines
6.5 KiB
JavaScript
Raw Normal View History

2023-06-26 17:25:17 +05:00
const SoftUI = require("./dashboard-core/theme/dbd-soft-ui"),
2023-06-27 00:56:18 +05:00
DBD = require("./dashboard-core/index"),
settings = require("./settings"),
2023-06-27 00:56:18 +05:00
fs = require("fs");
2023-06-26 17:25:17 +05:00
const { PermissionsBitField } = require("discord.js");
2023-06-26 17:25:17 +05:00
/**
*
* @param {import("../base/JaBa")} client
*/
module.exports.load = async client => {
const commands = client.commands.map(v => {
return {
_category: v.category,
commandName: v.command.name,
commandDescription: client.translate(`${v.category.toLowerCase()}/${v.command.name}:DESCRIPTION`),
commandUsage: client.translate(`${v.category.toLowerCase()}/${v.command.name}:USAGE`),
commandAlias: "",
};
});
let categories = [];
commands.forEach(c => {
if (!categories.includes(c._category)) categories.push(c._category);
2023-06-26 17:25:17 +05:00
});
categories = categories.map(c => {
return {
category: c,
categoryId: c.toLowerCase(),
subTitle: "",
hideAlias: true,
hideDescription: false,
hideSidebarItem: c === "Owner" || c === "IAT" || c === "SunCountry" ? true : false,
list: commands.filter(v => v._category === c),
};
});
const Dashboard = new DBD.Dashboard({
port: client.config.dashboard.port,
client: {
2023-07-05 00:58:06 +05:00
id: client.config.userId,
2023-06-26 17:25:17 +05:00
secret: client.config.dashboard.secret,
},
2023-06-27 00:41:09 +05:00
SSL: {
2023-06-27 01:01:33 +05:00
enabled: false,
2023-06-27 00:56:18 +05:00
key: fs.readFileSync(`${__dirname}/../jababot-cloudflare.key`, "utf-8"),
cert: fs.readFileSync(`${__dirname}/../jababot-cloudflare.crt`, "utf-8"),
2023-06-27 00:41:09 +05:00
},
2023-06-26 17:25:17 +05:00
cookiesSecret: client.config.dashboard.secret,
domain: client.config.dashboard.domain,
redirectUri: `${client.config.dashboard.domain}${client.config.dashboard.port !== 80 ? `:${client.config.dashboard.port}` : ""}/discord/callback`,
bot: client,
ownerIDs: [client.config.owner.id],
2023-06-26 17:25:17 +05:00
requiredPermissions: PermissionsBitField.Flags.ViewChannel,
minimizedConsoleLogs: true,
invite: {
2023-07-05 00:58:06 +05:00
clientId: client.config.userId,
2023-06-26 17:25:17 +05:00
scopes: ["bot", "applications.commands"],
permissions: "8",
2023-07-02 01:44:29 +05:00
redirectUri: `${client.config.dashboard.domain}${client.config.dashboard.port !== 80 ? `:${client.config.dashboard.port}` : ""}`,
2023-06-26 17:25:17 +05:00
},
supportServer: {
slash: "/support",
inviteUrl: client.config.support.invite,
},
rateLimits: {
manage: {
windowMs: 15 * 60 * 1000, // 15 minutes
max: 100, // Limit each IP to 100 requests per `window` (here, per 15 minutes)
message: "You are ratelimited!", // Message returned if user should be rate limited, could be also JSON/HTML
store: null, // <Rate Limiter Store> - if null, new MemoryStore()
// supported stores: https://www.npmjs.com/package/express-rate-limit#store
},
guildPage: {
windowMs: 15 * 60 * 1000,
max: 100,
message: "You are ratelimited!",
store: null,
},
settingsUpdatePostAPI: {
windowMs: 15 * 60 * 1000,
max: 100,
message: "You are ratelimited!",
store: null,
},
},
useTheme404: true,
useThemeMaintenance: true,
useUnderMaintenance: false,
underMaintenanceAccessKey: client.config.dashboard.maintanceKey,
underMaintenanceAccessPage: "/get-access",
underMaintenance: {
title: "Under Maintenance",
contentTitle: "This page is under maintenance",
texts: [
"<br>",
"We still want to change for the better for you.",
"Therefore, we are introducing technical updates so that we can allow you to enjoy the quality of our services.",
"<br>",
`Come back to us later or join our <a href="${client.config.support.invite}">Discord Support Server</a>`,
],
},
theme: SoftUI({
customThemeOptions: {
// eslint-disable-next-line no-unused-vars
index: async ({ req, res, config }) => {
const user = req.session?.user;
const username = (user?.discriminator === "0" ? user?.username : user?.tag) || "Guest";
2023-06-26 17:25:17 +05:00
const hiddenGuildMembersCount = client.guilds.cache.get("568120814776614924").memberCount;
let users = 0;
client.guilds.cache.forEach(g => {
users += g.memberCount;
});
users = users - hiddenGuildMembersCount;
const cards = [
{
title: "Current User",
icon: "single-02",
getValue: username,
},
{
2023-06-27 00:28:41 +05:00
title: "Playing music in this much servers",
2023-06-26 17:25:17 +05:00
icon: "settings-gear-65",
2023-06-27 00:28:41 +05:00
getValue: client.player.nodes.cache.size,
2023-06-26 17:25:17 +05:00
},
{
title: "Users Count",
icon: "favourite-28",
getValue: users,
},
{
title: "Servers Count",
icon: "notification-70",
2023-06-27 00:28:41 +05:00
getValue: `${client.guilds.cache.size - 1} out of 2000`,
2023-06-26 17:25:17 +05:00
progressBar: {
enabled: true,
2023-06-27 00:28:41 +05:00
getProgress: Math.round(((client.guilds.cache.size - 1) / 2000) * 100),
2023-06-26 17:25:17 +05:00
},
},
];
return {
values: [],
graph: {},
cards,
};
},
},
2023-07-07 21:50:36 +05:00
websiteName: `${client.user.getUsername()} Dashboard`,
2023-06-26 17:25:17 +05:00
colorScheme: "blue",
supporteMail: "",
icons: {
favicon: client.user.avatarURL(),
noGuildIcon: "https://pnggrid.com/wp-content/uploads/2021/05/Discord-Logo-Circle-1024x1024.png",
sidebar: {
darkUrl: client.user.avatarURL(),
lightUrl: client.user.avatarURL(),
hideName: false,
borderRadius: "1rem",
alignCenter: true,
},
},
index: {
card: {
category: "JaBa Bot",
title: "Simple bot made by <a href=\"https://github.com/JonnyBro\">Jonny_Bro</a>",
description: "JaBa's dashboard",
image: "",
link: {
enabled: false,
url: "https://google.com",
},
},
graph: {
enabled: false,
lineGraph: true,
title: "Memory Usage",
tag: "Memory (MB)",
max: 100,
},
},
sweetalert: {
errors: {
settingsSave: "Failed to save setttings",
},
success: {
settingsSave: "Successfully saved setttings.",
login: "Successfully logged in.",
logout: "Successfully logged out.",
},
},
preloader: {
image: "",
spinner: true,
text: "Page is loading",
},
commands: categories,
locales: {
enUS: require("../languages/en-US/dashboard.json"),
ruRU: require("../languages/ru-RU/dashboard.json"),
ukUA: require("../languages/uk-UA/dashboard.json"),
},
}),
customPages: [
DBD.customPagesTypes.redirectToUrl("/github", () => {
return "https://github.com/JonnyBro/JaBa";
}),
2023-07-03 20:01:52 +05:00
DBD.customPagesTypes.redirectToUrl("/updates", () => {
return "https://github.com/JonnyBro/JaBa/blob/main/dashboard/docs/updates.md";
}),
2023-06-26 17:25:17 +05:00
],
settings: settings(client),
2023-06-26 17:25:17 +05:00
});
await Dashboard.init().then(() => {
client.logger.log(`Dashboard launched on port ${client.config.dashboard.port}`, "ready");
}).catch(err => {
client.logger.log(`Dashboard failed to initialize:\n${err}`, "error");
});
};