JaBa/commands/Fun/lmgtfy.js

73 lines
2.1 KiB
JavaScript
Raw Normal View History

const { SlashCommandBuilder } = require("discord.js");
const BaseCommand = require("../../base/BaseCommand"),
fetch = require("node-fetch");
class LMGTFY extends BaseCommand {
/**
*
2023-11-05 16:03:23 +05:00
* @param {import("../base/Client")} client
*/
constructor(client) {
super({
command: new SlashCommandBuilder()
.setName("lmgtfy")
.setDescription(client.translate("fun/lmgtfy:DESCRIPTION"))
.setDescriptionLocalizations({
2023-07-05 00:58:06 +05:00
uk: client.translate("fun/lmgtfy:DESCRIPTION", null, "uk-UA"),
ru: client.translate("fun/lmgtfy:DESCRIPTION", null, "ru-RU"),
})
.setDMPermission(true)
2023-07-05 00:58:06 +05:00
.addStringOption(option =>
option
.setName("query")
.setDescription(client.translate("fun/lmgtfy:QUERY"))
.setDescriptionLocalizations({
uk: client.translate("fun/lmgtfy:QUERY", null, "uk-UA"),
ru: client.translate("fun/lmgtfy:QUERY", null, "ru-RU"),
})
.setRequired(true),
)
.addBooleanOption(option =>
option
.setName("short")
.setDescription(client.translate("fun/lmgtfy:SHORT"))
.setDescriptionLocalizations({
uk: client.translate("fun/lmgtfy:SHORT", null, "uk-UA"),
ru: client.translate("fun/lmgtfy:SHORT", 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
2022-08-09 23:48:33 +05:00
* @param {Object} data
*/
async execute(client, interaction) {
await interaction.deferReply({ ephemeral: true });
const query = interaction.options.getString("query").replace(/[' '_]/g, "+"),
short = interaction.options.getBoolean("short"),
2023-11-18 16:30:42 +05:00
url = `https://letmegooglethat.com/?q=${encodeURIComponent(query)}`;
if (short) {
2023-11-18 16:30:42 +05:00
const res = await fetch(`https://plsgo.ru/yourls-api.php?signature=${client.config.apiKeys.jababot_yourls}&action=shorturl&url=${encodeURIComponent(url)}&format=json`).then(res => res.json());
interaction.editReply({
2023-11-18 16:30:42 +05:00
content: `<${res.shorturl}>`,
});
} else {
interaction.editReply({
content: `<${url}>`,
});
}
}
}
2023-07-05 00:58:06 +05:00
module.exports = LMGTFY;