Skip to content

Commit

Permalink
🎗️ [1.3.6] - Package update
Browse files Browse the repository at this point in the history
- Updated minecraft-server-util package and changed code for it
- Fixed status command split version function
- KNOWN BUG: Motd result is wrong
- Fixed bot crashing when was server offline (enable warns in the config for knowing if is your server offline)
- Better error handler
- Updated command template
- Better Discord embeds organization in code
  • Loading branch information
PetyXbronCZ committed Dec 7, 2021
1 parent c37a5ac commit 8b95f05
Show file tree
Hide file tree
Showing 6 changed files with 143 additions and 117 deletions.
13 changes: 8 additions & 5 deletions commands/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ module.exports.config = {
};

module.exports.run = async (bot, message) => {
const { server, config } = bot
const { server, config } = bot,
warn = c.keyword('yellow').bold,
warns = config.settings.warns

if(!server.work) return

Expand All @@ -20,13 +22,13 @@ module.exports.run = async (bot, message) => {
icon = server.icon ? server.icon : message.guild.icon

if(server.type === 'java') {
util.status(ip1, { port: port1 })
.then((response) => {
util.status(ip1, port1)
.then((result) => {
const serverEmbed = new Discord.MessageEmbed()
.setAuthor(config.server.name ? config.server.name : message.guild.name, icon)
.setDescription(`:white_check_mark: **ONLINE**`)
.addFields(
{ name: "Players", value: `**${response.onlinePlayers}**/**${response.maxPlayers}**` + (response.samplePlayers ? "\n\`\`\`" + response.samplePlayers.map(p => ` ${p.name} `).join('\n') + "\`\`\`":"") , inline: false },
{ name: "Players", value: `**${result.players.online}**/**${result.players.max}**` + (result.players.sample ? "\n\`\`\`" + result.players.sample.map(p => ` ${p.name} `).join('\n') + "\`\`\`":"") , inline: false },
)
.setColor(config.embeds.color)
message.channel.send({ embeds: [serverEmbed] });
Expand All @@ -38,10 +40,11 @@ module.exports.run = async (bot, message) => {
.setColor(config.embeds.error)
message.channel.send({ embeds: [errorEmbed] });

throw error;
if (warns) console.log(warn(`Error when using command ${module.exports.config.name}! Error:\n`) + error)
});
} else {
//Doesn't work for bedrock edition, sorry.
message.reply('Sorry, but this function is not working for Bedrock servers.')
}

};
57 changes: 28 additions & 29 deletions commands/status.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const { commands, settings } = require("../config");
const util = require('minecraft-server-util');
const Discord = require('discord.js');
const c = require('chalk')

module.exports.config = {
name: "status", //Name of command - RENAME THE FILE TOO!!!
Expand All @@ -10,7 +11,10 @@ module.exports.config = {
};

module.exports.run = async (bot, message) => {
const { server, config } = bot
const { server, config } = bot,
settings = config.settings,
warn = c.keyword('yellow').bold,
warns = config.settings.warns

if(!server.work) return

Expand All @@ -20,13 +24,10 @@ module.exports.run = async (bot, message) => {
icon = server.icon ? server.icon : message.guild.icon

if(server.type === 'java') {
util.status(ip1, { port: port1 })
.then((response) => {
const
description1 = response.description.descriptionText,
description11 = description1.toString().replace(/\u00A7[0-9A-FK-OR]/ig, '')

const versionOriginal = response.version
util.status(ip1, port1)
.then((result) => {
const description11 = result.motd.clean
const versionOriginal = result.version.name
if(settings.split) {
if(versionOriginal.includes("Spigot")) {
var versionAdvanced = versionOriginal.replace("Spigot", "")
Expand All @@ -45,7 +46,7 @@ module.exports.run = async (bot, message) => {
{ name: "Description", value: `${description11}` , inline: false },
{ name: "IP Address", value: `\`${server.ip}\`:\`${server.port}\`` , inline: false },
{ name: "Version", value: `JAVA **${version}**` , inline: true },
{ name: "Players", value: `**${response.onlinePlayers}**/**${response.maxPlayers}**` , inline: true },
{ name: "Players", value: `**${result.players.online}**/**${result.players.max}**` , inline: true },
)
.setColor(config.embeds.color)
message.channel.send({ embeds: [serverEmbed] });
Expand All @@ -57,37 +58,35 @@ module.exports.run = async (bot, message) => {
.setColor(config.embeds.error)
message.channel.send({ embeds: [errorEmbed] });

throw error;
if (warns) console.log(warn(`Error when using command ${module.exports.config.name}! Error:\n`) + error)
});
} else {
util.statusBedrock(ip1, { port: port1 })
.then((response) => {
const
description1 = response.motdLine1.descriptionText + '\n' + response.motdLine2.descriptionText,
description11 = description1.toString().replace(/\u00A7[0-9A-FK-OR]/ig, '')
util.statusBedrock(ip1, port1)
.then((result) => {
const description11 = result.motd.clean

const version = response.version
const version = result.version.name

const serverEmbed = new Discord.MessageEmbed()
.setAuthor(config.server.name ? config.server.name : message.guild.name, icon)
.setDescription(`:white_check_mark: **ONLINE**`)
.addFields(
{ name: "Description", value: `${description11}` , inline: false },
{ name: "IP Address", value: `\`${server.ip}\`:\`${server.port}\`` , inline: false },
{ name: "Version", value: `BEDROCK **${version}**` , inline: true },
{ name: "Players", value: `**${response.onlinePlayers}**/**${response.maxPlayers}**` , inline: true },
)
.setColor('#77fc03')
.setAuthor(config.server.name ? config.server.name : message.guild.name, icon)
.setDescription(`:white_check_mark: **ONLINE**`)
.addFields(
{ name: "Description", value: `${description11}` , inline: false },
{ name: "IP Address", value: `\`${server.ip}\`:\`${server.port}\`` , inline: false },
{ name: "Version", value: `BEDROCK **${version}**` , inline: true },
{ name: "Players", value: `**${result.players.online}**/**${result.players.max}**` , inline: true },
)
.setColor('#77fc03')
message.channel.send({ embeds: [serverEmbed] });
})
.catch((error) => {
const errorEmbed = new Discord.MessageEmbed()
.setAuthor(config.server.name ? config.server.name : message.guild.name, icon)
.setDescription(':x: **OFFLINE**')
.setColor('#f53636')
.setAuthor(config.server.name ? config.server.name : message.guild.name, icon)
.setDescription(':x: **OFFLINE**')
.setColor('#f53636')
message.channel.send({ embeds: [errorEmbed] });

throw error;
if (warns) console.log(warn(`Error when using command ${module.exports.config.name}! Error:\n`) + error)
});
}

Expand Down
8 changes: 4 additions & 4 deletions commands/version.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ module.exports.run = async (bot, message, args) => {

if(server.type === 'java') {
try {
const response = await util.status(server.ip, { port: server.port })
var versionOriginal = response.version;
const result = await util.status(server.ip, server.port)
var versionOriginal = result.version.name
} catch(e) {
if (warns) console.log(warn(`Couldn't get version from server! Getting it from config..`))
var versionOriginal = config.server.version;
Expand All @@ -50,8 +50,8 @@ module.exports.run = async (bot, message, args) => {
message.channel.send({ embeds: [versionEmbed] });
} else {
try {
const response = await util.statusBedrock(server.ip, { port: server.port })
var versionOriginal = response.version
const result = await util.statusBedrock(server.ip, server.port)
var versionOriginal = result.version.name
} catch(e) {
if (warns) console.log(warn(`Couldn't get version from server! Getting it from config..`))
var versionOriginal = config.server.version
Expand Down
Loading

0 comments on commit 8b95f05

Please sign in to comment.