Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
car-crushers-portal/functions/api/game-appeals/precheck.ts
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
77 lines (64 sloc)
1.77 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { getBanList } from "../../roblox-open-cloud.js"; | |
export default async function ( | |
context: RequestContext, | |
user: number, | |
): Promise<{ can_appeal?: boolean; error?: string; reason?: string }> { | |
if ( | |
await context.env.D1.prepare( | |
"SELECT * FROM game_appeals WHERE open = 1 AND user = ?;", | |
) | |
.bind(user) | |
.first() | |
) | |
return { | |
can_appeal: false, | |
reason: "You have already submitted an appeal", | |
}; | |
let banList; | |
try { | |
banList = (await getBanList(context)) as { | |
[k: number]: { BanType: number }; | |
}; | |
} catch { | |
return { | |
error: "Failed to check your ban status", | |
}; | |
} | |
if (!banList[user]?.BanType) | |
return { | |
can_appeal: false, | |
reason: "You do not appear to be banned", | |
}; | |
const appealBlock = await context.env.DATA.get(`gameappealblock_${user}`); | |
if (appealBlock) | |
return { | |
can_appeal: false, | |
reason: `You must wait until ${new Date( | |
parseInt(appealBlock), | |
).toLocaleString()} to submit another appeal`, | |
}; | |
let userLogs; | |
try { | |
userLogs = await context.env.D1.prepare( | |
"SELECT executed_at FROM game_mod_logs WHERE target = ? ORDER BY executed_at DESC;", | |
) | |
.bind(user) | |
.all(); | |
if (userLogs.error) throw new Error("Query failed"); | |
} catch { | |
return { | |
error: "Could not determine your eligibility", | |
}; | |
} | |
// Legacy bans | |
if (!userLogs.results.length) return { can_appeal: true, reason: "" }; | |
const allowedTime = (userLogs.results[0].executed_at as number) + 2592000000; | |
if (Date.now() < allowedTime) | |
return { | |
can_appeal: false, | |
reason: `You must wait until ${new Date( | |
allowedTime, | |
).toLocaleString()} to submit an appeal`, | |
}; | |
return { can_appeal: true, reason: "" }; | |
} |