FC scripts

This commit is contained in:
Kalle 2024-04-14 14:02:33 +03:00
parent 4aa9c50413
commit 5c9ebfd2f0
2 changed files with 97 additions and 0 deletions

38
scripts/fc-lookup.ts Normal file
View File

@ -0,0 +1,38 @@
import "dotenv/config";
import invariant from "tiny-invariant";
import { db } from "~/db/sql";
import { logger } from "~/utils/logger";
const friendCode = process.argv[2]?.trim();
invariant(friendCode, "friend code is required (argument 1)");
async function main() {
const allFcs = await db
.selectFrom("UserFriendCode")
.innerJoin("User", "User.id", "UserFriendCode.userId")
.select([
"UserFriendCode.friendCode",
"User.id as userId",
"User.discordId",
"User.discordUniqueName",
])
.orderBy("UserFriendCode.createdAt", "asc")
.whereRef("User.id", "=", "UserFriendCode.submitterUserId")
.execute();
const matches = allFcs.filter((fc) => fc.friendCode === friendCode);
if (matches.length === 0) {
logger.info("No matches found");
return;
}
for (const match of matches) {
logger.info(
`${match.friendCode} - ${match.discordUniqueName} - ${match.discordId}`,
);
}
}
void main();

59
scripts/recent-fcs.ts Normal file
View File

@ -0,0 +1,59 @@
import "dotenv/config";
import { db } from "~/db/sql";
import { databaseTimestampToDate } from "~/utils/dates";
import { logger } from "~/utils/logger";
async function main() {
const allFcs = await db
.selectFrom("UserFriendCode")
.innerJoin("User", "User.id", "UserFriendCode.userId")
.select(["UserFriendCode.friendCode", "User.id as userId"])
.orderBy("UserFriendCode.createdAt", "asc")
.whereRef("User.id", "=", "UserFriendCode.submitterUserId")
.execute();
const fcMap = new Map<string, number[]>();
for (const fc of allFcs) {
const fcs = fcMap.get(fc.friendCode) ?? [];
fcs.push(fc.userId);
fcMap.set(fc.friendCode, fcs);
}
const friendCodeAdders = await db
.selectFrom("UserFriendCode")
.innerJoin("User", "User.id", "UserFriendCode.userId")
.select([
"UserFriendCode.friendCode",
"UserFriendCode.createdAt",
"User.id",
"User.discordId",
"User.discordUniqueName",
])
.orderBy("UserFriendCode.createdAt", "desc")
.whereRef("User.id", "=", "UserFriendCode.submitterUserId")
.limit(90)
.execute();
let result = "";
let date = "";
for (const [i, friendCodeAdder] of friendCodeAdders.entries()) {
const utc = databaseTimestampToDate(
friendCodeAdder.createdAt,
).toUTCString();
const newDate = utc.split(",")[0];
if (date !== newDate) {
date = newDate;
result += "\n";
}
const isDuplicate =
(fcMap.get(friendCodeAdder.friendCode) ?? [])?.length > 1;
result += `${i < 9 ? "0" : ""}${i + 1}) ${utc} - ${friendCodeAdder.friendCode}${isDuplicate ? " >>DUPLICATE<<" : ""} - ${friendCodeAdder.discordUniqueName} - ${friendCodeAdder.discordId}\n`;
}
logger.info(result);
}
void main();