Send over all user id's to Lanista

This commit is contained in:
Kalle
2022-03-17 01:29:19 +02:00
parent 0dedf45552
commit 23bbea328c
3 changed files with 4 additions and 19 deletions

View File

@@ -1,6 +1,5 @@
import { Mode } from "@prisma/client";
import { fetchTimeout } from "~/utils";
import { playersWithResults } from "./play/playerInfos/playerInfos.server";
const LANISTA_REQUEST_TIMEOUT = 7000;
@@ -26,19 +25,13 @@ export async function requestMatchDetails({
throw new Error("process.env.LANISTA_URL not set");
}
// there is nothing Lanista can do for us in this case
// -> user should link and try again later manually
if (playersWithResults(playerDiscordIds).length === 0) {
return;
}
const response = await fetchTimeout(
process.env.LANISTA_URL,
LANISTA_REQUEST_TIMEOUT,
{
body: JSON.stringify({
maplist: playedStages,
requesterId: playersWithResults(playerDiscordIds),
requesterId: playerDiscordIds,
startTime: startTime.toISOString(),
endTime: (endTime ?? new Date()).toISOString(),
matchId,

View File

@@ -7,7 +7,6 @@ import rawInfos from "./data.json";
const infos = rawInfos as Partial<
Record<string, { weapons?: string[]; peakXP?: number; peakLP?: number }>
>;
const idsWithResults = new Set(Object.keys(infos));
export function addInfoFromOldSendouInk(
type: "LEAGUE" | "SOLO",
@@ -36,10 +35,6 @@ export function addInfoFromOldSendouInk(
}
}
export function playersWithResults(discordIds: string[]): string[] {
return discordIds.filter((id) => idsWithResults.has(id));
}
export function userHasTop500Result({ discordId }: { discordId?: string }) {
if (!discordId) return false;
return Boolean(infos[discordId]?.peakXP);

View File

@@ -1,5 +1,4 @@
import { PrismaClient } from "@prisma/client";
import { playersWithResults } from "~/core/play/playerInfos/playerInfos.server";
import fs from "fs";
const prisma = new PrismaClient();
@@ -21,15 +20,11 @@ async function main() {
}[] = [];
for (const match of matches) {
const players = playersWithResults(
match.groups.flatMap((g) => g.members).flatMap((m) => m.user.discordId)
);
const mapList = match.stages
.sort((a, b) => a.order - b.order)
.filter((stage) => stage.winnerGroupId)
.map((stage) => ({ map: stage.stage.name, mode: stage.stage.mode }));
if (!players.length) continue;
if (!mapList.length) continue;
result.push({
@@ -37,7 +32,9 @@ async function main() {
mapList,
start_time: match.createdAt.toISOString(),
end_time: new Date(match.createdAt.getTime() + 60 * 60000).toISOString(),
players,
players: match.groups
.flatMap((g) => g.members)
.flatMap((m) => m.user.discordId),
});
}