Add status command and valorant api wrapper

This commit is contained in:
2022-08-26 18:21:17 +00:00
parent c2fcab6738
commit b1f7be2ce8
3 changed files with 137 additions and 2 deletions

64
commands/status.js Normal file
View File

@@ -0,0 +1,64 @@
'use strict';
const path = require('path');
const { EmbedBuilder, SlashCommandBuilder } = require('discord.js');
const { API, Regions } = require('node-valorant-api');
const { VALORANT_API_KEY } = require(path.join(__dirname, '../config', 'config.json'));
const valorant = new API(Regions.EU, VALORANT_API_KEY, Regions.EUROPE);
const data = new SlashCommandBuilder()
.setName('status')
.setDescription('Check the status of Valorant servers');
const execute = async (interaction) => {
await interaction.deferReply();
const res = await valorant.StatusV1.getPlatformData();
const type = res.maintenances.length
? 'maintenance'
: res.incidents.length
? 'incident'
: false;
const embeds = [];
if (!type) {
embeds.push(new EmbedBuilder()
.setColor(0x5CB85C)
.setDescription('There are no current issues with the Valorant servers')
);
} else if (type === 'incident' && res.platforms.includes('windows')) {
embeds.push(new EmbedBuilder()
.setColor(0xCF352E)
.setTitle(`Ongoing incident: ${res.titles[0]['en-US']}`)
.setDescription(res.updates[0].translations['en-US'].content)
.addFields(
{ name: 'Created at', value: res.created_at },
{ name: 'Incident severity', value: res.incident_severity }
)
.setTimestamp()
);
} else if (type === 'maintenance' && res.platforms.includes('windows')) {
embeds.push(new EmbedBuilder()
.setColor(0xCF352E)
.setTitle(`Ongoing maintenance: ${res.titles['en-US']}`)
.setDescription(res.updates[0].translations['en-US'].content)
.addFields(
{ name: 'Created at', value: res.created_at },
{ name: 'Maintenance status', value: res.maintenance_status }
)
.setTimestamp()
);
}
await interaction.editReply({ embeds });
};
module.exports = {
data,
execute
};