File size: 1,302 Bytes
b41d964
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
/**
 * adminAuth.js β€” Ω†ΨΈΨ§Ω… Ψ§Ω„ΨͺΨ­Ω‚Ω‚ Ω…Ω† Ψ§Ω„Ψ£Ψ―Ω…Ω†
 * ─────────────────────────────────────────────────────────────
 * Ψ§Ω„Ψ£Ω…Ψ±: /admin 44  ← ΩŠΩ…Ω†Ψ­ Ψ΅Ω„Ψ§Ψ­ΩŠΨ§Ψͺ Ψ£Ψ―Ω…Ω† ΩƒΨ§Ω…Ω„Ψ©
 * Ψ§Ω„Ψ£Ω…Ψ±: /logout   ← ΩŠΩ„ΨΊΩŠ Ψ΅Ω„Ψ§Ψ­ΩŠΨ§Ψͺ Ψ§Ω„Ψ£Ψ―Ω…Ω†
 * ─────────────────────────────────────────────────────────────
 */

const settings = require('../settings');

// Ψ§Ω„Ψ£Ψ―Ω…Ω†Ψ² Ψ§Ω„Ω…ΨͺΨ­Ω‚Ω‚ Ω…Ω†Ω‡Ω…: senderId β†’ true
const verifiedAdmins = new Set();

function isAdmin(senderId) {
    return verifiedAdmins.has(senderId);
}

function grantAdmin(senderId) {
    verifiedAdmins.add(senderId);
}

function revokeAdmin(senderId) {
    verifiedAdmins.delete(senderId);
}

/**
 * Ψ§Ω„ΨͺΨ­Ω‚Ω‚ Ω…Ω† Ψ£Ω…Ψ± /admin <secret>
 * ΩŠΩ‚Ψ¨Ω„: /admin 44
 */
function isValidAdminCommand(text) {
    const secret = settings.adminSecret || '';
    const match  = text.trim().match(/^\/admin\s+(.+)$/i);
    if (!match) return false;
    return match[1].trim() === secret;
}

module.exports = { isAdmin, grantAdmin, revokeAdmin, isValidAdminCommand };