Skip to content

Commit

Permalink
Add 'get-credit-pools' command
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex22sv committed Jan 29, 2024
1 parent 00e4669 commit 36ed021
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 10 deletions.
18 changes: 9 additions & 9 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.10.0"
"exaroton": "^1.11.1"
}
}
1 change: 1 addition & 0 deletions src/commandDescriptions.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"dynip": "Get the Dinamic IP (DynIP) of your server.",
"execute": "Execute a Minecraft command on your server.",
"file": "Get the content of text files on your server.",
"get-credit-pools": "List credit pools.",
"get-motd": "Get your server MOTD.",
"get-ram": "Check the amount of RAM assigned to your server.",
"help": "Display the list of commands or get information about a single command.",
Expand Down
1 change: 1 addition & 0 deletions src/commandUsages.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"dynip": "/dynip",
"execute": "/execute <server name|ID|address> <Minecraft command>",
"file": "/file <server name|ID|address> <file name>",
"get-credit-pools": "/get-credit-pools",
"get-ram": "/get-ram <server name|ID|address>",
"get-motd": "/get-motd <server name|ID|address>",
"help": "/help [<command>]",
Expand Down
48 changes: 48 additions & 0 deletions src/commands/get-credit-pools.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
const {embedColor, errorColor, exarotonAPIkey} = require('../config.json');
const commandDescriptions = require('../commandDescriptions.json')
const {Client} = require('exaroton');
const exarotonClient = new Client(exarotonAPIkey);
const { SlashCommandBuilder } = require('@discordjs/builders');
const { MessageEmbed } = require('discord.js');

module.exports = {
data: new SlashCommandBuilder()
.setName('get-credit-pools')
.setDescription(commandDescriptions['get-credit-pools']),
async run(bot, interaction) {
try{
let account = await exarotonClient.getAccount();
let pools = await exarotonClient.getPools();
let string = '';
if(pools.length == 0) {
const noPoolFound = new MessageEmbed()
.setDescription(`The exaroton account **${account.name}** has no pools.`)
.setColor(embedColor)
.setTimestamp()
.setFooter({text:interaction.user.tag, iconURL:interaction.user.displayAvatarURL()})
return interaction.reply({ embeds:[noPoolFound], ephemeral:false});
} else{
for(let pool of pools){
string += `${pool.name} (${pool.id}): ${pool.credits} credits, ${pool.servers} servers, ${pool.members} members\n`;
}
const listPoolsEmbed = new MessageEmbed()
.setTitle(`${account.name}'s pools`)
.setDescription(string)
.setColor(embedColor)
.setTimestamp()
.setFooter({text:interaction.user.tag, iconURL:interaction.user.displayAvatarURL()})
return interaction.reply({ embeds:[listPoolsEmbed], ephemeral:false});
}
} catch(e) {
console.error(`An error ocurred while running the command 'get-credit-pools' executed by ${interaction.user.tag}(${interaction.user.id}): ${e}`)
const errorEmbed = new MessageEmbed()
.setTitle('Error!')
.setDescription('An error ocurred while running that command: `' + e.message + '`')
.setColor(errorColor)
.setTimestamp()
.setFooter({text:interaction.user.tag, iconURL:interaction.user.displayAvatarURL()})
return interaction.reply({embeds:[errorEmbed], ephemeral:true});

}
}
}

0 comments on commit 36ed021

Please sign in to comment.