JaBa/commands/Beatrun/courses.js

101 lines
3.2 KiB
JavaScript
Raw Permalink Normal View History

2024-09-19 23:58:06 +05:00
const { SlashCommandBuilder, InteractionContextType, ApplicationIntegrationType } = require("discord.js");
2024-04-07 15:29:16 +05:00
const BaseCommand = require("../../base/BaseCommand"),
fetch = require("node-fetch");
class Courses extends BaseCommand {
/**
*
* @param {import("../base/Client")} client
*/
constructor(client) {
super({
command: new SlashCommandBuilder()
.setName("courses")
2024-11-17 13:58:35 +05:00
.setDescription(client.translate("beatrun/courses:DESCRIPTION"))
2024-04-07 15:29:16 +05:00
.setDescriptionLocalizations({
2024-11-17 13:58:35 +05:00
uk: client.translate("beatrun/courses:DESCRIPTION", null, "uk-UA"),
ru: client.translate("beatrun/courses:DESCRIPTION", null, "ru-RU"),
2024-04-07 15:29:16 +05:00
})
2024-09-19 23:58:06 +05:00
.setIntegrationTypes([ApplicationIntegrationType.GuildInstall, ApplicationIntegrationType.UserInstall])
2024-09-14 19:52:56 +05:00
.setContexts([InteractionContextType.Guild, InteractionContextType.BotDM, InteractionContextType.PrivateChannel])
2024-04-07 15:29:16 +05:00
.addStringOption(option =>
option
.setName("code")
.setDescription(client.translate("common:CODE"))
.setDescriptionLocalizations({
uk: client.translate("common:CODE", null, "uk-UA"),
ru: client.translate("common:CODE", null, "ru-RU"),
})
.setRequired(true),
2024-09-19 23:58:06 +05:00
)
.addBooleanOption(option =>
option
.setName("ephemeral")
.setDescription(client.translate("misc:EPHEMERAL_RESPONSE"))
.setDescriptionLocalizations({
uk: client.translate("misc:EPHEMERAL_RESPONSE", null, "uk-UA"),
ru: client.translate("misc:EPHEMERAL_RESPONSE", null, "ru-RU"),
}),
2024-04-07 15:29:16 +05:00
),
dirname: __dirname,
ownerOnly: false,
});
}
/**
*
* @param {import("../../base/Client")} client
* @param {import("discord.js").ChatInputCommandInteraction} interaction
* @param {Object} data
*/
async execute(client, interaction) {
2024-09-19 23:58:06 +05:00
await interaction.deferReply({ ephemeral: interaction.options.getBoolean("ephemeral") || false });
2024-04-07 15:29:16 +05:00
const code = interaction.options.getString("code");
2024-09-14 19:52:56 +05:00
const response = await fetch(`https://courses.jonnybro.ru/api/info/${code}`).then(res => res.json()),
{ data } = response;
2024-04-07 15:29:16 +05:00
2024-11-17 13:58:35 +05:00
if (response.res === 401) return interaction.error("beatrun/courses:NOT_FOUND", null, { ephemeral: true, edit: true });
2024-04-07 15:29:16 +05:00
const embed = client.embed({
2024-09-14 19:52:56 +05:00
title: data.name,
2024-11-17 13:58:35 +05:00
description: `[${interaction.translate("beatrun/courses:DOWNLOAD")}](https://courses.jonnybro.ru/${data.path})`,
2024-09-14 19:52:56 +05:00
thumbnail: data.mapimg,
2024-08-04 22:35:58 +05:00
url: `https://courses.jonnybro.ru/?search=${code}`,
2024-04-07 15:29:16 +05:00
fields: [
{
2024-11-17 13:58:35 +05:00
name: interaction.translate("beatrun/courses:MAP"),
2024-09-14 19:52:56 +05:00
value: `[${data.map}](https://steamcommunity.com/sharedfiles/filedetails/?id=${data.mapid})`,
2024-04-07 15:29:16 +05:00
inline: true,
},
{
2024-11-17 13:58:35 +05:00
name: interaction.translate("beatrun/courses:UPLOADER"),
2024-09-14 19:52:56 +05:00
value: `[${data.uploader.name || data.uploader.userid}](https://steamcommunity.com/profiles/${data.uploader.userid})`,
2024-04-07 15:29:16 +05:00
inline: true,
},
{
name: "\u200B",
value: "\u200B",
inline: true,
},
{
2024-11-17 13:58:35 +05:00
name: interaction.translate("beatrun/courses:DATE"),
2024-09-14 19:52:56 +05:00
value: `<t:${Math.floor(data.time / 1000)}:D>`,
2024-04-07 15:29:16 +05:00
inline: true,
},
{
2024-11-17 13:58:35 +05:00
name: interaction.translate("beatrun/courses:PLAYS"),
2024-09-14 19:52:56 +05:00
value: `${data.plays || 0}`,
2024-04-07 15:29:16 +05:00
inline: true,
},
],
});
interaction.editReply({
embeds: [embed],
});
}
}
module.exports = Courses;