nuno revisó este gist 3 weeks ago. Ir a la revisión
1 file changed, 44 insertions
gistfile1.txt(archivo creado)
| @@ -0,0 +1,44 @@ | |||
| 1 | + | import fs from "fs"; | |
| 2 | + | import path from "path"; | |
| 3 | + | ||
| 4 | + | const IMPERSONATE_RESET_ON_POLL = process.env.IMPERSONATE_RESET_ON_POLL !== "false"; | |
| 5 | + | const IMPERSONATE_INDICATOR = process.env.IMPERSONATE_INDICATOR !== "false"; | |
| 6 | + | ||
| 7 | + | // realDiscordId → userKey being impersonated | |
| 8 | + | const impersonations = new Map<string, string>(); | |
| 9 | + | ||
| 10 | + | export function setImpersonation(realDiscordId: string, userKey: string): void { | |
| 11 | + | impersonations.set(realDiscordId, userKey); | |
| 12 | + | } | |
| 13 | + | ||
| 14 | + | export function clearImpersonation(realDiscordId: string): void { | |
| 15 | + | impersonations.delete(realDiscordId); | |
| 16 | + | } | |
| 17 | + | ||
| 18 | + | export function getImpersonation(realDiscordId: string): string | null { | |
| 19 | + | return impersonations.get(realDiscordId) ?? null; | |
| 20 | + | } | |
| 21 | + | ||
| 22 | + | export function clearAllImpersonations(): void { | |
| 23 | + | if (IMPERSONATE_RESET_ON_POLL) impersonations.clear(); | |
| 24 | + | } | |
| 25 | + | ||
| 26 | + | export function shouldShowIndicator(): boolean { | |
| 27 | + | return IMPERSONATE_INDICATOR; | |
| 28 | + | } | |
| 29 | + | ||
| 30 | + | // Returns all registered userKeys from usermap.json | |
| 31 | + | export function getRegisteredUsers(): { userKey: string; aliases: string[] }[] { | |
| 32 | + | try { | |
| 33 | + | const usermap = JSON.parse( | |
| 34 | + | fs.readFileSync(path.join(__dirname, "../../data/usermap.json"), "utf8") | |
| 35 | + | ); | |
| 36 | + | return Object.entries(usermap).map(([, entry]: [string, any]) => { | |
| 37 | + | const fileKey = typeof entry === "string" ? entry : entry.file; | |
| 38 | + | const aliases = typeof entry === "object" ? (entry.aliases ?? []) : []; | |
| 39 | + | return { userKey: fileKey, aliases }; | |
| 40 | + | }); | |
| 41 | + | } catch { | |
| 42 | + | return []; | |
| 43 | + | } | |
| 44 | + | } | |
Siguiente
Anterior