Skip to content

Commit

Permalink
🥞 Organize commands for interactive use only.
Browse files Browse the repository at this point in the history
  • Loading branch information
Maseshi committed Mar 1, 2023
1 parent 5f3a629 commit 5c6b49e
Show file tree
Hide file tree
Showing 71 changed files with 492 additions and 4,138 deletions.
28 changes: 5 additions & 23 deletions source/commands/developer/ping.js
Original file line number Diff line number Diff line change
@@ -1,38 +1,20 @@
const { EmbedBuilder, PermissionsBitField } = require("discord.js");

module.exports = {
"enable": true,
"name": "ping",
"description": "Check the ping and api latency of the bot.",
"category": "developer",
"permissions": {
"client": [PermissionsBitField.Flags.SendMessages]
}
};

module.exports.command = {
"enable": true,
},
"usage": "ping",
"aliases": ["ปิง", "การเชื่อมต่อ"],
async execute(client, message, args) {
const msg = await message.channel.send(client.translate.commands.ping.waiting);
const ping = Math.round((msg.createdTimestamp - message.createdTimestamp) - client.ws.ping);
const api = Math.round(client.ws.ping);
const pingEmbed = new EmbedBuilder()
.setTitle(client.translate.commands.ping.connection)
.setDescription(client.translate.commands.ping.info.replace("%s1", ping).replace("%s2", api))

msg.edit({
"content": client.translate.commands.ping.result,
"embeds": [pingEmbed]
});
"function": {
"command": {}
}
}

module.exports.interaction = {
"enable": true
}

module.exports.interaction.slash = {
module.exports.function.command = {
"data": {
"name": module.exports.name,
"name_localizations": {
Expand Down
48 changes: 5 additions & 43 deletions source/commands/developer/reload.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,58 +3,20 @@ const { readdirSync } = require("node:fs");
const path = require("path");

module.exports = {
"enable": true,
"name": "reload",
"description": "Reload the command that doesn't work.",
"category": "developer",
"permissions": {
"client": [PermissionsBitField.Flags.SendMessages]
}
}

module.exports.command = {
"enable": true,
},
"usage": "reload <command: name, aliases>",
"aliases": ["recommand", "รีโหลด", "โหลดซ้ำ"],
async execute(client, message, args) {
const inputCommand = args[0];

if (!inputCommand) return message.reply(client.translate.commands.reload.command_required);

const commandName = inputCommand.toLowerCase();
const commands = message.client.commands.get(commandName);
const aliases = message.client.commands.get(client.aliases.get(commandName));
const command = commands || aliases;

if (!command) return message.reply(client.translate.commands.reload.invalid_command);

readdirSync(path.join(__dirname, "..")).forEach(async (dirs) => {
const files = readdirSync(path.join(__dirname, "..", dirs));

if (files.includes(commandName + ".js")) {
const file = "../" + dirs + "/" + commandName + ".js";

try {
delete require.cache[require.resolve(file)];
client.commands.delete(commandName);

const pull = require(file);

client.commands.set(commandName, pull);
message.channel.send(client.translate.commands.reload.reloaded.replace("%s", commandName));
} catch (error) {
message.channel.send(client.translate.commands.reload.reload_error.replace("%s", inputCommand.toUpperCase()));
console.log(error.stack || error);
}
}
});
"function": {
"command": {}
}
}

module.exports.interaction = {
"enable": true
}

module.exports.interaction.slash = {
module.exports.function.command = {
"data": {
"name": module.exports.name,
"name_localizations": {
Expand Down
165 changes: 6 additions & 159 deletions source/commands/developer/system.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,173 +3,20 @@ const { version } = require("discord.js");
const { get } = require("systeminformation");

module.exports = {
"enable": true,
"name": "system",
"description": "Get system operating status and more",
"category": "developer",
"permissions": {
"client": [PermissionsBitField.Flags.SendMessages]
}
}

module.exports.command = {
"enable": true,
},
"usage": "system",
"aliases": ["sys", "systeminfo", "ระบบ"],
async execute(client, message, args) {
const msg = await message.channel.send(client.translate.commands.system.loading);

get({
"time": "uptime",
"system": "manufacturer, model",
"bios": "vendor, version, releaseDate",
"cpu": "manufacturer, brand, speed, cores, physicalCores",
"cpuTemperature": "main",
"mem": "total, used",
"battery": "hasBattery, isCharging, percent, type",
"graphics": "controllers, displays",
"osInfo": "platform, arch"
}).then((data) => {
const serverSeconds = (data.time.uptime / 1000);
const serverDays = Math.floor(serverSeconds / (3600 * 24));
const serverHours = Math.floor(serverSeconds % (3600 * 24) / 3600);

const systemManufacturer = data.system.manufacturer;
const systemModel = data.system.model;

const biosVendor = data.bios.vendor;
const biosVersion = data.bios.version;
const biosReleaseDate = data.bios.releaseDate;

const cpuManufacturer = data.cpu.manufacturer;
const cpuBrand = data.cpu.brand;
const cpuSpeed = data.cpu.speed;
const cpuCores = data.cpu.cores;
const cpuPhysicalCores = data.cpu.physicalCores;

const cpuTempMain = data.cpuTemperature.cpuTempMain;

const memUsed = (data.mem.used / 1024 / 1024).toFixed(2);
const memTotal = (data.mem.total / 1024 / 1024).toFixed(2);

const batteryHasBattery = data.battery.hasBattery;
const batteryIsCharging = data.battery.isCharging;
const batteryPercent = data.battery.percent;
const batteryType = data.battery.type;

const gpuControllers = data.graphics.controllers;
const gpuControllersLength = gpuControllers.length;
let gpuMain = "",
gpuMainModel = "",
gpuMainFanSpeed = "",
gpuMainMemoryTotal = "",
gpuMainMemoryUsed = "",
gpuMainTemperatureGpu = "";
for (let i = 0; i < gpuControllersLength; i++) {
gpuMainModel = gpuControllers[i].model;
gpuMainFanSpeed = gpuControllers[i].fanSpeed;
gpuMainMemoryTotal = gpuControllers[i].memoryTotal;
gpuMainMemoryUsed = gpuControllers[i].memoryUsed;
gpuMainTemperatureGpu = gpuControllers[i].temperatureGpu;

gpuMain += ("```" + gpuMainModel + ", " + (gpuMainMemoryUsed ? (gpuMainMemoryTotal ? (gpuMainMemoryUsed + "/" + gpuMainMemoryTotal + "MB") : "") : "") + (gpuMainFanSpeed ? gpuMainFanSpeed + " " : "") + (gpuMainTemperatureGpu ? gpuMainTemperatureGpu : "") + "```");
}

const gpuDisplays = data.graphics.displays;
const gpuDisplaysLength = gpuDisplays.length;
let gpuSecond = "",
gpuSecondModel = "",
gpuSecondMain = "";
for (let i = 0; i < gpuDisplaysLength; i++) {
gpuSecondModel = gpuDisplays[i].model;
gpuSecondMain = gpuDisplays[i].main;

gpuSecond += ("```" + gpuSecondModel + ", " + (gpuSecondMain ? client.translate.commands.system.main : "") + "```");
}

const osPlatform = data.osInfo.platform;
const osArch = data.osInfo.arch;

const clientColor = message.guild.members.me.displayHexColor;
const systemEmbed = new EmbedBuilder()
.setTitle(client.translate.commands.system.info_title)
.setDescription(client.translate.commands.system.info_description)
.setColor(clientColor)
.addFields([
{
"name": "• Discord.js",
"value": "```" + "v" + version + "```",
"inline": true
},
{
"name": "• Node.js",
"value": "```" + process.version + "```",
"inline": true
},
{
"name": client.translate.commands.system.info_uptime.title,
"value": "```" + client.translate.commands.system.info_uptime.info.replace("%s1", serverDays).replace("%s2", serverHours) + "```",
"inline": true
},
{
"name": client.translate.commands.system.info_system,
"value": "```" + (systemManufacturer ? (systemManufacturer + " " + systemModel) : client.translate.commands.system.unknown) + "```",
"inline": true
},
{
"name": "• BIOS",
"value": "```" + (biosVendor ? (biosVendor + " " + biosVersion + ", " + biosReleaseDate) : client.translate.commands.system.unknown) + "```",
"inline": true
},
{
"name": "• CPU",
"value": "```" + (cpuManufacturer ? (cpuManufacturer + " " + cpuBrand + ", " + cpuSpeed + "GHz " + cpuCores + " Cores " + cpuPhysicalCores + " Trades") : client.translate.commands.system.unknown) + "```",
"inline": true
},
{
"name": client.translate.commands.system.info_temperature,
"value": "```" + (cpuTempMain || client.translate.commands.system.unknown) + "```",
"inline": true
},
{
"name": client.translate.commands.system.info_memory_used,
"value": "```" + (memUsed && memTotal ? (memUsed + " / " + memTotal + "MB") : client.translate.commands.system.unknown) + "```",
"inline": true
},
{
"name": client.translate.commands.system.info_battery.title,
"value": "```" + (batteryHasBattery ? (batteryIsCharging ? (client.translate.commands.system.info_battery.charging + " " + batteryPercent + ", " + batteryType || client.translate.commands.system.unknown) : client.translate.commands.system.info_battery.charging + " " + batteryPercent + ", " + batteryType || client.translate.commands.system.unknown) : client.translate.commands.system.info_battery.without) + "```",
"inline": true
},
{
"name": client.translate.commands.system.info_gpu_control,
"value": gpuMain || "```" + client.translate.commands.system.unknown + "```",
"inline": true
},
{
"name": client.translate.commands.system.info_gpu_display,
"value": gpuSecond || "```" + client.translate.commands.system.unknown + "```",
"inline": true
},
{
"name": client.translate.commands.system.info_platform,
"value": "```" + (osPlatform ? (osPlatform + " " + osArch) : client.translate.commands.system.unknown) + "```",
"inline": true
}
]);

msg.edit({
"content": null,
"embeds": [systemEmbed]
});
});
"function": {
"command": {}
}
}

module.exports.interaction = {
"enable": true
}

module.exports.interaction.slash = {
module.exports.function.command = {
"data": {
"name": module.exports.name,
"name_localizations": {
Expand Down Expand Up @@ -330,4 +177,4 @@ module.exports.interaction.slash = {
});
});
}
};
}
38 changes: 6 additions & 32 deletions source/commands/developer/uptime.js
Original file line number Diff line number Diff line change
@@ -1,46 +1,20 @@
const { EmbedBuilder, PermissionsBitField } = require("discord.js");

module.exports = {
"enable": true,
"name": "uptime",
"description": "Displays the bots current uptime!",
"category": "developer",
"permissions": {
"client": [PermissionsBitField.Flags.SendMessages]
}
}

module.exports.command = {
"enable": true,
},
"usage": "uptime",
"aliases": ["uptimes", "เวลา"],
async execute(client, message, args) {
const ms = client.uptime;
const sec = Math.floor((ms / 1000) % 60).toString();
const min = Math.floor((ms / (1000 * 60)) % 60).toString();
const hrs = Math.floor((ms / (1000 * 60 * 60)) % 60).toString();
const days = Math.floor((ms / (1000 * 60 * 60 * 24)) % 60).toString();
const duration = days.padStart(1, "0") + " " + client.translate.commands.uptime.days + " " +
hrs.padStart(2, "0") + " " + client.translate.commands.uptime.hours + " " +
min.padStart(2, "0") + " " + client.translate.commands.uptime.minute + " " +
sec.padStart(2, "0") + " " + client.translate.commands.uptime.second + " ";

const clientColor = message.guild.members.me.displayHexColor;
const uptimeEmbed = new EmbedBuilder()
.setTitle(client.translate.commands.uptime.info_title)
.setDescription("```" + duration + "```")
.setColor(clientColor);

message.channel.send({
"embeds": [uptimeEmbed]
});
"function": {
"command": {}
}
}

module.exports.interaction = {
"enable": true
}

module.exports.interaction.slash = {
module.exports.function.command = {
"data": {
"name": module.exports.name,
"name_localizations": {
Expand Down Expand Up @@ -74,4 +48,4 @@ module.exports.interaction.slash = {
"embeds": [uptimeEmbed]
});
}
};
}
Loading

0 comments on commit 5c6b49e

Please sign in to comment.