mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-22 11:17:05 +02:00
feat: general inactive command
This commit is contained in:
1 parent
468bca77de
commit
57cc67c8be
10 files changed
+189
-115
No files matched your search
@@ -10,19 +10,19 @@ import { Player, Players } from '../types/players.js';
|
||||
|
||||
export default async function getBlitzAccount(
|
||||
interaction: ChatInputCommandInteraction<CacheType>,
|
||||
ign: string,
|
||||
name: string,
|
||||
server: BlitzServer,
|
||||
callback: (account: Player) => void,
|
||||
) {
|
||||
const serverName = BLITZ_SERVERS[server];
|
||||
const players = (await fetch(
|
||||
`https://api.wotblitz.${server}/wotb/account/list/?application_id=${process.env.WARGAMING_APPLICATION_ID}&search=${ign}`,
|
||||
`https://api.wotblitz.${server}/wotb/account/list/?application_id=${process.env.WARGAMING_APPLICATION_ID}&search=${name}`,
|
||||
).then((response) => response.json())) as Players;
|
||||
|
||||
if (
|
||||
players.status === 'ok' &&
|
||||
players.data.length > 0 &&
|
||||
players.data[0].nickname === ign
|
||||
players.data[0].nickname === name
|
||||
) {
|
||||
callback(players.data[0]);
|
||||
} else {
|
||||
@@ -33,7 +33,7 @@ export default async function getBlitzAccount(
|
||||
.setColor(NEGATIVE_COLOR)
|
||||
.setTitle(`Account not found`)
|
||||
.setDescription(
|
||||
`I couldn't find "${ign}" in the ${serverName} server. I found ${
|
||||
`I couldn't find "${name}" in the ${serverName} server. I found ${
|
||||
players?.data
|
||||
? players.data.length < 100
|
||||
? players.data.length
|
||||
|
||||
@@ -10,7 +10,7 @@ import { PlayerStatistics } from '../types/statistics.js';
|
||||
export default async function getBlitzStarsAccount(
|
||||
interaction: ChatInputCommandInteraction<CacheType>,
|
||||
accountId: number,
|
||||
ign: string,
|
||||
name: string,
|
||||
callback: (account: PlayerStatistics) => void,
|
||||
) {
|
||||
function notTracked() {
|
||||
@@ -18,7 +18,7 @@ export default async function getBlitzStarsAccount(
|
||||
embeds: [
|
||||
new EmbedBuilder()
|
||||
.setTitle('No data to display')
|
||||
.setDescription(`${ign} is not tracked by BlitzStars.`)
|
||||
.setDescription(`${name} is not tracked by BlitzStars.`)
|
||||
.setColor(NEGATIVE_COLOR),
|
||||
],
|
||||
});
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
import {
|
||||
CacheType,
|
||||
ChatInputCommandInteraction,
|
||||
EmbedBuilder,
|
||||
} from 'discord.js';
|
||||
import fetch from 'node-fetch';
|
||||
import { NEGATIVE_COLOR } from '../constants/colors.js';
|
||||
import { BLITZ_SERVERS, BlitzServer } from '../constants/servers.js';
|
||||
import { Clan, ClanList } from '../types/clanList.js';
|
||||
|
||||
export default async function getClan(
|
||||
interaction: ChatInputCommandInteraction<CacheType>,
|
||||
name: string,
|
||||
server: BlitzServer,
|
||||
callback: (account: Clan) => void,
|
||||
) {
|
||||
const serverName = BLITZ_SERVERS[server];
|
||||
|
||||
const clans = (await fetch(
|
||||
`https://api.wotblitz.${server}/wotb/clans/list/?application_id=${process.env.WARGAMING_APPLICATION_ID}&search=${name}`,
|
||||
).then((response) => response.json())) as ClanList;
|
||||
|
||||
if (
|
||||
clans.status === 'ok' &&
|
||||
clans.data.length > 0 &&
|
||||
(clans.data[0].name === name || clans.data[0].tag === name.toUpperCase())
|
||||
) {
|
||||
callback(clans.data[0]);
|
||||
} else {
|
||||
// no exact match
|
||||
interaction.reply({
|
||||
embeds: [
|
||||
new EmbedBuilder()
|
||||
.setColor(NEGATIVE_COLOR)
|
||||
.setTitle(`Clan not found`)
|
||||
.setDescription(
|
||||
`I couldn't find "${name}" in the ${serverName} server. I found ${
|
||||
clans?.data
|
||||
? clans.data.length < 100
|
||||
? clans.data.length
|
||||
: 'over 100'
|
||||
: 0
|
||||
} similarly spelled clan${clans?.data?.length !== 1 ? 's' : ''}. ${
|
||||
clans?.data && clans.data.length > 0
|
||||
? `Did you mean "${clans.data[0].name}" or "${clans.data[0].tag}"? `
|
||||
: ''
|
||||
}Re-run the command, don't make typos, and capitalize correctly.`,
|
||||
),
|
||||
],
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user