-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
82 lines (67 loc) · 3.68 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
const { Client, Intents, MessageEmbed, MessageActionRow, MessageButton } = require('discord.js');
const { token, channelID, ip, port } = require('./config.json');
const Gamedig = require('gamedig');
const cliente = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES] });
let mensajeEstado, canal;
cliente.on('ready', async () => {
console.log(`Iniciado sesión como: ${cliente.user.tag}!`);
canal = cliente.channels.cache.get(channelID);
try {
const mensajes = await canal.messages.fetch({ limit: 10 });
mensajeEstado = mensajes.find(msg => msg.author.id === cliente.user.id);
if (!mensajeEstado) {
mensajeEstado = await canal.send('🤔');
}
console.log('La aplicación se ha iniciado.');
} catch (error) {
console.error(error);
}
actualizarEstadoServidor();
setInterval(actualizarEstadoServidor, 60000);
});
async function actualizarEstadoServidor() {
try {
const estado = await Gamedig.query({ type: 'garrysmod', host: ip, port });
const jugadoresConectando = estado.players.filter(player => !player.name || player.name === "Conectando ...");
const otrosJugadores = estado.players.filter(player => player.name && player.name !== "Conectando ...");
const listaJugadores = otrosJugadores.map(player => `🔹 ${player.name}`).join('\n') +
(jugadoresConectando.length > 0 ? `\n🔹 Hay ${jugadoresConectando.length} usuarios conectando ...` : "");
const embedEstado = new MessageEmbed()
.setTitle(`🟢 GenosRP | Un servidor de Roleplay Mágico`)
.setDescription("*¡Bienvenido/a a nuestro servidor de Garry's Mod!\nAquí encontrarás una comunidad amigable y muchas aventuras emocionantes.\n¡Únete ahora y conviértete en el mejor mago o bruja!*")
.setColor("#5ad65c")
.setImage('https://i.imgur.com/WXRppSR.png')
.addFields(
{ name: "\u200B", value: "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n\u200B" },
{ name: `👥 ┃ Jugadores conectados: \`${estado.raw.numplayers}/${estado.maxplayers}\``, value: listaJugadores || "🔸 No hay nadie en el servidor. 😴" },
{ name: "\u200B", value: "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n\u200B" },
{ name: "📡 ┃ Copia y pega esto en tu navegador para jugar:", value: `\`\`\`steam://connect/${ip}:${port}\`\`\`` }
)
.setFooter({ text: 'Actualizado:' })
.setTimestamp();
const filaBotones = new MessageActionRow()
.addComponents(
new MessageButton()
.setLabel('Conectar al Servidor')
.setURL('https://tinyurl.com/genosrp')
.setEmoji('🚀')
.setStyle('LINK')
)
.addComponents(
new MessageButton()
.setLabel('Página web')
.setURL('https://genos.nn.pe')
.setEmoji('🌐')
.setStyle('LINK')
);
await mensajeEstado.edit({ content: null, embeds: [embedEstado], components: [filaBotones] });
} catch (error) {
const embedEstadoApagado = new MessageEmbed()
.setTitle("🔴 SERVIDOR APAGADO")
.setColor("#d65a5a")
.setFooter({ text: 'Actualizado:' })
.setTimestamp();
await mensajeEstado.edit({ content: null, embeds: [embedEstadoApagado], components: [] });
}
}
cliente.login(token);