mirror of
https://github.com/thedrewen/protojx-manager.git
synced 2026-03-21 01:48:54 +01:00
Add /status.
This commit is contained in:
19
package-lock.json
generated
19
package-lock.json
generated
@@ -9,8 +9,10 @@
|
||||
"version": "1.0.0",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@types/ping": "^0.4.4",
|
||||
"discord.js": "^14.24.0",
|
||||
"dotenv": "^17.2.2"
|
||||
"dotenv": "^17.2.2",
|
||||
"ping": "^1.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"typescript": "^5.9.2"
|
||||
@@ -185,6 +187,12 @@
|
||||
"undici-types": "~7.16.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@types/ping": {
|
||||
"version": "0.4.4",
|
||||
"resolved": "https://registry.npmjs.org/@types/ping/-/ping-0.4.4.tgz",
|
||||
"integrity": "sha512-ifvo6w2f5eJYlXm+HiVx67iJe8WZp87sfa683nlqED5Vnt9Z93onkokNoWqOG21EaE8fMxyKPobE+mkPEyxsdw==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/@types/ws": {
|
||||
"version": "8.18.1",
|
||||
"resolved": "https://registry.npmjs.org/@types/ws/-/ws-8.18.1.tgz",
|
||||
@@ -276,6 +284,15 @@
|
||||
"integrity": "sha512-ThQLOhN86ZkJ7qemtVRGYM+gRgR8GEXNli9H/PMvpnZsE44Xfh3wx9kGJaldg314v85m+bFW6WBMaVHJc/c3zA==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/ping": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/ping/-/ping-1.0.0.tgz",
|
||||
"integrity": "sha512-3dxdgGtV+7P/EVo42JhkGSomeO/0GGicSz3mI/yK+AI+VGNAOfakw5XfcbGI4IjyBY+ZZwvuRXdhnNF2uliKew==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">=22.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/ts-mixer": {
|
||||
"version": "6.0.4",
|
||||
"resolved": "https://registry.npmjs.org/ts-mixer/-/ts-mixer-6.0.4.tgz",
|
||||
|
||||
@@ -27,7 +27,9 @@
|
||||
"typescript": "^5.9.2"
|
||||
},
|
||||
"dependencies": {
|
||||
"@types/ping": "^0.4.4",
|
||||
"discord.js": "^14.24.0",
|
||||
"dotenv": "^17.2.2"
|
||||
"dotenv": "^17.2.2",
|
||||
"ping": "^1.0.0"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { ApplicationIntegrationType, CommandInteraction, InteractionContextType, SlashCommandBuilder } from "discord.js";
|
||||
import { ApplicationIntegrationType, ChatInputCommandInteraction, CommandInteraction, InteractionContextType, SlashCommandBuilder } from "discord.js";
|
||||
|
||||
export default {
|
||||
data: new SlashCommandBuilder()
|
||||
@@ -13,7 +13,7 @@ export default {
|
||||
InteractionContextType.Guild,
|
||||
InteractionContextType.PrivateChannel
|
||||
),
|
||||
async execute(interaction : CommandInteraction) {
|
||||
async execute(interaction : ChatInputCommandInteraction) {
|
||||
await interaction.reply('Pong !');
|
||||
}
|
||||
}
|
||||
83
src/commands/utility/statut.ts
Normal file
83
src/commands/utility/statut.ts
Normal file
@@ -0,0 +1,83 @@
|
||||
import { ApplicationIntegrationType, ChatInputCommandInteraction, CommandInteraction, EmbedBuilder, InteractionContextType, SlashCommandBuilder } from "discord.js";
|
||||
import ping from "ping";
|
||||
|
||||
export default {
|
||||
data: new SlashCommandBuilder()
|
||||
.setName('status')
|
||||
.setDescription('Give statut of servers.')
|
||||
.setIntegrationTypes(
|
||||
ApplicationIntegrationType.GuildInstall,
|
||||
ApplicationIntegrationType.UserInstall
|
||||
)
|
||||
.setContexts(
|
||||
InteractionContextType.BotDM,
|
||||
InteractionContextType.Guild,
|
||||
InteractionContextType.PrivateChannel
|
||||
),
|
||||
async execute(interaction : ChatInputCommandInteraction) {
|
||||
await interaction.deferReply();
|
||||
|
||||
const hosts : {host: string, name: string, alive: boolean, type: 'ping' | 'website'}[] = [
|
||||
{
|
||||
'host': 'https://protojx.com',
|
||||
'name': 'Protojx Website 🌐',
|
||||
alive: false,
|
||||
type: 'website'
|
||||
},
|
||||
{
|
||||
'host': 'https://manager.protojx.com',
|
||||
'name': 'Espace Client 💻',
|
||||
alive: false,
|
||||
type: 'website'
|
||||
},
|
||||
{
|
||||
host: 'node.thedrewen.com',
|
||||
name: 'Ryzen 9 (Unknow ID) 🖥️',
|
||||
alive: false,
|
||||
type: 'ping'
|
||||
},
|
||||
{
|
||||
host: 'node.under-scape.com',
|
||||
name: 'Xeon (Unknow ID) 🖥️',
|
||||
alive: false,
|
||||
type: 'ping'
|
||||
},
|
||||
{
|
||||
host: 'panel.protojx.com',
|
||||
name: 'Game Ryzen 👾',
|
||||
alive: false,
|
||||
type: 'ping'
|
||||
}
|
||||
]
|
||||
|
||||
async function fetchAlive(host: {host: string, name: string, alive: boolean, type: 'ping' | 'website'}) {
|
||||
if(host.type === 'ping'){
|
||||
let res = await ping.promise.probe(host.host, {timeout: 3});
|
||||
host.alive = res.alive;
|
||||
}else if(host.type === 'website'){
|
||||
try {
|
||||
const response = await fetch(host.host, { method: 'HEAD', signal: AbortSignal.timeout(3000) });
|
||||
host.alive = response.ok;
|
||||
} catch (error) {
|
||||
host.alive = false;
|
||||
}
|
||||
}
|
||||
return host;
|
||||
}
|
||||
|
||||
const fetchPromises = hosts.map(host => fetchAlive(host));
|
||||
const hosts_ = await Promise.all(fetchPromises);
|
||||
|
||||
const embed = new EmbedBuilder();
|
||||
embed.setTitle('Status of protojx servers');
|
||||
embed.setColor(0xffffff);
|
||||
embed.setTimestamp(new Date());
|
||||
embed.setThumbnail(interaction.client.user.avatarURL())
|
||||
|
||||
for(let host of hosts_){
|
||||
embed.addFields({name: host.name, value: host.alive ? '<a:online:1432684754276323431> Online' : '<a:offline:1432684900175183882> Offline', inline: false});
|
||||
}
|
||||
|
||||
await interaction.editReply({embeds: [embed]});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user