feat: markdownEscape

This commit is contained in:
TresAbhi committed 2023-05-06 17:45:43 +00:00
1 parent 01b5ec9bc2
commit 5ef1f87236
11 files changed
+75 -26

No files matched your search

+9 -4
View File
@@ -1,4 +1,5 @@
import { EmbedBuilder, SlashCommandBuilder } from 'discord.js';
import markdownEscape from 'markdown-escape';
import { CommandRegistry } from '../behaviors/interactionCreate.js';
import { NEGATIVE_COLOR, POSITIVE_COLOR } from '../constants/colors.js';
import { BlitzServer } from '../constants/servers.js';
@@ -108,7 +109,7 @@ export default {
poweredByBlitzStars(
new EmbedBuilder()
.setTitle(
`${data.nickname} is ${
`${markdownEscape(data.nickname)} is ${
eligible ? '' : 'not '
}eligible for ${CLANS[clan].name}`,
)
@@ -116,10 +117,14 @@ export default {
.setDescription(
`${
eligible
? `${data.nickname} meets all the requirements set for ${CLANS[clan].name}.`
: `${data.nickname}'s shortcomings for ${
? `${markdownEscape(
data.nickname,
)} meets all the requirements set for ${
CLANS[clan].name
} (${
}.`
: `${markdownEscape(
data.nickname,
)}'s shortcomings for ${CLANS[clan].name} (${
clan === 'sklld' ? '30 days stats' : 'career stats'
}):\n\n${issues.join('\n')}`
}\n\n${blitzLinks(data)}`,
+6 -3
View File
@@ -1,4 +1,5 @@
import { EmbedBuilder, SlashCommandBuilder } from 'discord.js';
import markdownEscape from 'markdown-escape';
import { CommandRegistry } from '../behaviors/interactionCreate.js';
import { NEGATIVE_COLOR, POSITIVE_COLOR } from '../constants/colors.js';
import { BlitzServer } from '../constants/servers.js';
@@ -68,7 +69,9 @@ export default {
.sort((a, b) => b[1] - a[1])
.map(([nickname, inactiveDays]) => {
const days = Math.floor(inactiveDays);
return `**${nickname}**: ${days} day${days === 1 ? '' : 's'}`;
return `**${markdownEscape(nickname)}**: ${days} day${
days === 1 ? '' : 's'
}`;
});
const hasInactiveMembers = inactiveInfo.length > 0;
@@ -80,8 +83,8 @@ export default {
)
.setTitle(
hasInactiveMembers
? `${clan.name}'s inactive members`
: `No inactive members in ${clan.name}`,
? `${markdownEscape(clan.name)}'s inactive members`
: `No inactive members in ${markdownEscape(clan.name)}`,
)
.setDescription(
hasInactiveMembers
+5 -2
View File
@@ -1,4 +1,5 @@
import { EmbedBuilder, SlashCommandBuilder } from 'discord.js';
import markdownEscape from 'markdown-escape';
import { CommandRegistry } from '../behaviors/interactionCreate.js';
import { SKILLED_COLOR } from '../constants/colors.js';
import { Players } from '../types/players.js';
@@ -38,12 +39,14 @@ export default {
embeds: [
new EmbedBuilder()
.setColor(SKILLED_COLOR)
.setTitle(`Player search results for "${name}"`)
.setTitle(`Player search results for "${markdownEscape(name)}"`)
.setDescription(
`\`\`\`${
players.length === 0
? 'No players found.'
: players.map((player) => player.nickname).join('\n')
: players
.map((player) => markdownEscape(player.nickname))
.join('\n')
}\`\`\``,
),
],
+2 -1
View File
@@ -1,4 +1,5 @@
import { EmbedBuilder, SlashCommandBuilder } from 'discord.js';
import markdownEscape from 'markdown-escape';
import { CommandRegistry } from '../behaviors/interactionCreate.js';
import { SKILLED_COLOR } from '../constants/colors.js';
import { BlitzServer } from '../constants/servers.js';
@@ -55,7 +56,7 @@ export default {
new EmbedBuilder()
.setColor(SKILLED_COLOR)
.setTitle(
`${data.nickname}'s ${
`${markdownEscape(data.nickname)}'s ${
period === 'career' ? period : `${period} day`
} stats`,
)
+6 -5
View File
@@ -1,4 +1,5 @@
import { EmbedBuilder, SlashCommandBuilder } from 'discord.js';
import markdownEscape from 'markdown-escape';
import { CommandRegistry } from '../behaviors/interactionCreate.js';
import { SKILLED_COLOR } from '../constants/colors.js';
import { BlitzServer } from '../constants/servers.js';
@@ -68,20 +69,20 @@ export default {
embeds: [
new EmbedBuilder()
.setTitle(
`${account.nickname}'s owned ${
`${markdownEscape(account.nickname)}'s owned ${
tier === null ? '' : `tier ${tier} `
}tanks`,
)
.setDescription(
`${
tanks.length === 0
? `No tanks found for player in tier ${tier}`
? `No tanks found in tier ${tier}`
: tanks
.map(
(tank) =>
`${TANK_TYPE_EMOJIS[tank.type]} ${tank.name} ${
tank.is_premium ? '⭐' : ''
}${
`${TANK_TYPE_EMOJIS[tank.type]} ${markdownEscape(
tank.name,
)} ${tank.is_premium ? '⭐' : ''}${
COMP_TANKS.includes(tank.tank_id) ? '🏆' : ''
}`,
)
+9 -2
View File
@@ -1,4 +1,5 @@
import { EmbedBuilder, SlashCommandBuilder } from 'discord.js';
import markdownEscape from 'markdown-escape';
import discord from '../../discord.json' assert { type: 'json' };
import { CommandRegistry } from '../behaviors/interactionCreate.js';
import { NEGATIVE_COLOR, POSITIVE_COLOR } from '../constants/colors.js';
@@ -52,7 +53,9 @@ export default {
.setColor(POSITIVE_COLOR)
.setTitle(`${interaction.user.username} is verified`)
.setDescription(
`The user is now verified as ${name}${clanTag}`,
`The user is now verified as ${markdownEscape(
name,
)}${markdownEscape(clanTag)}`,
),
],
});
@@ -66,7 +69,11 @@ export default {
embeds: [
new EmbedBuilder()
.setColor(NEGATIVE_COLOR)
.setTitle(`${interaction.user.username} failed to verify`)
.setTitle(
`${markdownEscape(
interaction.user.username,
)} failed to verify`,
)
.setDescription(
'I may not have the permission to change your nickname.',
),
+10 -4
View File
@@ -3,6 +3,7 @@ import {
ChatInputCommandInteraction,
EmbedBuilder,
} from 'discord.js';
import markdownEscape from 'markdown-escape';
import { NEGATIVE_COLOR } from '../constants/colors.js';
import { BLITZ_SERVERS, BlitzServer } from '../constants/servers.js';
import { Player, Players } from '../types/players.js';
@@ -21,7 +22,10 @@ export default async function getBlitzAccount(
`https://api.wotblitz.${server}/wotb/account/list/?application_id=${args['wargaming-application-id']}&search=${name}`,
interaction,
async (players) => {
if (players.length > 0 && players[0].nickname === name) {
if (
players.length > 0 &&
players[0].nickname.toLowerCase() === name.toLowerCase()
) {
callback(players[0]);
} else {
// no exact match
@@ -31,7 +35,9 @@ export default async function getBlitzAccount(
.setColor(NEGATIVE_COLOR)
.setTitle(`Account not found`)
.setDescription(
`I couldn't find "${name}" in the ${serverName} server. I found ${
`I couldn't find "${markdownEscape(
name,
)}" in the ${serverName} server. I found ${
players
? players.length < 100
? players.length
@@ -41,9 +47,9 @@ export default async function getBlitzAccount(
players?.length !== 1 ? 's' : ''
}. ${
players && players.length > 0
? `Did you mean "${players[0].nickname}"? `
? `Did you mean "${markdownEscape(players[0].nickname)}"? `
: ''
}Re-run the command, don't make typos, and capitalize correctly.`,
}Re-run the command and don't make typos.`,
),
],
});
+4 -1
View File
@@ -3,6 +3,7 @@ import {
ChatInputCommandInteraction,
EmbedBuilder,
} from 'discord.js';
import markdownEscape from 'markdown-escape';
import fetch from 'node-fetch';
import { NEGATIVE_COLOR } from '../constants/colors.js';
import { PlayerStatistics } from '../types/statistics.js';
@@ -20,7 +21,9 @@ export default async function getBlitzStarsAccount(
embeds: [
new EmbedBuilder()
.setTitle('No data to display')
.setDescription(`${name} is not tracked by BlitzStars.`)
.setDescription(
`${markdownEscape(name)} is not tracked by BlitzStars.`,
)
.setColor(NEGATIVE_COLOR),
],
});
+10 -4
View File
@@ -3,6 +3,7 @@ import {
ChatInputCommandInteraction,
EmbedBuilder,
} from 'discord.js';
import markdownEscape from 'markdown-escape';
import { NEGATIVE_COLOR } from '../constants/colors.js';
import { BLITZ_SERVERS, BlitzServer } from '../constants/servers.js';
import { Clan, ClanList } from '../types/clanList.js';
@@ -23,7 +24,8 @@ export default async function getClan(
async (clans) => {
if (
clans.length > 0 &&
(clans[0].name === name || clans[0].tag === name.toUpperCase())
(clans[0].name.toLowerCase() === name.toLowerCase() ||
clans[0].tag.toLowerCase() === name.toLowerCase())
) {
callback(clans[0]);
} else {
@@ -34,13 +36,17 @@ export default async function getClan(
.setColor(NEGATIVE_COLOR)
.setTitle(`Clan not found`)
.setDescription(
`I couldn't find "${name}" in the ${serverName} server. I found ${
`I couldn't find "${markdownEscape(
name,
)}" in the ${serverName} server. I found ${
clans ? (clans.length < 100 ? clans.length : 'over 100') : 0
} similarly spelled clan${clans?.length !== 1 ? 's' : ''}. ${
clans && clans.length > 0
? `Did you mean "${clans[0].name}" or "${clans[0].tag}"? `
? `Did you mean "${markdownEscape(
clans[0].name,
)}" or "${markdownEscape(clans[0].tag)}"? `
: ''
}Re-run the command, don't make typos, and capitalize correctly.`,
}Re-run the command, don't make typos.`,
),
],
});