Add status command and valorant api wrapper
This commit is contained in:
64
commands/status.js
Normal file
64
commands/status.js
Normal 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
|
||||
};
|
||||
Reference in New Issue
Block a user