From 44f51bd2192c21a333e55c238c7ac7ef0593d21a Mon Sep 17 00:00:00 2001 From: Dragon Fire Date: Mon, 13 May 2024 23:47:28 -0400 Subject: [PATCH] Use embedURL when relevant --- commands/events/florida-man.js | 4 ++-- commands/info/first-message.js | 3 ++- commands/pokedex/smogon.js | 4 +++- commands/random-img/xiao.js | 5 ++++- commands/search/anime.js | 2 +- commands/search/magic.js | 5 +++-- commands/search/manga.js | 2 +- commands/search/wikipedia.js | 3 ++- commands/util/generate-credit.js | 7 ++++--- 9 files changed, 22 insertions(+), 13 deletions(-) diff --git a/commands/events/florida-man.js b/commands/events/florida-man.js index c2c772ab..2d000481 100644 --- a/commands/events/florida-man.js +++ b/commands/events/florida-man.js @@ -4,7 +4,7 @@ const { stripIndents } = require('common-tags'); const request = require('node-superfetch'); const cheerio = require('cheerio'); const { decode: decodeHTML } = require('html-entities'); -const { firstUpperCase } = require('../../util/Util'); +const { firstUpperCase, embedURL } = require('../../util/Util'); const { months } = require('../../assets/json/month'); module.exports = class FloridaManCommand extends Command { @@ -48,7 +48,7 @@ module.exports = class FloridaManCommand extends Command { return msg.say(stripIndents` **${article.title}** ${firstUpperCase(months[month - 1])} ${day} — ${article.firstLine} - [Read more...]() + ${embedURL('Read more...', ``)} `, { files: [article.image] }); } diff --git a/commands/info/first-message.js b/commands/info/first-message.js index d4b0d8e6..c5a85aa1 100644 --- a/commands/info/first-message.js +++ b/commands/info/first-message.js @@ -1,5 +1,6 @@ const Command = require('../../framework/Command'); const { EmbedBuilder, PermissionFlagsBits } = require('discord.js'); +const { embedURL } = require('../../util/Util'); module.exports = class FirstMessageCommand extends Command { constructor(client) { @@ -33,7 +34,7 @@ module.exports = class FirstMessageCommand extends Command { .setDescription(message.content || 'No content.') .setTimestamp(message.createdAt) .setFooter({ text: `ID: ${message.id}` }) - .addField('❯ Jump', `[Click Here to Jump](${message.url})`); + .addField('❯ Jump', embedURL('Click Here to Jump', message.url)); return msg.embed(embed); } }; diff --git a/commands/pokedex/smogon.js b/commands/pokedex/smogon.js index e3437158..05cbe88c 100644 --- a/commands/pokedex/smogon.js +++ b/commands/pokedex/smogon.js @@ -1,5 +1,6 @@ const Command = require('../../framework/Command'); const { EmbedBuilder, PermissionFlagsBits } = require('discord.js'); +const { embedURL } = require('../../util/Util'); const genGames = [null, 'rb', 'gs', 'rs', 'dp', 'bw', 'xy', 'sm', 'ss', 'sv']; const games = { rb: 'Red/Blue', @@ -71,7 +72,8 @@ module.exports = class SmogonCommand extends Command { }) .setThumbnail(pokemon.spriteImageURL); for (const game of fetchGames) { - embed.addField(`❯ ${games[game]}`, `[${pokemon.smogonTiers[game].join('/')}](${pokemon.smogonURL(game)})`, true); + const tiers = pokemon.smogonTiers[game]; + embed.addField(`❯ ${games[game]}`, embedURL(tiers.join('/'), pokemon.smogonURL(game)), true); } if (fetchGames.length % 3 !== 0 && fetchGames.length > 3) { for (let i = 0; i < 3 - (fetchGames.length % 3); i++) { diff --git a/commands/random-img/xiao.js b/commands/random-img/xiao.js index e72ab92a..2b8382e8 100644 --- a/commands/random-img/xiao.js +++ b/commands/random-img/xiao.js @@ -1,6 +1,7 @@ const Command = require('../../framework/Command'); const { PermissionFlagsBits } = require('discord.js'); const sagiri = require('sagiri'); +const { embedURL } = require('../../util/Util'); const { SAUCENAO_KEY } = process.env; const sagiriClient = sagiri(SAUCENAO_KEY); const fs = require('fs'); @@ -58,7 +59,9 @@ module.exports = class XiaoCommand extends Command { if (data && data[0].similarity > 90) { result = ''; const sauce = data[0]; - if (sauce.authorName && sauce.authorUrl) result += `Art by [${sauce.authorName}](<${sauce.authorUrl}>) | `; + if (sauce.authorName && sauce.authorUrl) { + result += `Art by ${embedURL(sauce.authorName, `<${sauce.authorUrl}>`)} | `; + } if (sauce.authorName && !sauce.authorUrl) result += `Art by ${sauce.authorName} | `; result += `Art Source: <${sauce.url}>`; } diff --git a/commands/search/anime.js b/commands/search/anime.js index 0b75316f..2c49ca70 100644 --- a/commands/search/anime.js +++ b/commands/search/anime.js @@ -132,7 +132,7 @@ module.exports = class AnimeCommand extends Command { .addField(`❯ MAL Score`, malScore ? embedURL(malScore, malURL) : '???', true) .addField(`❯ ${ANILIST_USERNAME}'s Score`, entry && entry.score ? `${entry.score}/10` : '???', true) .addField('❯ External Links', anime.externalLinks.length - ? anime.externalLinks.map(link => `[${link.site}](${link.url})`).join(', ') + ? anime.externalLinks.map(link => embedURL(link.site, link.url)).join(', ') : 'None'); return msg.embed(embed); } diff --git a/commands/search/magic.js b/commands/search/magic.js index b6f43143..a70aa460 100644 --- a/commands/search/magic.js +++ b/commands/search/magic.js @@ -2,6 +2,7 @@ const Command = require('../../framework/Command'); const request = require('node-superfetch'); const { EmbedBuilder } = require('discord.js'); const { stripIndents } = require('common-tags'); +const { embedURL } = require('../../util/Util'); const logos = require('../../assets/json/logos'); module.exports = class MagicCommand extends Command { @@ -75,8 +76,8 @@ module.exports = class MagicCommand extends Command { embed.addField('❯ Loyalty', card.loyalty); } embed.addField('❯ Price', stripIndents` - **Non-Foil:** [${card.prices.usd ? `$${card.prices.usd}` : '???'}](${card.purchase_uris.tcgplayer}) - **Foil:** [${card.prices.usd_foil ? `$${card.prices.usd_foil}` : '???'}](${card.purchase_uris.tcgplayer}) + **Non-Foil:** ${embedURL(card.prices.usd ? `$${card.prices.usd}` : '???', card.purchase_uris.tcgplayer)} + **Foil:** ${embedURL(card.prices.usd_foil ? `$${card.prices.usd_foil}` : '???', card.purchase_uris.tcgplayer)} `); return msg.embed(embed); } diff --git a/commands/search/manga.js b/commands/search/manga.js index 1ade483e..0e59b9e7 100644 --- a/commands/search/manga.js +++ b/commands/search/manga.js @@ -125,7 +125,7 @@ module.exports = class MangaCommand extends Command { .addField(`❯ MAL Score`, malScore ? embedURL(malScore, malURL) : '???', true) .addField(`❯ ${ANILIST_USERNAME}'s Score`, entry && entry.score ? `${entry.score}/10` : '???', true) .addField('❯ External Links', manga.externalLinks.length - ? manga.externalLinks.map(link => `[${link.site}](${link.url})`).join(', ') + ? manga.externalLinks.map(link => embedURL(link.site, link.url)).join(', ') : 'None'); return msg.embed(embed); } diff --git a/commands/search/wikipedia.js b/commands/search/wikipedia.js index 660048c2..55d1cfb5 100644 --- a/commands/search/wikipedia.js +++ b/commands/search/wikipedia.js @@ -1,6 +1,7 @@ const Command = require('../../framework/Command'); const { EmbedBuilder, PermissionFlagsBits } = require('discord.js'); const request = require('node-superfetch'); +const { embedURL } = require('../../util/Util'); const logos = require('../../assets/json/logos'); module.exports = class WikipediaCommand extends Command { @@ -67,7 +68,7 @@ module.exports = class WikipediaCommand extends Command { fact += ' '; } const url = `https://en.wikipedia.org/wiki/${encodeURIComponent(query).replaceAll(')', '%29')}`; - fact += `[Read more...](${url})`; + face += embedURL('Read more...', url); const embed = new EmbedBuilder() .setColor(0xE7E7E7) .setTitle(data.title) diff --git a/commands/util/generate-credit.js b/commands/util/generate-credit.js index 9ee26ce4..41354120 100644 --- a/commands/util/generate-credit.js +++ b/commands/util/generate-credit.js @@ -1,4 +1,5 @@ const Command = require('../../framework/Command'); +const { embedURL } = require('../../util/Util'); const { dependencies, optionalDependencies } = require('../../package'); const deps = Object.keys({ ...dependencies, ...optionalDependencies }).sort(); @@ -17,7 +18,7 @@ module.exports = class GenerateCreditCommand extends Command { } async run(msg) { - const npm = `* ${deps.map(dep => `[${dep}](https://www.npmjs.com/package/${dep})`).join('\n* ')}`; + const npm = `* ${deps.map(dep => embedURL(dep, `https://www.npmjs.com/package/${dep}`)).join('\n* ')}`; const list = this.client.registry.groups .map(g => { const commands = g.commands @@ -28,8 +29,8 @@ module.exports = class GenerateCreditCommand extends Command { const credits = c.credit .filter(cred => cred.name !== 'Dragon Fire') .map(cred => { - const reason = cred.reasonURL ? `[${cred.reason}](${cred.reasonURL})` : cred.reason; - return `[${cred.name}](${cred.url}) (${reason})`; + const reason = cred.reasonURL ? embedURL(cred.reason, cred.reasonURL) : cred.reason; + return `${embedURL(cred.name, cred.url)} (${reason})`; }); return `* **${c.name}:**\n - ${credits.join('\n - ')}`; }).join('\n');