update to new url shortener

This commit is contained in:
Jonny_Bro (Nikita) 2024-02-28 18:35:51 +05:00
parent 91d1e37be0
commit 7130632844
No known key found for this signature in database
GPG key ID: 391C19BE62D36B33
4 changed files with 28 additions and 11 deletions

View file

@ -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);
}
}

View file

@ -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({

View file

@ -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}>`,
});
}
}

View file

@ -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 */
},
};