aboutsummaryrefslogtreecommitdiff
path: root/src/plugins/urbanDictionary.ts
diff options
context:
space:
mode:
authorHunter <70922563+HunterAPI@users.noreply.github.com>2023-05-16 22:40:40 -0400
committerGitHub <noreply@github.com>2023-05-17 04:40:40 +0200
commitc2a1c4cbf624486ebfc0e907bd0c9c43e4b6a579 (patch)
treed6ff29573cfd9d5d20b0773536583a4f4a50468f /src/plugins/urbanDictionary.ts
parent1d6b78f6c660f0cd6905552243a3908366a28595 (diff)
downloadVencord-c2a1c4cbf624486ebfc0e907bd0c9c43e4b6a579.tar.gz
Vencord-c2a1c4cbf624486ebfc0e907bd0c9c43e4b6a579.tar.bz2
Vencord-c2a1c4cbf624486ebfc0e907bd0c9c43e4b6a579.zip
Urban Dictionary: better embed (#1127)
Co-authored-by: V <vendicated@riseup.net>
Diffstat (limited to 'src/plugins/urbanDictionary.ts')
-rw-r--r--src/plugins/urbanDictionary.ts35
1 files changed, 23 insertions, 12 deletions
diff --git a/src/plugins/urbanDictionary.ts b/src/plugins/urbanDictionary.ts
index 0adf8a5..840fe5c 100644
--- a/src/plugins/urbanDictionary.ts
+++ b/src/plugins/urbanDictionary.ts
@@ -41,37 +41,48 @@ export default definePlugin({
],
execute: async (args, ctx) => {
try {
- const { list: [definition] } = await (await fetch(`https://api.urbandictionary.com/v0/define?term=${args[0].value}`)).json();
+ const query = encodeURIComponent(args[0].value);
+ const { list: [definition] } = await (await fetch(`https://api.urbandictionary.com/v0/define?term=${query}`)).json();
if (!definition)
return void sendBotMessage(ctx.channel.id, { content: "No results found." });
- const linkify = text => text.replace(/\[(.+?)\]/g, (_, word) => `[${word}](https://www.urbandictionary.com/define.php?term=${encodeURIComponent(word)})`);
+ const linkify = (text: string) => text
+ .replaceAll("\r\n", "\n")
+ .replace(/([*>_`~\\])/gsi, "\\$1")
+ .replace(/\[(.+?)\]/g, (_, word) => `[${word}](https://www.urbandictionary.com/define.php?term=${encodeURIComponent(word)} "Define '${word}' on Urban Dictionary")`)
+ .trim();
return void sendBotMessage(ctx.channel.id, {
embeds: [
{
type: "rich",
author: {
- name: `Definition of ${definition.word}`,
- url: definition.permalink
+ name: `Uploaded by "${definition.author}"`,
+ url: `https://www.urbandictionary.com/author.php?author=${encodeURIComponent(definition.author)}`,
},
+ title: definition.word,
+ url: `https://www.urbandictionary.com/define.php?term=${encodeURIComponent(definition.word)}`,
description: linkify(definition.definition),
fields: [
{
name: "Example",
- value: linkify(definition.example)
- }
+ value: linkify(definition.example),
+ },
+ {
+ name: "Want more definitions?",
+ value: `Check out [more definitions](https://www.urbandictionary.com/define.php?term=${query} "Define "${args[0].value}" on Urban Dictionary") on Urban Dictionary.`,
+ },
],
color: 0xFF9900,
- footer: { text: `👍 ${definition.thumbs_up.toString()} | 👎 ${definition.thumbs_down.toString()} | Uploaded by ${definition.author}`, icon_url: "https://www.urbandictionary.com/favicon.ico" },
- timestamp: new Date(definition.written_on).toISOString()
- }
- ] as any
+ footer: { text: `👍 ${definition.thumbs_up.toString()} | 👎 ${definition.thumbs_down.toString()}`, icon_url: "https://www.urbandictionary.com/favicon.ico" },
+ timestamp: new Date(definition.written_on).toISOString(),
+ },
+ ] as any,
});
} catch (error) {
- return void sendBotMessage(ctx.channel.id, {
- content: `Something went wrong: \`${error}\``
+ sendBotMessage(ctx.channel.id, {
+ content: `Something went wrong: \`${error}\``,
});
}
}