Skip to content

Commit

Permalink
🧨 [1.7.0] - Updated the MC server API (#22)
Browse files Browse the repository at this point in the history
- Added enableNormals option (settable in the config file)
- Created data.json file
- Removed quick.db and replaced it with pure JSON saving (node.js fs function) (closes #19, fixes #3, fixes #10)
- Changed license from MIT to GPL-3.0
- Renamed "split" settings to "removeServerType" and moved the code to the functions.js file
- Added "deleteOther" feature for votingCH feature
- Added "install-cmd" to the package.json file
- Updated the  API for getting the live Minecraft server info (removed minecraft-server-util & minecraft-motd-util and installed axios for HTTP GET method)
- Using https://mcstatus.io/ API (from the same author)
  • Loading branch information
PetyXbron authored Apr 9, 2023
1 parent 12eb91b commit 90a0db0
Show file tree
Hide file tree
Showing 22 changed files with 1,197 additions and 732 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ package-lock.json

test/
dev-config.js
json.sqlite
dev-data.json
6 changes: 4 additions & 2 deletions .replit
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
run = "npm start"
language = "nodejs-npm"
entrypoint = "index.js"
onBoot = "npm install"
language = "nodejs"
run = "npm start"
hidden = ".gitignore"
695 changes: 674 additions & 21 deletions LICENSE

Large diffs are not rendered by default.

68 changes: 39 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,71 +1,81 @@
## [DOCUMENTATION HERE 🔗](https://petyxbron.gitbook.io/minecraft-bot/installation)
## [DOWNLOAD LATEST .ZIP 🔗](https://github.com/PetyXbron/minecraft-bot/archive/refs/heads/main.zip)
## [🔗 DOCUMENTATION HERE](https://petyxbron.gitbook.io/minecraft-bot/installation)
## [🔗 DOWNLOAD LATEST MAIN .ZIP](https://github.com/PetyXbron/minecraft-bot/archive/refs/heads/main.zip)
## [🔗 JOIN DISCORD SUPPORT SERVER](https://discord.com/invite/PYTqqhWad2)

# <img src="https://imgur.com/2L1l0lk.png" width="40" height="40"/>Custom Discord Minecraft bot<img src="https://imgur.com/2L1l0lk.png" width="40" height="40"/>
### *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) [![Latest Version](https://img.shields.io/github/package-json/v/PetyXbron/minecraft-bot?color=blue&label=Version&labelColor=232121&logo=github&sort=semver&style=flat)](https://github.com/PetyXbron/minecraft-bot/tree/main/) [![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)

This code uses **Minecraft server util package** for getting status of Minecraft servers
* minecraft-server-util package
* [Github Repository](https://github.com/PassTheMayo/minecraft-server-util)
* [npmjs Package](https://www.npmjs.com/package/minecraft-server-util)
* [Author Github Profile](https://github.com/PassTheMayo)
**This project uses MSC API ([mcstatus.io](https://mcstatus.io)) for getting status of Minecraft servers.**

## REQUIREMENTS
- **Need to install:**
- [Node.js](https://nodejs.org/en/about) v16.9.0 or higher *([download here](https://nodejs.org/en/download))*
- [NPM](https://docs.npmjs.com/about-npm) (automatically installs with Node.js)
- **Recommended to:**
- Install IDE for editing files ([Visual Studio Code](https://code.visualstudio.com/) recommended)
- **How to use?**
1. Edit the [`config.js`](config.js) and [`data.json`](data.json) files
2. Use the command `npm install` before running to install all required dependencies (or use *"install-cmd"* in the [`package.json`](package.json) file)
3. Use `npm start` or `node index.js` to run the project

## WHAT CAN THIS BOT DO?

- **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
- `version` command for getting Minecraft version of server
- `help` command for getting the help menu (list of all user-available commands)
- `ip` command for getting the IP address of the server
- `list` command for getting an actual list of online players now
- `status` command for getting a simple and clear overview of the server
- `version` command for getting the Minecraft version of the server
- `vote` command for getting vote link for voting for server on Minecraft server list
- **Auto updating bot's status** with online and max players (setup in config with variables)
- **Auto updating bot's status** with online and max players (setup in the config with variables)

![Auto updating bot status](https://i.imgur.com/xNDVb2D.png)
![Auto updating bot status](https://imgur.com/4D8W8lT.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
- More Discord bot activities: `playing`, `listening`, `watching`, and `competing`
- More Discord bot statuses: `online`, `idle`, `dnd`, and `invisible`
- **Suggestions/voting channel** with reactions and threads

![Voting channel](https://i.imgur.com/OfCxqhf.gif)
- Custom responses for each command, editable in [config file](config.js)
- Custom responses for each command, editable in [the config file](config.js)
- **Auto updating status message** with player list

![Auto status messsage](https://i.imgur.com/L6gFK4Q.png)
![Auto status messsage](https://imgur.com/gSAUIh5.png)
- **Random** RGB **color of command embeds** (each message another)

![Random embed color](https://i.imgur.com/pA7h5rC.png)
- **Clear colorful console** logging

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

## HOW TO USE & INSTALL
## MORE INFO

### Go to our [documentation](https://petyxbron.gitbook.io/minecraft-bot/installation/install) and see.
Run on Repl.it:

[![Run on Repl.it](https://repl.it/badge/github/MrMazzone/dotreplit-example)](https://repl.it/github/PetyXbron/minecraft-bot)
*Repl could not be updated for lastest Node.js version. Please check if you can install Node.js v17*

*Repl probably won't be updated for the latest Node.js version. Please check if you can install Node.js v16.9.0 or higher to support Discord.js v14*

## TO DO

- [x] <s>Auto changing status message</s>
- [ ] Send custom embed message command
- [ ] Send a custom message/announcement command
- [ ] Better test command variables (more process info - like uptime)
- [ ] Poll/Voting command (simple or with more options)
- [x] <s>Auto changing statusCH message</s>
- [x] <s>Status command</s>
- [x] <s>IP address command</s>
- [x] <s>Minecraft version command</s>
- [x] <s>Player list command</s>
- [x] <s>Vote link command</s>
- [x] <s>Poll/Voting channel with reactions</s>
- [x] <s>Slash commands</s>
- [x] <s>Custom reply for ip, test and version command</s>
- [x] <s>Installation with repl.it</s>
- [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)
- [ ] Server AdminTeam applications
- [ ] Send custom embed message command
- [ ] Send custom message/announcement command
- [ ] Better test command variables (more process info - like uptime)
- [x] And many other unlisted things 😉
31 changes: 14 additions & 17 deletions commands/list.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const util = require('minecraft-server-util'),
const util = require('axios'),
Discord = require('discord.js'),
c = require('chalk'),
fs = require('fs'),
Expand All @@ -18,21 +18,18 @@ module.exports.run = async (bot, message) => {

if (!server.work) return;

let
ip1 = server.ip,
port1 = server.port,
icon = server.icon ? server.icon : message.guild.iconURL();
let icon = server.icon ? server.icon : message.guild.iconURL();

if (server.type === 'java') {
util.status(ip1, port1)
.then((result) => {
util.get(`https://api.mcstatus.io/v2/status/java/${server.ip}:${server.port}`)
.then((response) => {
if (text.title === "" || text.description === "" || text.listFormat === "") {
const trueList = result.players.sample ? "\n\`\`\`" + result.players.sample.map(p => ` ${p.name} `).join('\r\n') + "\`\`\`" : "";
const trueList = response.data.players.list ? "\n\`\`\`" + response.data.players.list.map(p => ` ${p.name_clean} `).join('\r\n') + "\`\`\`" : "";

const serverEmbed = new Discord.EmbedBuilder()
.setAuthor({ name: config.server.name ? config.server.name : message.guild.name, iconURL: icon })
.setTitle("Online player list:")
.setDescription(`**${result.players.online}**/**${result.players.max}**` + trueList)
.setDescription(`**${response.data.players.online}**/**${response.data.players.max}**` + trueList)
.setColor(config.embeds.color);
message.channel.send({ embeds: [serverEmbed] });
} else {
Expand All @@ -41,19 +38,19 @@ module.exports.run = async (bot, message) => {
text.title = text.title.replaceAll('{serverName}', config.server.name ? config.server.name : message.guild.name);
text.title = text.title.replaceAll('{voteLink}', config.server.vote);
text.title = text.title.replaceAll('{serverType}', config.server.type.charAt(0).toUpperCase() + config.server.type.slice(1));
text.title = text.title.replaceAll('{playersOnline}', result.players.online);
text.title = text.title.replaceAll('{playersMax}', result.players.max);
text.title = text.title.replaceAll('{playersOnline}', response.data.players.online);
text.title = text.title.replaceAll('{playersMax}', response.data.players.max);

text.description = text.description.replaceAll('{serverIp}', server.ip);
text.description = text.description.replaceAll('{serverPort}', server.port);
text.description = text.description.replaceAll('{serverName}', config.server.name ? config.server.name : message.guild.name);
text.description = text.description.replaceAll('{voteLink}', config.server.vote);
text.description = text.description.replaceAll('{serverType}', config.server.type.charAt(0).toUpperCase() + config.server.type.slice(1));
text.description = text.description.replaceAll('{playersOnline}', result.players.online);
text.description = text.description.replaceAll('{playersMax}', result.players.max);
text.description = text.description.replaceAll('{playersOnline}', response.data.players.online);
text.description = text.description.replaceAll('{playersMax}', response.data.players.max);

if (result.players.sample) {
var trueList = text.listFormat.replaceAll('{playersList}', result.players.sample.map(p => ` ${p.name} `).join('\r\n'));
if (response.data.players.list) {
var trueList = text.listFormat.replaceAll('{playersList}', response.data.players.list.map(p => ` ${p.name_clean} `).join('\r\n'));
}

const serverEmbed = new Discord.EmbedBuilder()
Expand Down Expand Up @@ -90,8 +87,8 @@ module.exports.run = async (bot, message) => {
if (warns) console.log(`${bot.emotes.warn} ` + 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.');
//Doesn't work for Bedrock edition, sorry.
message.reply({ content: 'Sorry, but this function is not working for Bedrock servers.' });
}

};
Loading

0 comments on commit 90a0db0

Please sign in to comment.