mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-21 10:47:04 +02:00
feat: base work
This commit is contained in:
1 parent
9d715c23e5
commit
310640c1ec
6 files changed
+38
-10
No files matched your search
@@ -0,0 +1,32 @@
|
||||
import { Locale } from 'discord.js';
|
||||
import { REGIONS } from '../src/constants/regions';
|
||||
import getTankStats from '../src/core/blitz/getTankStats';
|
||||
import { idToRegion } from '../src/core/blitz/idToRegion';
|
||||
import usersRaw from '../test.users.json';
|
||||
|
||||
let done = 0;
|
||||
|
||||
const users = usersRaw.slice(0, 100);
|
||||
const regionUsers = REGIONS.map((region) =>
|
||||
users.filter((user) => idToRegion(user.blitz) === region),
|
||||
);
|
||||
const regionChunkedUsers = await Promise.all(
|
||||
regionUsers.map(async (regionUsers, index) => {
|
||||
return await Promise.all(
|
||||
regionUsers.map(async (user) => {
|
||||
const region = REGIONS[index];
|
||||
const stats = await getTankStats(region, user.blitz, Locale.EnglishUS);
|
||||
|
||||
console.log(`Fetch user ${++done} / ${users.length}`);
|
||||
|
||||
return stats;
|
||||
}),
|
||||
);
|
||||
}),
|
||||
);
|
||||
|
||||
regionChunkedUsers.map((users, regionIndex) => {
|
||||
const region = REGIONS[regionIndex];
|
||||
|
||||
console.log(region, users.length);
|
||||
});
|
||||
@@ -10,7 +10,8 @@ type BlitzResponse<Data extends object> =
|
||||
data: Data;
|
||||
};
|
||||
|
||||
const MAX_CALLS_PER_SECOND = 10;
|
||||
// 1 less than 10 to ensure not bad things lol
|
||||
const MAX_CALLS_PER_SECOND = 9;
|
||||
|
||||
const queue: { url: string; resolve: (data: object) => void }[] = [];
|
||||
let inProgress = 0;
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import { Locale } from 'discord.js';
|
||||
import { Region } from '../../constants/regions';
|
||||
import { WARGAMING_APPLICATION_ID } from '../../constants/wargamingApplicationID';
|
||||
import { UserError } from '../../hooks/userError';
|
||||
import { TanksStats } from '../../types/tanksStats';
|
||||
import { translator } from '../localization/translator';
|
||||
import fetchBlitz from './fetchBlitz';
|
||||
@@ -16,9 +15,5 @@ export default async function getTankStats(
|
||||
`https://api.wotblitz.${region}/wotb/tanks/stats/?application_id=${WARGAMING_APPLICATION_ID}&account_id=${id}`,
|
||||
);
|
||||
|
||||
if (tankStats[id] === null) {
|
||||
throw new UserError(t`bot.common.errors.no_tank_stats`);
|
||||
}
|
||||
|
||||
return tankStats[id];
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
import { Region } from '../../constants/regions';
|
||||
|
||||
export function idToRange(id: number): Region {
|
||||
export function idToRegion(id: number): Region {
|
||||
if (id >= 42e8) {
|
||||
throw new Error('bot id');
|
||||
} else if (id >= 31e8) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { usersDatabase } from '../../databases/users';
|
||||
import { idToRange } from '../blitz/idToRegion';
|
||||
import { idToRegion } from '../blitz/idToRegion';
|
||||
|
||||
export async function flagUserActivity(blitz: number) {
|
||||
await usersDatabase.users.upsert({
|
||||
@@ -26,5 +26,5 @@ export async function getBlitzFromDiscord(discord: bigint) {
|
||||
if (unique === null) return null;
|
||||
|
||||
await flagUserActivity(unique.blitz);
|
||||
return { id: unique.blitz, region: idToRange(unique.blitz) };
|
||||
return { id: unique.blitz, region: idToRegion(unique.blitz) };
|
||||
}
|
||||
@@ -15,7 +15,7 @@ export interface IndividualTankStats {
|
||||
}
|
||||
|
||||
export interface TanksStats {
|
||||
[accountId: number]: IndividualTankStats[];
|
||||
[accountId: number]: null | IndividualTankStats[];
|
||||
}
|
||||
|
||||
export interface NormalizedTankStats {
|
||||
|
||||
Reference in new issue
Block a user