JaBa/commands/General/shorturl.js

62 lines
1.7 KiB
JavaScript
Raw Normal View History

2024-09-14 19:52:56 +05:00
const { SlashCommandBuilder, InteractionContextType } = 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-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),
),
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-08-01 23:23:23 +05:00
const res = await fetch("https://i.jonnybro.ru/api/shorten", {
2024-02-28 18:35:51 +05:00
method: "POST",
headers: {
2024-08-01 23:23:23 +05:00
"Content-Type": "application/json",
Authorization: client.config.apiKeys.zipline,
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-08-01 23:23:23 +05:00
console.log(res);
2024-02-28 18:35:51 +05:00
interaction.editReply({
2024-08-01 23:23:23 +05:00
content: `<${res.url}>`,
});
}
}
2023-07-05 00:58:06 +05:00
module.exports = Shorturl;