Skip to content

Commit

Permalink
Merge branch 'deploy' into vendor
Browse files Browse the repository at this point in the history
  • Loading branch information
FaiThiX authored Sep 23, 2024
2 parents 778b1d3 + 21da665 commit 742e1e8
Show file tree
Hide file tree
Showing 9 changed files with 920 additions and 0 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"jimp": "^0.22.7",
"libsodium-wrappers": "^0.7.11",
"lodash": "^4.17.21",
"node-system-stats": "^1.3.0",
"translate": "^1.4.1",
"ts-node": "^10.9.1",
"typescript": "^4.8.2",
Expand Down
42 changes: 42 additions & 0 deletions src/commands/info.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
Copyright (C) 2022 Alexander Emanuelsson (alexemanuelol) and FaiThiX
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
https://github.com/alexemanuelol/rustplusplus
*/

const Builder = require('@discordjs/builders');

const DiscordMessages = require('../discordTools/discordMessages.js');

module.exports = {
name: 'info',

getData(client, guildId) {
return new Builder.SlashCommandBuilder()
.setName('info')
.setDescription(client.intlGet(guildId, 'commandsInfoDesc'));
},

async execute(client, interaction) {
const verifyId = Math.floor(100000 + Math.random() * 900000);
client.logInteraction(interaction, verifyId, 'slashCommand');

if (!await client.validatePermissions(interaction)) return;

await DiscordMessages.sendInfoMessage(interaction);
},
};
36 changes: 36 additions & 0 deletions src/discordTools/discordEmbeds.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
*/

import os from "node:os";
import { showTotalMemory, usagePercent } from "node-system-stats";
const Discord = require('discord.js');

const Client = require('../../index.ts');
Expand Down Expand Up @@ -1054,6 +1056,40 @@ module.exports = {
});
},

getInfoEmbed: async function (guildId) {
const osInfo = `${os.type()} ${os.release()}`;
const osUptime = `${Math.floor(os.uptime() / 86400)} Days ${String(Math.floor((os.uptime() % 86400) / 3600)).padStart(2, '0')}h ${String(Math.floor((os.uptime() % 3600) / 60)).padStart(2, '0')}m ${String(Math.floor(os.uptime() % 60)).padStart(2, '0')}s`;
const osHostname = os.hostname();
const cpuInfo = `${os.arch()} (${os.cpus().length} cores)`;
const cpuUsed = (await usagePercent({ coreIndex: 0, sampleMs: 2000 })).percent;
const memTotal = showTotalMemory(true);
const memUsed = (process.memoryUsage().rss / 1024 ** 2).toFixed(2);
const nodeVersion = process.version;
const discordJsVersion = Discord.version;
const guilds = Client.client.guilds.cache.size;
const channels = Client.client.channels.cache.size;
const users = Client.client.users.cache.size;

const description =
`${Client.client.intlGet(guildId, 'commandsInfoOperationSystem')}: ${osInfo}\n` +
`${Client.client.intlGet(guildId, 'commandsInfoUptime')}: ${osUptime}\n` +
`${Client.client.intlGet(guildId, 'commandsInfoHostname')}: ${osHostname}\n` +
`${Client.client.intlGet(guildId, 'commandsInfoCPUArch')}: ${cpuInfo}\n` +
`${Client.client.intlGet(guildId, 'commandsInfoCPUUsage')}: ${cpuUsed}\n` +
`${Client.client.intlGet(guildId, 'commandsInfoMemoryUsage')}: ${memUsed}MB/${memTotal}MB\n` +
`${Client.client.intlGet(guildId, 'commandsInfoNodeVersion')}: ${nodeVersion}\n` +
`${Client.client.intlGet(guildId, 'commandsInfoDiscordVersion')}: ${discordJsVersion}\n` +
`${Client.client.intlGet(guildId, 'commandsInfoConnected', { guilds, channels, users })}\n`;

return module.exports.getEmbed({
color: Constants.COLOR_DEFAULT,
timestamp: true,
title: `RustPlusPlus Server Status`,
description: description
});

},

getCctvEmbed: function (guildId, monument, cctvCodes, dynamic) {
let code = '';
for (const cctvCode of cctvCodes) {
Expand Down
9 changes: 9 additions & 0 deletions src/discordTools/discordMessages.js
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,15 @@ module.exports = {
await Client.client.interactionReply(interaction, content);
},

sendInfoMessage: async function (interaction) {
const content = {
embeds: [await DiscordEmbeds.getInfoEmbed(interaction.guildId)],
ephemeral: true
}

await Client.client.interactionReply(interaction, content);
},

sendCctvMessage: async function (interaction, monument, cctvCodes, dynamic) {
const content = {
embeds: [DiscordEmbeds.getCctvEmbed(interaction.guildId, monument, cctvCodes, dynamic)],
Expand Down
10 changes: 10 additions & 0 deletions src/languages/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,16 @@
"commandsHelpDesc": "Display help message.",
"commandsHelpHowToCredentials": "How-to Register Credentials",
"commandsHelpHowToPairServer": "How-to Pair Bot with Rust Server",
"commandsInfoDesc": "Show information about the Hosting Server",
"commandsInfoOperationSystem": "**Operating System**",
"commandsInfoUptime": "**Uptime**",
"commandsInfoHostname": "**Hostname**",
"commandsInfoCPUArch": "**CPU Architecture**",
"commandsInfoCPUUsage": "**CPU Usage**",
"commandsInfoMemoryUsage": "**Memory Usage**",
"commandsInfoNodeVersion": "**Node Version**",
"commandsInfoDiscordVersion": "**Discord Version**",
"commandsInfoConnected": "**Connected to** {guilds} guilds, {channels} channels, and {users} users",
"commandsItemDesc": "Get the details of an item.",
"commandsLeaderDesc": "Give or take the leadership from/to a team member.",
"commandsLeaderMemberDesc": "The name of the team member.",
Expand Down
Loading

0 comments on commit 742e1e8

Please sign in to comment.