Skip to content

Commit

Permalink
Merge pull request #2 from Alex22sv/startowncredits
Browse files Browse the repository at this point in the history
Add start with own credits feature
  • Loading branch information
Alex22sv authored May 22, 2023
2 parents 528221d + afe8982 commit 253d0a1
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 44 deletions.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
# CommanderBot
## What does it do?
CommanderBot is an updated and improved version of [PhoenixAPI-Bot](https://github.com/Alex22sv/PhoenixAPI-Bot) which has the same commanods but the difference between both bots is that CommanderBot no longer uses message commands but slash commands.
## Features
- Get information about your exaroton account.
- List all servers in your exaroton account.
- Create an embed to automatically display the current status of your server.
- Start, stop & restart your own servers.
- Start servers that you have shared access to with your own credits.
- Get your server log or upload it to https://mclo.gs/.
- Update your server settings, like RAM, banned players & ips, whitelisted players, etc.
- Execute Minecraft commands.
- Get your server Dynamic IP (DynIP).
## Slash commands?
Yes. CommanderBot will only reply through slash commands, e.g. `/help`.
![image](https://user-images.githubusercontent.com/70553543/203646292-dc042b32-d52e-43e4-a391-09e6c8a4f88c.png)
Expand Down Expand Up @@ -36,7 +46,9 @@ Yes. CommanderBot will only reply through slash commands, e.g. `/help`.
### Starting the bot
Once you have the bot on your server and added all the config to the `config.json` file, you can start the bot running the command `node main.js`. Make sure the path is set to the `CommanderBot` folder.
You'll see this message when the bot is online:

![image](https://user-images.githubusercontent.com/70553543/203649611-90e43061-8af3-49dc-af99-412406914933.png)

And done! The bot is set up and online. You can now run `/help` to get the list of commands.

## Support
Expand Down
39 changes: 7 additions & 32 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@
"@discordjs/rest": "^0.4.1",
"discord-api-types": "^0.33.1",
"discord.js": "^13.8.1",
"exaroton": "^1.8.0"
"exaroton": "^1.9.0"
}
}
6 changes: 3 additions & 3 deletions src/commandDescriptions.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
"pardon": "Remove the ban of a player on your server.",
"pardonip": "Remove the ban of an IP on your server.",
"ram": "Get or change the RAM on your server.",
"restart": "Restart your Minecraft server. This command requires you to have the 'Server Manager' role.",
"restart": "Restart your Minecraft server.",
"servers": "Get the list of servers on your exaroton account.",
"start": "Start your Minecraft server. This command requires you to have the 'Server Manager' role.",
"start": "Start your Minecraft server or one that you have shared access to.",
"status": "Create an embed to display the status of your server.",
"stop": "Stop your Minecraft server. This command requires you to have the 'Server Manager' role.",
"stop": "Stop your Minecraft server.",
"unwhitelist": "Remove Minecraft players from the whitelist/allowlist on your server.",
"whitelist": "Add Minecraft players to the whitelist/allowlist on your server."
}
2 changes: 1 addition & 1 deletion src/commandUsages.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"ram": "/ram <server name|ID|address> [<new RAM>]",
"restart": "/restart <server name|ID|address>.",
"servers": "/servers",
"start": "/start <server name|ID|address>",
"start": "/start <server name|ID|address> [<use own credits>]",
"status": "/status <server name|ID|address>",
"stop": "/stop <server name|ID|address>",
"unwhitelist": "/unwhitelist <server name|ID|address> <Minecraft player>",
Expand Down
47 changes: 40 additions & 7 deletions src/commands/start.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,43 @@ module.exports = {
option.setName('server')
.setDescription('Send the server name, ID or address here.')
.setRequired(true)
)
.addStringOption(option =>
option.setName('credits')
.setDescription('Use your own credits to start a server that you have shared access to.')
.setRequired(false)
.addChoices(
{name:'No', value:'false'},
{name:'Yes', value:'true'}
)
),
async run(bot, interaction) {
try{
let account = await exarotonClient.getAccount();
let name = interaction.options.getString('server');
let serverLists = await exarotonClient.getServers();
let server = serverLists.find(server => server.name === name || server.id === name || server.address === name);
await server.start();
const startingServerEmbed = new MessageEmbed()
.setDescription(`${loadingEmoji} Starting server **${server.name}**.`)
.setColor(embedColor)
.setTimestamp()
.setFooter({text:interaction.user.tag, iconURL:interaction.user.displayAvatarURL()})
return interaction.reply({ embeds:[startingServerEmbed], ephemeral:false});
let ownCredits = interaction.options.getString('credits');
if(ownCredits == "true"){
console.log('Starting server with own credits.');
await server.start(true);
const startingServerEmbedOwnCredits = new MessageEmbed()
.setDescription(`${loadingEmoji} Starting server **${server.name}** using **${account.name}**'s credits.`)
.setColor(embedColor)
.setTimestamp()
.setFooter({text:interaction.user.tag, iconURL:interaction.user.displayAvatarURL()})
return interaction.reply({ embeds:[startingServerEmbedOwnCredits], ephemeral:false});
} else {
console.log('Starting server with owner credits');
await server.start(false);
const startingServerEmbed = new MessageEmbed()
.setDescription(`${loadingEmoji} Starting server **${server.name}**.`)
.setColor(embedColor)
.setTimestamp()
.setFooter({text:interaction.user.tag, iconURL:interaction.user.displayAvatarURL()})
return interaction.reply({ embeds:[startingServerEmbed], ephemeral:false});

}
} catch(e) {
console.error(`An error ocurred while running the command 'start' executed by ${interaction.user.tag}(${interaction.user.id}): ${e}`)
if(e.message == "Server is not offline"){
Expand All @@ -46,6 +70,15 @@ module.exports = {
.setTimestamp()
.setFooter({text:interaction.user.tag, iconURL:interaction.user.displayAvatarURL()})
return interaction.reply({embeds:[serverNotFoundEmbed], ephemeral:true});
}
if(e.message.includes("Not enough credits")){
const notEnoughCredits = new MessageEmbed()
.setTitle('Error!')
.setDescription('The owner of that server does not have enough credits to start the server.')
.setColor(errorColor)
.setTimestamp()
.setFooter({text:interaction.user.tag, iconURL:interaction.user.displayAvatarURL()})
return interaction.reply({embeds:[notEnoughCredits], ephemeral:true});
} else {
const errorEmbed = new MessageEmbed()
.setTitle('Error!')
Expand Down

0 comments on commit 253d0a1

Please sign in to comment.