JaBa/commands/General/shorturl.js

72 lines
2.4 KiB
JavaScript
Raw Normal View History

2024-09-19 23:58:06 +05:00
const { SlashCommandBuilder, InteractionContextType, ApplicationIntegrationType } = 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"),
})
2024-09-19 23:58:06 +05:00
.setIntegrationTypes([ApplicationIntegrationType.GuildInstall, ApplicationIntegrationType.UserInstall])
2024-09-14 19:52:56 +05:00
.setContexts([InteractionContextType.BotDM, InteractionContextType.PrivateChannel, InteractionContextType.Guild])
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),
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"),
}),
2023-07-05 00:58:06 +05:00
),
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-09-19 23:58:06 +05:00
await interaction.deferReply({ ephemeral: interaction.options.getBoolean("ephemeral") || false });
2024-02-28 18:35:51 +05:00
const url = interaction.options.getString("url");
2024-12-04 12:55:18 +05:00
if (!url.startsWith("http")) return interaction.error("general/shorturl:NOT_A_LINK", null, { edit: true });
const res = await fetch("https://s.jonnybro.ru/api/link/create", {
2024-02-28 18:35:51 +05:00
method: "POST",
headers: {
2024-12-04 11:55:24 +05:00
"Authorization": `Bearer ${client.config.apiKeys.sink}`,
2024-08-01 23:23:23 +05:00
"Content-Type": "application/json",
2024-02-28 18:35:51 +05:00
},
2024-08-01 23:23:23 +05:00
body: JSON.stringify({ url: url }),
2024-02-28 18:35:51 +05:00
}).then(res => res.json());
2024-02-28 18:35:51 +05:00
interaction.editReply({
2024-12-04 12:55:18 +05:00
content: `<https://s.jonnybro.ru/${res.link.slug}>`,
});
}
}
2023-07-05 00:58:06 +05:00
module.exports = Shorturl;