mirror of
https://github.com/Sendouc/sendou.ink.git
synced 2026-03-22 02:14:41 -05:00
FC scripts
This commit is contained in:
parent
4aa9c50413
commit
5c9ebfd2f0
38
scripts/fc-lookup.ts
Normal file
38
scripts/fc-lookup.ts
Normal 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
59
scripts/recent-fcs.ts
Normal 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();
|
||||
Loading…
Reference in New Issue
Block a user