Skip to content

Commit

Permalink
💐 [1.6.0] - Discord presence update
Browse files Browse the repository at this point in the history
- Added more maintenance mode compatibility
- Edited starting scripts and updated developer testing start method
- Updated dependencies and engines versions
- Updated file URLs of gifs and images in README.md with some other updates
- Added help command
- Added choice to set bot status (online. idle, dnd. invisible) [CONFIG UPDATE!]
- Auto updating bot's status now updates immediately after bot start
  • Loading branch information
PetyXbronCZ committed Jun 30, 2022
1 parent c3e5fca commit d923e9d
Show file tree
Hide file tree
Showing 9 changed files with 246 additions and 47 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,4 @@ package-lock.json

test/
dev-config.js
dev-index.js
json.sqlite
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
## [DOCUMENTATION HERE 🔗](https://petyxbron.gitbook.io/minecraft-bot/installation)

# Custom Discord Minecraft bot
### *Get info about your minecraft server with this Discord bot!*
### *Get info about your Minecraft server with this Discord bot!*

[![Repo stars](https://img.shields.io/github/stars/PetyXbron/minecraft-bot?style=flat&logo=github&labelColor=232121&color=blue&label=Stars)](https://github.com/PetyXbron/minecraft-bot/stargazers) [![Repo forks](https://img.shields.io/github/forks/PetyXbron/minecraft-bot?style=flat&logo=github&labelColor=232121&color=blue&label=Forks)](https://github.com/PetyXbron/minecraft-bot/network) [![Repo license](https://img.shields.io/github/license/PetyXbron/minecraft-bot?style=flat&logo=github&labelColor=232121&color=blue&label=License)](https://github.com/PetyXbron/minecraft-bot/blob/main/LICENSE)

Expand All @@ -15,6 +15,7 @@ This code uses **Minecraft server util package** for getting status of Minecraft

- **Fully customizable [config](config.js)**
- Working **commands** with **custom prefix** + their **[slash commands]((https://support.discord.com/hc/en-us/articles/1500000368501-Slash-Commands-FAQ))**
- `help` command for getting help menu (list of all user-available commands)
- `ip` command for getting IP address of server
- `list` command for getting actual list of online players now
- `status` command for getting simple and clear overview of server
Expand All @@ -25,9 +26,10 @@ This code uses **Minecraft server util package** for getting status of Minecraft
![Auto updating bot status](https://i.imgur.com/xNDVb2D.png)
![Bot status config variables](https://i.imgur.com/7TXaWTC.png)
- More Discord bot activites: `playing`, `listening`, `watching` and `competing`
- More Discord bot statuses: `online`, `idle`, `dnd` and `invsible`
- **Poll/Voting channel** with reactions

![Voting channel](https://4254518267-files.gitbook.io/~/files/v0/b/gitbook-28427.appspot.com/o/assets%2F-MbqA4Jea2-IO37rpuOb%2F-MejM8GdpoTFx3MovYuy%2F-MejY9Dg6WsJ5LJ7qIVO%2Fvoting-channel.gif?alt=media&token=2a1d71d6-7544-4ba4-a6ff-f468872121c6)
![Voting channel](https://i.imgur.com/OfCxqhf.gif)
- Custom responses for each command, editable in [config file](config.js)
- **Auto updating status message** with player list

Expand All @@ -37,7 +39,7 @@ This code uses **Minecraft server util package** for getting status of Minecraft
![Random embed color](https://i.imgur.com/pA7h5rC.png)
- **Clear colorful console** logging

![minecraft-bot console](https://i.imgur.com/N17AfDn.png)
![minecraft-bot console](https://i.imgur.com/TyTCsQv.png)

## HOW TO USE & INSTALL

Expand All @@ -60,8 +62,8 @@ This code uses **Minecraft server util package** for getting status of Minecraft
- [x] <s>More text languages (or custom)</s>
- [x] <s>Bot status (activity) for players online number</s>
- [x] <s>Get invite link on bot start (available option in config)</s>
- [x] <s>Help command with all commands listing</s>
- [ ] Poll/Voting command (simple or with more options)
- [ ] Help command with all commands listing
- [ ] Server AdminTeam applications
- [ ] Send custom embed message command
- [ ] Send custom message/announcement command
Expand Down
77 changes: 77 additions & 0 deletions commands/help.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
const { commands } = require("../config");;
const { MessageEmbed } = require('discord.js');
const fs = require('fs');

module.exports.config = {
name: "help", //Name of command - RENAME THE FILE TOO!!!
description: "Sends the command list menu", //Description of command - you can change it :)
aliases: commands.help, //Command's aliases - set them in config.js
enable: true //Enable this command? - true or false (boolean)
};

module.exports.run = async (bot, message, args) => {
const { server, config, text } = bot;
let icon = server.icon ? server.icon : message.guild.iconURL();

if (!args[0]) {
let commands = [],
lines = [];

commands = fs.readdirSync(`./commands`).filter(file => file.endsWith('.js'));

for (const commandFile of commands) {
const command = bot.commands.get(commandFile.split(".js")[0]);
command.config.description = command.config.description ? command.config.description : false;
if (commands.length > 0) lines.push(`> \`${bot.prefix}${command.config.name ? command.config.name : commandFile.split(".js")[0]}\`` + (command.config.description ? ` - ${command.config.description}` : ""));
}

if (!text.help.title || !text.help.description) {
const helpEmbed = new MessageEmbed()
.setAuthor({ name: config.server.name ? config.server.name : message.guild.name, iconURL: icon })
.setTitle(config.server.name ? config.server.name : message.guild.name + " bot commands:")
.setDescription(`> **Prefix:** \`${bot.prefix}\`\n\n> **Commands:**\n` + lines.join("\n"))
.setColor(config.embeds.color);
message.channel.send({ embeds: [helpEmbed] });
} else {
text.help.title = text.help.title.replaceAll('{serverIp}', server.ip);
text.help.title = text.help.title.replaceAll('{serverPort}', server.port);
text.help.title = text.help.title.replaceAll('{serverName}', config.server.name ? config.server.name : message.guild.name);
text.help.title = text.help.title.replaceAll('{voteLink}', config.server.vote);
text.help.title = text.help.title.replaceAll('{serverType}', config.server.type.charAt(0).toUpperCase() + config.server.type.slice(1));
text.help.title = text.help.title.replaceAll('{prefix}', config.bot.prefix);
text.help.title = text.help.title.replaceAll('{commands}', "\n" + lines.join("\n"));

text.help.description = text.help.description.replaceAll('{serverIp}', server.ip);
text.help.description = text.help.description.replaceAll('{serverPort}', server.port);
text.help.description = text.help.description.replaceAll('{serverName}', config.server.name ? config.server.name : message.guild.name);
text.help.description = text.help.description.replaceAll('{voteLink}', config.server.vote);
text.help.description = text.help.description.replaceAll('{serverType}', config.server.type.charAt(0).toUpperCase() + config.server.type.slice(1));
text.help.description = text.help.description.replaceAll('{prefix}', config.bot.prefix);
text.help.description = text.help.description.replaceAll('{commands}', "\n" + lines.join("\n"));

const helpEmbed = new MessageEmbed()
.setAuthor({ name: config.server.name ? config.server.name : message.guild.name, iconURL: icon })
.setTitle(text.help.title)
.setDescription(text.help.description)
.setColor(config.embeds.color);
message.channel.send({ embeds: [helpEmbed] });
}
return;
}

if (bot.commands.has(args[0].toLocaleLowerCase()) || bot.aliases.has(args[0].toLocaleLowerCase())) {
commandName = bot.commands.has(args[0].toLocaleLowerCase()) ? args[0].toLocaleLowerCase() : bot.aliases.get(args[0].toLocaleLowerCase());

let command = bot.commands.get(commandName);

const helpEmbed = new MessageEmbed()
.setAuthor({ name: config.server.name ? config.server.name : message.guild.name, iconURL: icon })
.setTitle(`${commandName.charAt(0).toUpperCase() + commandName.slice(1)} Command:`)
.setDescription(`
> **Description:** ${!!command.config.description ? command.config.description : "Without description"}
> **Aliases:** ${!!command.config.aliases ? "`" + bot.prefix + command.config.aliases.join(`\`, \`${bot.prefix}`) + "`" : "No aliases"}
`)
.setColor(config.embeds.color);
return message.channel.send({ embeds: [helpEmbed] });
}
};
16 changes: 14 additions & 2 deletions commands/status.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ module.exports.run = async (bot, message) => {
let versionOriginal = result.version.name,
versionAdvanced = false;

let maintenceStatus = false,
lowCaseMotdClean = result.motd.clean.toLocaleLowerCase();
if (lowCaseMotdClean.includes("maintenance")) maintenceStatus = true;

if (settings.split) {
versionAdvanced = versionOriginal.toLocaleLowerCase()
.replace("bukkit ", "")
Expand Down Expand Up @@ -63,7 +67,7 @@ module.exports.run = async (bot, message) => {
const serverEmbed = new Discord.MessageEmbed()
.setAuthor({ name: config.server.name ? config.server.name : message.guild.name, iconURL: icon })
.setTitle("Server status:")
.setDescription(`:white_check_mark: **ONLINE**
.setDescription(`${maintenceStatus ? ":construction_worker: **MAINTENANCE**" : ":white_check_mark: **ONLINE**"}
**Description**
${result.motd.clean}
Expand All @@ -88,6 +92,7 @@ module.exports.run = async (bot, message) => {
text.status.title = text.status.title.replaceAll('{playersMax}', result.players.max);
text.status.title = text.status.title.replaceAll('{motd}', result.motd.clean);
text.status.title = text.status.title.replaceAll('{serverVersion}', version);
text.status.title = text.status.title.replaceAll('{status}', maintenceStatus ? ":construction_worker: **MAINTENANCE**" : ":white_check_mark: **ONLINE**");

text.status.description = text.status.description.replaceAll('{serverIp}', server.ip);
text.status.description = text.status.description.replaceAll('{serverPort}', server.port);
Expand All @@ -98,6 +103,7 @@ module.exports.run = async (bot, message) => {
text.status.description = text.status.description.replaceAll('{playersMax}', result.players.max);
text.status.description = text.status.description.replaceAll('{motd}', result.motd.clean);
text.status.description = text.status.description.replaceAll('{serverVersion}', version);
text.status.description = text.status.description.replaceAll('{status}', maintenceStatus ? ":construction_worker: **MAINTENANCE**" : ":white_check_mark: **ONLINE**");

const serverEmbed = new Discord.MessageEmbed()
.setAuthor({ name: config.server.name ? config.server.name : message.guild.name, iconURL: icon })
Expand All @@ -123,6 +129,10 @@ module.exports.run = async (bot, message) => {
const versionOriginal = result.version.name;
let versionAdvanced = false;

let maintenceStatus = false,
lowCaseMotdClean = result.motd.clean.toLocaleLowerCase();
if (lowCaseMotdClean.includes("maintenance")) maintenceStatus = true;

if (settings.split) {
versionAdvanced = versionOriginal.toLocaleLowerCase()
.replace("bukkit ", "")
Expand Down Expand Up @@ -157,7 +167,7 @@ module.exports.run = async (bot, message) => {
const serverEmbed = new Discord.MessageEmbed()
.setAuthor({ name: config.server.name ? config.server.name : message.guild.name, iconURL: icon })
.setTitle("Server status:")
.setDescription(`:white_check_mark: **ONLINE**
.setDescription(`:white_check_mark: ${maintenceStatus ? ":construction_worker: **MAINTENANCE**" : ":white_check_mark: **ONLINE**"}
**Description**
${result.motd.clean}
Expand All @@ -182,6 +192,7 @@ module.exports.run = async (bot, message) => {
text.status.title = text.status.title.replaceAll('{playersMax}', result.players.max);
text.status.title = text.status.title.replaceAll('{motd}', result.motd.clean);
text.status.title = text.status.title.replaceAll('{serverVersion}', version);
text.status.title = text.status.title.replaceAll('{status}', maintenceStatus ? ":construction_worker: **MAINTENANCE**" : ":white_check_mark: **ONLINE**");

text.status.description = text.status.description.replaceAll('{serverIp}', server.ip);
text.status.description = text.status.description.replaceAll('{serverPort}', server.port);
Expand All @@ -192,6 +203,7 @@ module.exports.run = async (bot, message) => {
text.status.description = text.status.description.replaceAll('{playersMax}', result.players.max);
text.status.description = text.status.description.replaceAll('{motd}', result.motd.clean);
text.status.description = text.status.description.replaceAll('{serverVersion}', version);
text.status.description = text.status.description.replaceAll('{status}', maintenceStatus ? ":construction_worker: **MAINTENANCE**" : ":white_check_mark: **ONLINE**");

const serverEmbed = new Discord.MessageEmbed()
.setAuthor({ name: config.server.name ? config.server.name : message.guild.name, iconURL: icon })
Expand Down
3 changes: 2 additions & 1 deletion config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ module.exports = {
bot: {
token: '', //Your bot token - https://tinyurl.com/discordbot-token
prefix: '', //Your custom prefix of the bot, like "!" or "."
status: '', //Custom activity/status text
presence: '', //Custom activity/status text
status: '', //You can choose: ONLINE, IDLE, DND (do not disturb), INVISIBLE
activity: '' //You can choose: PLAYING, LISTENING, WATCHING, COMPETING
},

Expand Down
41 changes: 22 additions & 19 deletions events/ready.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@ module.exports = async (bot) => {
const debug = config.settings.debug;
var warns = config.settings.warns;

if (bot.status) {
if (bot.status.includes("{onlinePlayers}") | bot.status.includes("{maxPlayers}")) {
setInterval(async () => {
let status = bot.status;
if (bot.pres) {
let presence = config.bot.presence,
status = config.bot.status.toLowerCase(),
activity = config.bot.activity.toUpperCase();
if (bot.pres.includes("{onlinePlayers}") | bot.pres.includes("{maxPlayers}")) {
async function autoUpdatingPresence() {
let errored = false,
result = undefined;

Expand All @@ -38,35 +40,36 @@ module.exports = async (bot) => {
};

if (!errored) {
if (status.includes("{onlinePlayers}")) {
status = status.replaceAll("{onlinePlayers}", result.players.online);
if (presence.includes("{onlinePlayers}")) {
presence = presence.replaceAll("{onlinePlayers}", result.players.online);
};

if (status.includes("{maxPlayers}")) {
status = status.replaceAll("{maxPlayers}", result.players.max);
if (presence.includes("{maxPlayers}")) {
presence = presence.replaceAll("{maxPlayers}", result.players.max);
};

try {
bot.user.setActivity(status, { type: bot.activity }); //Sets bot activity
if (debug) console.log(`${bot.emotes.success} Successfully set status to ` + gr(`${bot.activity.toLowerCase()} ${status}`));
bot.user.setPresence({ activities: [{ name: presence }], status: status, type: activity, afk: false }); //Sets bot activity
if (debug) console.log(`${bot.emotes.success} Successfully set presence to ` + gr(`${bot.activity.toLowerCase()} ${presence}`));
} catch (e) {
console.log();
}
} else {
const status = "Offline";
const presence = "Offline";
try {
bot.user.setActivity(status, { type: bot.activity }); //Sets bot activity
if (debug) console.log(`${bot.emotes.warn} ` + warn('Server was not found! Status set to ') + gr(`${bot.activity.toLowerCase()} ${status}`));
bot.user.setPresence({ activities: [{ name: presence }], status: status, type: activity, afk: false }); //Sets bot activity
if (debug) console.log(`${bot.emotes.warn} ` + warn('Server was not found! Presence set to ') + gr(`${bot.activity.toLowerCase()} ${presence}`));
} catch (e) {
console.log();
}
}

}, ms(config.autoStatus.time));
}
autoUpdatingPresence()
setInterval(autoUpdatingPresence, ms(config.autoStatus.time));
} else {
try {
bot.user.setActivity(bot.status, { type: bot.activity }); //Sets bot activity
console.log(`${bot.emotes.success} Successfully set status to ` + gr(`${bot.activity.toLowerCase()} ${bot.status}`));
bot.user.setPresence({ activities: [{ name: presence }], status: status, type: activity, afk: false }); //Sets bot activity
if (debug) console.log(`${bot.emotes.success} Successfully set presence to ` + gr(`${bot.activity.toLowerCase()} ${bot.pres}`));
} catch (e) {
console.log();
}
Expand Down Expand Up @@ -377,7 +380,7 @@ module.exports = async (bot) => {
if (server.type === 'java') {
util.status(server.ip, server.port)
.then((result) => {
console.log(`${bot.emotes.success} Successfully located ${gr(server.type)} server ${gr(server.ip)}!\n` + " " + gr('Server info:\n')
console.log(`${bot.emotes.success} Successfully located ${gr(server.type.toUpperCase())} server ${gr(server.ip)}!\n` + " " + gr('Server info:\n')
+ " " + bold('IP: ') + bl(`${server.ip}:${result.port ? result.port : server.port}\n`)
+ " " + bold('VERSION: ') + bl(`${result.version.name ? result.version.name : 'unknown'}\n`)
+ " " + bold('PLAYERS: ') + bl(`${result.players.online ? result.players.online : '0'}` + '/' + `${result.players.max ? result.players.max : '0'}`)
Expand All @@ -389,7 +392,7 @@ module.exports = async (bot) => {
} else if (server.type === 'bedrock') {
util.statusBedrock(server.ip, server.port)
.then((result) => {
console.log(`${bot.emotes.success} Successfully located ${gr(server.type)} server ${gr(server.ip)}!\n` + " " + gr('Server info:\n')
console.log(`${bot.emotes.success} Successfully located ${gr(server.type.toUpperCase())} server ${gr(server.ip)}!\n` + " " + gr('Server info:\n')
+ " " + bold('IP: ') + bl(`${server.ip}:${result.port ? result.port : server.port}\n`)
+ " " + bold('VERSION: ') + bl(`${result.version.name ? result.version.name : 'unknown'}\n`)
+ " " + bold('PLAYERS: ') + bl(`${result.players.online ? result.players.online : '0'}` + '/' + `${result.players.max ? result.players.max : '0'}`)
Expand Down
Loading

0 comments on commit d923e9d

Please sign in to comment.