JaBa/commands/General/shorturl.js

60 lines
1.6 KiB
JavaScript
Raw Normal View History

const { SlashCommandBuilder } = require("discord.js");
const BaseCommand = require("../../base/BaseCommand"),
fetch = require("node-fetch");
class Shorturl extends BaseCommand {
/**
*
2023-11-05 16:03:23 +05:00
* @param {import("../base/Client")} client
*/
constructor(client) {
super({
command: new SlashCommandBuilder()
.setName("shorturl")
.setDescription(client.translate("general/shorturl:DESCRIPTION"))
.setDescriptionLocalizations({
2023-07-05 00:58:06 +05:00
uk: client.translate("general/shorturl:DESCRIPTION", null, "uk-UA"),
ru: client.translate("general/shorturl:DESCRIPTION", null, "ru-RU"),
})
.setDMPermission(true)
2023-07-05 00:58:06 +05:00
.addStringOption(option =>
option
.setName("url")
.setDescription(client.translate("common:URL"))
.setDescriptionLocalizations({
uk: client.translate("common:URL", null, "uk-UA"),
ru: client.translate("common:URL", null, "ru-RU"),
})
.setRequired(true),
),
dirname: __dirname,
ownerOnly: false,
});
}
/**
*
2023-11-05 16:03:23 +05:00
* @param {import("../../base/Client")} client
* @param {import("discord.js").ChatInputCommandInteraction} interaction
*/
async execute(client, interaction) {
2024-02-28 18:35:51 +05:00
await interaction.deferReply({ ephemeral: true });
const url = interaction.options.getString("url");
2024-02-28 18:35:51 +05:00
const res = await fetch("https://plsgo.ru/rest/v3/short-urls", {
method: "POST",
headers: {
"Content-Type": "application/x-www-form-urlencoded",
"X-Api-Key": client.config.apiKeys.shlink,
},
body: new URLSearchParams({ longUrl: url }),
}).then(res => res.json());
2024-02-28 18:35:51 +05:00
interaction.editReply({
content: `<${res.shortUrl}>`,
});
}
}
2023-07-05 00:58:06 +05:00
module.exports = Shorturl;