{"version":3,"file":"guards.luau","names":[],"sources":["..\\..\\src\\centurion\\guards.ts"],"sourcesContent":["import { includes } from \"@lisachandra/core/utils/string\";\nimport type { CommandContext } from \"@rbxts/centurion\";\n\nlet groupId = 0;\nconst allowedUserIds = new Array<number>();\nconst allowedRoles = [\"Developer\", \"Founder\"];\n\n/**\n * Configures the Roblox group ID used for centurion command authorization.\n *\n * @param id - The Roblox group ID to check roles against.\n */\nexport function configureCenturionGroup(id: number): void {\n\tgroupId = id;\n}\n\n/**\n * Configures which group roles are authorized to run admin commands. Default: `[\"Developer\",\n * \"Founder\"]`.\n */\nexport function configureCenturionRoles(roles: Array<string>): void {\n\tallowedRoles.clear();\n\tfor (const role of roles) {\n\t\tallowedRoles.push(role);\n\t}\n}\n\n/**\n * Configures which Roblox user IDs are authorized to run admin commands.\n *\n * @param userIds - The Roblox user IDs that should bypass group-role checks.\n */\nexport function configureCenturionUsers(userIds: Array<number>): void {\n\tallowedUserIds.clear();\n\tfor (const userId of userIds) {\n\t\tallowedUserIds.push(userId);\n\t}\n}\n\n/**\n * Centurion guard that checks whether the command executor is explicitly allowed by user ID or\n * belongs to the configured group with an authorized role.\n *\n * @param context - The command context, providing the executor and error reporting.\n * @returns `true` if the executor has an allowed user ID or role; otherwise `false` and an error is\n *   reported to the context.\n */\nexport function adminOrDeveloper(context: CommandContext): boolean {\n\tfor (const allowedUserId of allowedUserIds) {\n\t\tif (context.executor.UserId === allowedUserId) {\n\t\t\treturn true;\n\t\t}\n\t}\n\n\tconst role = context.executor.GetRoleInGroup(groupId);\n\tfor (const allowed of allowedRoles) {\n\t\tif (includes(role, allowed)) {\n\t\t\treturn true;\n\t\t}\n\t}\n\n\tcontext.error(`Insufficient permissions for ${context.executor.Name} (${context.getData()})`);\n\treturn false;\n}\n"],"mappings":";;AAAA;AAGA;AACA;AACA;;;;;;;;AAOA;AACC;AACD;;;;;;;AAMA;AACC;AACA;AACC;AACD;AACD;;;;;;;;AAOA;AACC;AACA;AACC;AACD;AACD;;;;;;;;;;;AAUA;AACC;AACC;AACC;AACD;AACD;AAEA;AACA;AACC;AACC;AACD;AACD;AAEA;AACA;AACD","ignoreList":[]}