feat: cleaned up directories

This commit is contained in:
TresAbhi committed 2023-05-13 22:01:58 +00:00
1 parent 473ebfa46c
commit 613527e78f
41 files changed
+116 -832

No files matched your search

+54
View File
@@ -0,0 +1,54 @@
import {
CacheType,
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 { Players } from '../../types/players.js';
import { args } from '../process/args.js';
import getWargamingResponse from './getWargamingResponse.js';
export default async function getBlitzAccount(
interaction: ChatInputCommandInteraction<CacheType>,
name: string,
server: BlitzServer,
) {
const serverName = BLITZ_SERVERS[server];
const players = await getWargamingResponse<Players>(
`https://api.wotblitz.${server}/wotb/account/list/?application_id=${args['wargaming-application-id']}&search=${name}`,
);
if (
players.length > 0 &&
players[0].nickname.toLowerCase() === name.toLowerCase()
) {
return players[0];
} else {
// no exact match
await interaction.editReply({
embeds: [
new EmbedBuilder()
.setColor(NEGATIVE_COLOR)
.setTitle(`Account not found`)
.setDescription(
`I couldn't find "${markdownEscape(
name,
)}" in the ${serverName} server. I found ${
players ? (players.length < 100 ? players.length : 'over 100') : 0
} similarly spelled account${players?.length !== 1 ? 's' : ''}. ${
players && players.length > 0
? `Did you mean "${markdownEscape(players[0].nickname)}"? `
: ''
}Use the \`/verify\` command to fix any issues or re-run the command and don't make typos.`,
),
],
});
console.log(`Account not found for ${name} in ${serverName} server.`);
return null;
}
}
+57
View File
@@ -0,0 +1,57 @@
import {
CacheType,
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 { ClanList } from '../../types/clanList.js';
import { args } from '../process/args.js';
import getWargamingResponse from './getWargamingResponse.js';
export default async function getClan(
interaction: ChatInputCommandInteraction<CacheType>,
name: string,
server: BlitzServer,
) {
const serverName = BLITZ_SERVERS[server];
const clans = await getWargamingResponse<ClanList>(
`https://api.wotblitz.${server}/wotb/clans/list/?application_id=${args['wargaming-application-id']}&search=${name}`,
);
if (
clans.length > 0 &&
(clans[0].name.toLowerCase() === name.toLowerCase() ||
clans[0].tag.toLowerCase() === name.toLowerCase())
) {
return clans[0];
} else {
// no exact match
await interaction.editReply({
embeds: [
new EmbedBuilder()
.setColor(NEGATIVE_COLOR)
.setTitle(`Clan not found`)
.setDescription(
`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 "${markdownEscape(
clans[0].name,
)}" or "${markdownEscape(clans[0].tag)}"? `
: ''
}Re-run the command, don't make typos.`,
),
],
});
console.log(`Clan not found for ${name} in ${serverName} server.`);
return null;
}
}
+18
View File
@@ -0,0 +1,18 @@
import fetch from 'node-fetch';
import { WargamingResponse } from '../../types/wargamingResponse.js';
export default async function getWargamingResponse<Data extends object>(
url: string,
) {
let parsed: WargamingResponse<Data>;
const response = await fetch(url);
parsed = (await response.json()) as WargamingResponse<Data>;
if (parsed.status === 'ok') {
return parsed.data;
} else {
console.error(`Wargaming response status ${parsed.status}`);
return null;
}
}
+26
View File
@@ -0,0 +1,26 @@
import {
CacheType,
ChatInputCommandInteraction,
EmbedBuilder,
} from 'discord.js';
import { handleError } from '../../behaviors/error.js';
import { NEGATIVE_COLOR } from '../../constants/colors.js';
import { client } from '../../index.js';
export default async function wargamingError(
interaction: ChatInputCommandInteraction<CacheType>,
error: Error,
command: string,
) {
await interaction.editReply({
embeds: [
new EmbedBuilder()
.setColor(NEGATIVE_COLOR)
.setTitle(`${client.user?.username} ran into an issue`)
.setDescription('Wargaming returned an error. Please try again later.'),
],
});
console.log(`Wargaming returned an error`);
handleError(error, client, command);
}