diff --git a/commands/games-sp/will-you-press-the-button.js b/commands/games-sp/will-you-press-the-button.js
index 5bbaecd9..3ff216f6 100644
--- a/commands/games-sp/will-you-press-the-button.js
+++ b/commands/games-sp/will-you-press-the-button.js
@@ -1,7 +1,8 @@
const Command = require('../../structures/Command');
const request = require('node-superfetch');
+const { unescape } = require('html-escaper');
const { stripIndents } = require('common-tags');
-const { verify, cleanHTML } = require('../../util/Util');
+const { verify } = require('../../util/Util');
module.exports = class WillYouPressTheButtonCommand extends Command {
constructor(client) {
@@ -28,7 +29,7 @@ module.exports = class WillYouPressTheButtonCommand extends Command {
try {
const dilemma = await this.fetchDilemma();
await msg.reply(stripIndents`
- **${cleanHTML(dilemma.txt1)}** but **${cleanHTML(dilemma.txt2)}**
+ **${unescape(dilemma.txt1)}** but **${unescape(dilemma.txt2)}**
Will you press the button?
_Respond with [y]es or [n]o to continue._
diff --git a/commands/search/anime-character.js b/commands/search/anime-character.js
index 3eb2daa7..2894f4de 100644
--- a/commands/search/anime-character.js
+++ b/commands/search/anime-character.js
@@ -2,7 +2,7 @@ const Command = require('../../structures/Command');
const { MessageEmbed } = require('discord.js');
const request = require('node-superfetch');
const { stripIndents } = require('common-tags');
-const { embedURL, cleanHTML, trimArray } = require('../../util/Util');
+const { embedURL, cleanAnilistHTML, trimArray } = require('../../util/Util');
const searchGraphQL = stripIndents`
query ($search: String) {
characters: Page (perPage: 1) {
@@ -82,7 +82,7 @@ module.exports = class AnimeCharacterCommand extends Command {
.setURL(character.siteUrl)
.setThumbnail(character.image.large || character.image.medium || null)
.setTitle(`${character.name.first || ''}${character.name.last ? ` ${character.name.last}` : ''}`)
- .setDescription(character.description ? cleanHTML(character.description, false) : 'No description.')
+ .setDescription(character.description ? cleanAnilistHTML(character.description, false) : 'No description.')
.addField('❯ Appearances', trimArray(character.media.edges.map(edge => {
const title = edge.node.title.english || edge.node.title.userPreferred;
return embedURL(`${title} (${types[edge.node.type]})`, edge.node.siteUrl);
diff --git a/commands/search/anime.js b/commands/search/anime.js
index d66e6e72..721f8070 100644
--- a/commands/search/anime.js
+++ b/commands/search/anime.js
@@ -3,7 +3,7 @@ const { MessageEmbed } = require('discord.js');
const request = require('node-superfetch');
const cheerio = require('cheerio');
const { stripIndents } = require('common-tags');
-const { cleanHTML, embedURL } = require('../../util/Util');
+const { cleanAnilistHTML, embedURL } = require('../../util/Util');
const ANILIST_USERNAME = process.env.ANILIST_USERNAME || 'dragonfire535';
const searchGraphQL = stripIndents`
query ($search: String, $type: MediaType, $isAdult: Boolean) {
@@ -124,7 +124,7 @@ module.exports = class AnimeCommand extends Command {
.setURL(anime.siteUrl)
.setThumbnail(anime.coverImage.large || anime.coverImage.medium || null)
.setTitle(anime.title.english || anime.title.romaji)
- .setDescription(anime.description ? cleanHTML(anime.description) : 'No description.')
+ .setDescription(anime.description ? cleanAnilistHTML(anime.description) : 'No description.')
.addField('❯ Status', statuses[anime.status], true)
.addField('❯ Episodes', anime.episodes || '???', true)
.addField('❯ Season', anime.season ? `${seasons[anime.season]} ${anime.startDate.year}` : '???', true)
diff --git a/commands/search/manga.js b/commands/search/manga.js
index 2cb06a8d..e80ee677 100644
--- a/commands/search/manga.js
+++ b/commands/search/manga.js
@@ -3,7 +3,7 @@ const { MessageEmbed } = require('discord.js');
const request = require('node-superfetch');
const cheerio = require('cheerio');
const { stripIndents } = require('common-tags');
-const { cleanHTML, embedURL } = require('../../util/Util');
+const { cleanAnilistHTML, embedURL } = require('../../util/Util');
const ANILIST_USERNAME = process.env.ANILIST_USERNAME || 'dragonfire535';
const searchGraphQL = stripIndents`
query ($search: String, $type: MediaType, $isAdult: Boolean) {
@@ -118,7 +118,7 @@ module.exports = class MangaCommand extends Command {
.setURL(manga.siteUrl)
.setThumbnail(manga.coverImage.large || manga.coverImage.medium || null)
.setTitle(manga.title.english || manga.title.romaji)
- .setDescription(manga.description ? cleanHTML(manga.description) : 'No description.')
+ .setDescription(manga.description ? cleanAnilistHTML(manga.description) : 'No description.')
.addField('❯ Status', statuses[manga.status], true)
.addField('❯ Chapters / Volumes', `${manga.chapters || '???'}/${manga.volumes || '???'}`, true)
.addField('❯ Year', manga.startDate.year || '???', true)
diff --git a/package.json b/package.json
index bb08a7d7..efd32c6b 100644
--- a/package.json
+++ b/package.json
@@ -44,11 +44,12 @@
"discord.js": "^12.3.1",
"discord.js-commando": "github:discordjs/Commando",
"dotenv": "^8.2.0",
- "eslint": "^7.10.0",
+ "eslint": "^7.11.0",
"gifencoder": "^2.0.1",
"gm": "^1.23.1",
+ "html-escaper": "^3.0.0",
"js-beautify": "^1.13.0",
- "mathjs": "^7.5.0",
+ "mathjs": "^7.5.1",
"moment": "^2.29.1",
"moment-duration-format": "^2.3.2",
"moment-timezone": "^0.5.31",
diff --git a/util/Util.js b/util/Util.js
index c67c25ce..4eb28330 100644
--- a/util/Util.js
+++ b/util/Util.js
@@ -1,4 +1,5 @@
const crypto = require('crypto');
+const { unescape } = require('html-escaper');
const { SUCCESS_EMOJI_ID } = process.env;
const yes = ['yes', 'y', 'ye', 'yeah', 'yup', 'yea', 'ya', 'hai', 'si', 'sí', 'oui', 'はい', 'correct'];
const no = ['no', 'n', 'nah', 'nope', 'nop', 'iie', 'いいえ', 'non', 'fuck off'];
@@ -202,17 +203,15 @@ module.exports = class Util {
return verify.map(player => player.author.id);
}
- static cleanHTML(html, removeLineBreaks = true) {
+ static cleanAnilistHTML(html, removeLineBreaks = true) {
let clean = html;
if (removeLineBreaks) clean = clean.replace(/\r|\n|\f/g, '');
+ clean = unescape(clean);
clean = clean
- .replace(/
/g, '\n')
- .replace(/'/g, '\'')
- .replace(/"/g, '"')
+ .replace(/
/g, '*')
.replace(/<\/?b>/g, '**')
- .replace(/~!|!~/g, '||')
- .replace(/—/g, '—');
+ .replace(/~!|!~/g, '||');
if (clean.length > 2000) clean = `${clean.substr(0, 1995)}...`;
const spoilers = (clean.match(/\|\|/g) || []).length;
if (spoilers !== 0 && (spoilers && (spoilers % 2))) clean += '||';