Autoban on repeated FC + admin FC search Closes #2024
Some checks failed
Tests and checks on push / run-checks-and-tests (push) Has been cancelled
Updates translation progress / update-translation-progress-issue (push) Has been cancelled

This commit is contained in:
Kalle
2025-03-23 19:14:57 +02:00
parent d6f4cf577b
commit 1e905e2941
5 changed files with 166 additions and 6 deletions

View File

@@ -253,6 +253,15 @@ export function findByCustomUrl(customUrl: string) {
.executeTakeFirst();
}
export function findByFriendCode(friendCode: string) {
return db
.selectFrom("UserFriendCode")
.innerJoin("User", "User.id", "UserFriendCode.userId")
.select([...COMMON_USER_FIELDS])
.where("UserFriendCode.friendCode", "=", friendCode)
.execute();
}
export function findBannedStatusByUserId(userId: number) {
return db
.selectFrom("User")
@@ -553,6 +562,36 @@ export async function currentFriendCodeByUserId(userId: number) {
.executeTakeFirst();
}
let cachedFriendCodes: Set<string> | null = null;
export async function allCurrentFriendCodes() {
if (cachedFriendCodes) {
return cachedFriendCodes;
}
const allFriendCodes = await db
.selectFrom("UserFriendCode")
.select(["UserFriendCode.friendCode", "UserFriendCode.userId"])
.orderBy("UserFriendCode.createdAt desc")
.execute();
const seenUserIds = new Set<number>();
const friendCodes = new Set<string>();
for (const row of allFriendCodes) {
if (seenUserIds.has(row.userId)) {
continue;
}
seenUserIds.add(row.userId);
friendCodes.add(row.friendCode);
}
cachedFriendCodes = friendCodes;
return friendCodes;
}
export async function inGameNameByUserId(userId: number) {
return (
await db
@@ -564,6 +603,8 @@ export async function inGameNameByUserId(userId: number) {
}
export function insertFriendCode(args: TablesInsertable["UserFriendCode"]) {
cachedFriendCodes?.add(args.friendCode);
return db.insertInto("UserFriendCode").values(args).execute();
}