38443-vm/includes/permissions.php
Flatlogic Bot 4883125cda v2
2026-02-15 10:30:17 +00:00

26 lines
761 B
PHP

<?php
class Permissions {
const VIEW_CHANNEL = 1;
const SEND_MESSAGES = 2;
const MANAGE_MESSAGES = 4;
const MANAGE_CHANNELS = 8;
const MANAGE_SERVER = 16;
const ADMINISTRATOR = 32;
public static function hasPermission($user_id, $server_id, $permission) {
$stmt = db()->prepare("
SELECT SUM(r.permissions) as total_perms
FROM roles r
JOIN user_roles ur ON r.id = ur.role_id
WHERE ur.user_id = ? AND r.server_id = ?
");
$stmt->execute([$user_id, $server_id]);
$row = $stmt->fetch();
$perms = (int)($row['total_perms'] ?? 0);
if ($perms & self::ADMINISTRATOR) return true;
return ($perms & $permission) === $permission;
}
}