diff --git a/bot.js b/bot.js index 224d75e..c4ffce2 100644 --- a/bot.js +++ b/bot.js @@ -13,6 +13,17 @@ const client = new Client({ initializationMoonlink(client); client.commands = new Collection(); +client.status = "online"; + +process.on("message", (message) => { + if (message && message.operation) { + if (message.operation == "offline") { + client.status = "dnd"; + } else if (message.operation == "online") { + client.status = "online"; + } + } +}); const functions = fs.readdirSync("./functions").filter(file => file.endsWith(".js")); const eventFiles = fs.readdirSync("./events").filter(file => file.endsWith(".js")); diff --git a/events/interactionCreate.js b/events/interactionCreate.js index ed35150..421e001 100644 --- a/events/interactionCreate.js +++ b/events/interactionCreate.js @@ -93,6 +93,17 @@ module.exports = { async execute(interaction, client) { const locale = new Locale(interaction.locale); + if (client.status != "online") { + return await interaction.reply({ + embeds: [ + new EmbedBuilder() + .setColor(Colors.Red) + .setTitle(locale.getLocaleString("interaction.client.notOnline")) + ], + ephemeral: true + }); + } + await handleInteraction(interaction, client, locale); try { diff --git a/events/ready.js b/events/ready.js index b464a96..e6a665a 100644 --- a/events/ready.js +++ b/events/ready.js @@ -21,9 +21,14 @@ module.exports = { "šŸŽµ /play to play song", ]; - client.user.setActivity({ - name: status[currentStatus], - type: ActivityType.Custom + client.user.setPresence({ + status: client.status, + activities: [ + { + name: status[currentStatus], + type: ActivityType.Custom + } + ] }); if (currentStatus >= status.length - 1) { @@ -37,7 +42,7 @@ module.exports = { console.log(`[${client.shard.ids}] Ready! Logged in as ${client.user.tag}`); console.log(`[${client.shard.ids}] Server Count: ${client.guilds.cache.size.toLocaleString()}`); - + console.log(`[${client.shard.ids}] Member Count: ${client.guilds.cache.reduce((acc, guild) => acc + guild.memberCount, 0).toLocaleString()}`); setInterval(setActivity, 5 * 1000); if (mongoDBUrl) { diff --git a/index.js b/index.js index f3a3a2d..84482f0 100644 --- a/index.js +++ b/index.js @@ -3,6 +3,7 @@ const { REST } = require("@discordjs/rest"); const { Routes } = require("discord-api-types/v10"); const express = require("express"); const cors = require("cors"); +const readline = require("readline"); const handleCommands = require("./utils/commands"); const package = require("./package.json"); @@ -116,4 +117,44 @@ require("dotenv").config(); api.listen(port, () => { console.log(`\n\nšŸš€ Status page server is running at http://localhost:${port}/status\n\n`); }); + + // Handle Console Input + const rl = readline.createInterface({ + input: process.stdin, + output: process.stdout + }); + + rl.on("line", async (input) => { + const cmdCommand = input.trim().toLowerCase(); + + switch (cmdCommand) { + case 'offline': { + console.log("šŸ›‘ Soft Offline all shards..."); + await manager.broadcast({ operation: "offline", value: true }); + console.log("āœ… All shards soft offline successfully."); + break; + } + case 'online': { + console.log("🟢 Online all shards..."); + await manager.broadcast({ operation: "online", value: true }); + console.log("āœ… All shards online successfully."); + break; + } + case 'restart': { + console.log("šŸ”„ Restarting all shards...") + try { + // Restart all shards + await manager.respawnAll(); + console.log("āœ… All shards restarted successfully."); + } catch (error) { + console.error("āŒ Error while restarting shards:", error); + } + break; + } + default: { + console.log(`Unknown command: ${input}`); + break; + } + } + }); })(); \ No newline at end of file diff --git a/locales/en-US.json b/locales/en-US.json index d3f8d9e..a69a4c6 100644 --- a/locales/en-US.json +++ b/locales/en-US.json @@ -120,5 +120,6 @@ "command.setting.search.saved": "šŸ’¾ Saved default source with `{0}`", "command.setting.search.save.fail": "āŒ Fail to save default source with `{0}`", "youtube.direct.disable.text": "# Want to listen to music directly from YouTube?\nYou can easily order through the HStudio website\n\n**[Support Discord](https://discord.gg/GzTbuZHTEx)**", - "youtube.direct.disable.button.text": "Buy now" + "youtube.direct.disable.button.text": "Buy now", + "interaction.client.notOnline": "āŒ The bot is not online" } \ No newline at end of file