-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from Alex0622/v4-update
Update bot to v4.1
- Loading branch information
Showing
21 changed files
with
1,820 additions
and
892 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,21 @@ | ||
# PhoenixAPI-Bot | ||
PhoenixAPI is a bot developed with discord.js. The main reason of this bot is the managment of [exaroton](https://exaroton.com/) servers using the exaroton API. | ||
You can find the documentation about the exaroton API [here](https://support.exaroton.com/hc/en-us/articles/360011926177-API-documentation) and its package [here](https://www.npmjs.com/package/exaroton). | ||
|
||
You can find the documentation about the exaroton API [here](https://support.exaroton.com/hc/en-us/articles/360019857878-API-documentation) and its package [here](https://www.npmjs.com/package/exaroton). | ||
# Using the bot | ||
This is a private bot but if you want to use it I have uploaded an example file with its main and config file. | ||
In the config file you can change the bot's prefix; add the exaroton API key which will be needed to get the information about your servers and account on exaroton; you will also find the Discord API token which is required to run the bot; also, the ID of the general channel which is used when the bot goes online and sends a message saying hi. And if you want to change the color of the embed you can do that in the config.json file. | ||
Follow the instructions to install and configure your own Discord bot: | ||
1. Install the [Node.js exaroton API client](https://www.npmjs.com/package/exaroton). | ||
2. Open the config.json file and add your exaroton API token and your Discord API token. | ||
3. Run your Discord bot. | ||
|
||
# Commands | ||
Information about the bot and its commands can be found using the `API help` command. | ||
To get the list of commands use `API help`. | ||
|
||
# Important changes | ||
* **Status**: Thanks to the [new update](https://github.com/exaroton/node-exaroton-api#websocket-api) you can now get your server status in real time by using `API status {server name}`, the bot will send an embed of the current status of that server and when an event happens (e.g. when someone joins the server or the status of the server changes, etc.) the bot will edit its embed with the new changes. | ||
|
||
* **Each command has its own file**: There is now a _Commands_ folder which contains all the available commands for the bot. | ||
|
||
* **All commands require {server name}**: Before the v4 update, just a few commands required to add the {server name} parameter to the messages because the server was already defined in the config file, but now that was removed so you need to add the parameter on your messages. If you need help use `API help {command}` | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
const Discord = require('discord.js'); | ||
const config = require('../config.json'); | ||
const prefix = config.prefix; | ||
const embedColor = config.embedColor; | ||
const errorColor = config.errorColor; | ||
|
||
const {Client} = require('exaroton'); | ||
const exarotonClient = new Client(config.exarotonAPIkey); | ||
|
||
module.exports = { | ||
name: 'account', | ||
description: 'Get information about your exaroton account.', | ||
usage: '`'+prefix+'account`', | ||
permission: '`None`', | ||
execute(msg){ | ||
async function APIaccount() { | ||
try{ | ||
let account = await exarotonClient.getAccount(); | ||
if (account.verified == true) { | ||
embedDescription = 'verified' | ||
} else if (account.verified == false) { | ||
embedDescription = 'not verified' | ||
} | ||
const accountEmbed = new Discord.MessageEmbed() | ||
.setDescription(`The exaroton account ${account.name} is ${embedDescription} and currently has ${account.credits} credits.`) | ||
.setColor(embedColor) | ||
.setFooter(msg.author.username+'#'+msg.author.discriminator, msg.member.user.displayAvatarURL()) | ||
console.log(msg.content + ' | User: ' + msg.author.username+'#'+msg.author.discriminator) | ||
msg.channel.send(accountEmbed) | ||
} | ||
catch (e){ | ||
console.log(msg.content + ' | User: ' + msg.author.username+'#'+msg.author.discriminator) | ||
console.error('Error while using "account" command: ' + e.message) | ||
const errorEmbed = new Discord.MessageEmbed() | ||
.setTitle('Error!') | ||
.setDescription('An error occurred while running that command: `' + e.message + '`') | ||
.setColor(errorColor) | ||
msg.channel.send(errorEmbed) | ||
} | ||
} | ||
APIaccount(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
const Discord = require('discord.js'); | ||
const config = require('../config.json'); | ||
const prefix = config.prefix; | ||
const embedColor = config.embedColor; | ||
const errorColor = config.errorColor; | ||
|
||
const {Client} = require('exaroton'); | ||
const exarotonClient = new Client(config.exarotonAPIkey); | ||
|
||
module.exports = { | ||
name: 'ban', | ||
description: 'Ban players in Minecraft servers.', | ||
usage: '`'+'ban {server name} {Minecraft player}`', | ||
permission: '`ADMINISTRATOR`', | ||
execute(msg, args){ | ||
if(args[0] == undefined){ | ||
const notSeverMentioned = new Discord.MessageEmbed() | ||
.setTitle('Error!') | ||
.setDescription('Your message does not include an exaroton server.') | ||
.setColor(errorColor) | ||
msg.channel.send(notSeverMentioned) | ||
console.log(msg.content + ' | User: ' + msg.author.username+'#'+msg.author.discriminator) | ||
return | ||
} | ||
if(args[0] != undefined){ | ||
if(msg.member.hasPermission('ADMINISTRATOR')){ | ||
if(args[1] == undefined){ | ||
const missingPlayerEmbed = new Discord.MessageEmbed() | ||
.setTitle('Error!') | ||
.setDescription('Your message does not include the {Minecraft player} parameter. \n Use `'+prefix+'help ban` for more information.') | ||
.setColor(errorColor) | ||
msg.channel.send(missingPlayerEmbed) | ||
console.log(msg.content + ' | User: ' + msg.author.username+'#'+msg.author.discriminator) | ||
return | ||
} else{ | ||
async function APIBan(){ | ||
try { | ||
let name = args[0]; | ||
let serverLists = await exarotonClient.getServers(); | ||
let server = serverLists.find(server => server.name === name); | ||
let username = args[1] | ||
let list = server.getPlayerList("banned-players") | ||
await list.addEntry(username) | ||
const playerBannedEmbed = new Discord.MessageEmbed() | ||
.setDescription(`Player **${username}** is now banned in Minecraft server **${server.name}**.`) | ||
.setColor(embedColor) | ||
msg.channel.send(playerBannedEmbed) | ||
console.log(`${msg.author.username}#${msg.author.discriminator} banned ${username} in server ${server.name}`) | ||
}catch (e) { | ||
console.log(msg.content + ' | User: ' + msg.author.username+'#'+msg.author.discriminator) | ||
console.error('Error while using "ban" command: ' + e.message) | ||
if(e.message == "Cannot read property 'getPlayerList' of undefined"){ | ||
const serverNotFoundEmbed = new Discord.MessageEmbed() | ||
.setTitle('Error!') | ||
.setDescription(`Server "${args[0]}" not found.`) | ||
.setColor(errorColor) | ||
msg.channel.send(serverNotFoundEmbed) | ||
} else{ | ||
const errorEmbed = new Discord.MessageEmbed() | ||
.setTitle('Error!') | ||
.setDescription('An error occurred while running that command: `' + e.message + '`') | ||
.setColor(errorColor) | ||
msg.channel.send(errorEmbed) | ||
} | ||
} | ||
} | ||
APIBan(); | ||
} | ||
} | ||
if(!msg.member.hasPermission('ADMINISTRATOR')) { | ||
const MissingPermissionsEmbed = new Discord.MessageEmbed() | ||
.setTitle('Error!') | ||
.setDescription('You need the permission `Administrator` to use that command.') | ||
.setColor(errorEmbed) | ||
msg.channel.send(MissingPermissionsEmbed) | ||
console.log(msg.content + ' | User: ' + msg.author.username+'#'+msg.author.discriminator) | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
const Discord = require('discord.js'); | ||
const config = require('../config.json'); | ||
const prefix = config.prefix; | ||
const embedColor = config.embedColor; | ||
const errorColor = config.errorColor; | ||
|
||
const {Client} = require('exaroton'); | ||
const exarotonClient = new Client(config.exarotonAPIkey); | ||
|
||
module.exports = { | ||
name: 'deop', | ||
description: 'Remove operators rights from players in Minecraft servers.', | ||
usage: '`'+prefix+'deop {Minecraft server} {server name}`', | ||
permission: '`ADMINISTRATOR`', | ||
execute(msg, args){ | ||
if(msg.member.hasPermission('ADMINISTRATOR')){ | ||
if(args[0] == undefined){ | ||
const notSeverMentioned = new Discord.MessageEmbed() | ||
.setTitle('Error!') | ||
.setDescription('Your message does not include an exaroton server.') | ||
.setColor(errorColor) | ||
console.log(msg.content + ' | User: ' + msg.author.username+'#'+msg.author.discriminator) | ||
msg.channel.send(notSeverMentioned) | ||
return | ||
} | ||
if(args[0] != undefined){ | ||
if(args[1] == undefined){ | ||
const missingPlayerEmbed = new Discord.MessageEmbed() | ||
.setTitle('Error!') | ||
.setDescription('Your message does not include the {Minecraft player} parameter. \n Use `'+prefix+'help deop` for more information.') | ||
.setColor(errorColor) | ||
msg.channel.send(missingPlayerEmbed) | ||
console.log(msg.content + ' | User: ' + msg.author.username+'#'+msg.author.discriminator) | ||
return | ||
} else{ | ||
async function APIdeop(){ | ||
try { | ||
let name = args[0]; | ||
let serverLists = await exarotonClient.getServers(); | ||
let server = serverLists.find(server => server.name === name); | ||
let username = args[1] | ||
let list = server.getPlayerList("ops") | ||
await list.deleteEntry(username) | ||
const playerDeoppedEmbed = new Discord.MessageEmbed() | ||
.setDescription(`Player **${username}** is no longer operator in Minecraft server **${server.name}**.`) | ||
.setColor(embedColor) | ||
msg.channel.send(playerDeoppedEmbed) | ||
console.log(`${msg.author.username}#${msg.author.discriminator} deopped ${username} in server ${server.name}`) | ||
} catch (e) { | ||
console.log(msg.content + ' | User: ' + msg.author.username+'#'+msg.author.discriminator) | ||
console.error('Error while using "deop" command: ' + e.message) | ||
if(e.message == "Cannot read property 'getPlayerList' of undefined"){ | ||
const serverNotFoundEmbed = new Discord.MessageEmbed() | ||
.setTitle('Error!') | ||
.setDescription(`Server "${args[0]}" not found.`) | ||
.setColor(errorColor) | ||
msg.channel.send(serverNotFoundEmbed) | ||
} else{ | ||
const errorEmbed = new Discord.MessageEmbed() | ||
.setTitle('Error!') | ||
.setDescription('An error occurred while running that command: `' + e.message + '`') | ||
.setColor(errorColor) | ||
msg.channel.send(errorEmbed) | ||
} | ||
} | ||
} | ||
APIdeop(); | ||
} | ||
} | ||
} | ||
if(!msg.member.hasPermission('ADMINISTRATOR')) { | ||
const MissingPermissionsEmbed = new Discord.MessageEmbed() | ||
.setTitle('Error!') | ||
.setDescription('You need the permission `Administrator` to use that command.') | ||
.setColor(errorEmbed) | ||
msg.channel.send(MissingPermissionsEmbed) | ||
console.log(msg.content + ' | User: ' + msg.author.username+'#'+msg.author.discriminator) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
const Discord = require('discord.js'); | ||
const config = require('../config.json'); | ||
const prefix = config.prefix; | ||
const embedColor = config.embedColor; | ||
const errorColor = config.errorColor; | ||
|
||
const {Client} = require('exaroton'); | ||
const exarotonClient = new Client(config.exarotonAPIkey); | ||
|
||
module.exports = { | ||
name: 'dynip', | ||
description: "Get the server's DynIP.", | ||
usage: '`'+prefix+'dynip {server name}`', | ||
permission: '`None`', | ||
execute(msg, args){ | ||
if(args[0] == undefined) { | ||
const notSeverMentioned = new Discord.MessageEmbed() | ||
.setTitle('Error!') | ||
.setDescription('Your message does not include an exaroton server.') | ||
.setColor(errorColor) | ||
msg.channel.send(notSeverMentioned) | ||
console.log(msg.content + ' | User: ' + msg.author.username+'#'+msg.author.discriminator) | ||
return | ||
} | ||
if(args[0] != undefined) { | ||
async function APIDynIP() { | ||
let name = args[0]; | ||
let serverLists = await exarotonClient.getServers(); | ||
let server = serverLists.find(server => server.name === name); | ||
try { | ||
await server.get(); | ||
if(server.host == null){ | ||
const errorDynipEmbed = new Discord.MessageEmbed() | ||
.setTitle('Error!') | ||
.setDescription("I can't get the DynIP of that server because it's not online.") | ||
.setColor(errorColor) | ||
msg.channel.send(errorDynipEmbed) | ||
console.log(msg.content + ' | User: ' + msg.author.username+'#'+msg.author.discriminator) | ||
} | ||
if(server.host != null){ | ||
const DynipEmbed = new Discord.MessageEmbed() | ||
.setDescription('DynIP for server **' + server.name + '**: `' + server.host + ':' +server.port + '`') | ||
.setColor(embedColor) | ||
.setFooter(msg.author.username+'#'+msg.author.discriminator, msg.member.user.displayAvatarURL()) | ||
msg.channel.send(DynipEmbed) | ||
console.log(msg.content + ' | User: ' + msg.author.username+'#'+msg.author.discriminator) | ||
} | ||
}catch (e) { | ||
console.log(msg.content + ' | User: ' + msg.author.username+'#'+msg.author.discriminator) | ||
console.error('Error while using "dynip" command: ' + e.message) | ||
if(e.message == "Cannot read property 'get' of undefined"){ | ||
const serverNotFoundEmbed = new Discord.MessageEmbed() | ||
.setTitle('Error!') | ||
.setDescription(`Server "${args[0]}" not found.`) | ||
.setColor(errorColor) | ||
msg.channel.send(serverNotFoundEmbed) | ||
} else{ | ||
const errorEmbed = new Discord.MessageEmbed() | ||
.setTitle('Error!') | ||
.setDescription('An error occurred while running that command: `' + e.message + '`') | ||
.setColor(errorColor) | ||
msg.channel.send(errorEmbed) | ||
} | ||
} | ||
} | ||
APIDynIP(); | ||
} | ||
} | ||
} |
Oops, something went wrong.