diff --git a/base/Client.js b/base/Client.js index bc00de9b..8bc7e1e2 100644 --- a/base/Client.js +++ b/base/Client.js @@ -137,12 +137,12 @@ class JaBaClient extends Client { } try { - if (this.config.production) await rest.put(Routes.applicationCommands(this.user.id), { body: commands }); - else await rest.put(Routes.applicationGuildCommands(this.user.id, this.config.support.id), { body: commands }); + if (this.config.production) await rest.put(Routes.applicationCommands(this.config.userId), { body: commands }); + else await rest.put(Routes.applicationGuildCommands(this.config.userId, this.config.support.id), { body: commands }); this.logger.log("Successfully registered application commands."); } catch (err) { - this.logger.error(`Error during commands registration!\n${err.message}`); + console.log(err); } } diff --git a/commands/Fun/lmgtfy.js b/commands/Fun/lmgtfy.js index f1f31344..872eb40a 100644 --- a/commands/Fun/lmgtfy.js +++ b/commands/Fun/lmgtfy.js @@ -55,10 +55,17 @@ class LMGTFY extends BaseCommand { url = `https://letmegooglethat.com/?q=${encodeURIComponent(query)}`; if (short) { - 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()); + 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()); interaction.editReply({ - content: `<${res.shorturl}>`, + content: `<${res.shortUrl}>`, }); } else { interaction.editReply({ diff --git a/commands/General/shorturl.js b/commands/General/shorturl.js index c8344184..091b3e1f 100644 --- a/commands/General/shorturl.js +++ b/commands/General/shorturl.js @@ -38,12 +38,20 @@ class Shorturl extends BaseCommand { * @param {import("discord.js").ChatInputCommandInteraction} interaction */ async execute(client, interaction) { - const url = interaction.options.getString("url"); - 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()); + await interaction.deferReply({ ephemeral: true }); - interaction.reply({ - content: `<${res.shorturl}>`, - ephemeral: true, + const url = interaction.options.getString("url"); + 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()); + + interaction.editReply({ + content: `<${res.shortUrl}>`, }); } } diff --git a/config.sample.js b/config.sample.js index c2b5e509..8c8b514c 100644 --- a/config.sample.js +++ b/config.sample.js @@ -1,6 +1,8 @@ module.exports = { /* The token of your Discord Bot */ token: "XXXXXXXXXXXXXXXXXXXXXXXXXXXX", + /* UserID of your Discord Bot */ + userId: "XXXXXXXXXXXXXXXXXXXXXXXXXXXX", /* The URL of the MongoDB database */ mongoDB: "mongodb://127.0.0.1:27017/discordbot", /* Set to true for production */ @@ -34,6 +36,6 @@ module.exports = { }, /* Add your own API keys here */ apiKeys: { - + shlink: "12345678-1234-1234-1234-123456789098", /* Shlink.io REST API key */ }, };