From 713063284434d88578761f7f97517588c172a4e5 Mon Sep 17 00:00:00 2001 From: "Jonny_Bro (Nikita)" Date: Wed, 28 Feb 2024 18:35:51 +0500 Subject: [PATCH] update to new url shortener --- base/Client.js | 6 +++--- commands/Fun/lmgtfy.js | 11 +++++++++-- commands/General/shorturl.js | 18 +++++++++++++----- config.sample.js | 4 +++- 4 files changed, 28 insertions(+), 11 deletions(-) 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 */ }, };