File size: 2,263 Bytes
3c7e34b
 
 
 
 
 
 
 
 
5fb7488
3c7e34b
 
5fb7488
3c7e34b
 
 
 
 
 
 
 
 
 
 
 
5fb7488
3c7e34b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
const { stmts } = require('../database');
const { logEmbed } = require('../utils/embeds');
const { Colors } = require('../config');

/**
 * Log an action to the staff-logs channel.
 */
async function log(client, { title, description, fields = [], color = Colors.MUTED }) {
    try {
        const row = await stmts.getState('channel_staff-logs');
        if (!row) return;

        const channelId = row;
        const channel = await client.channels.fetch(channelId).catch(() => null);
        if (!channel) return;

        const embed = logEmbed({ title, description, color, fields });
        await channel.send({ embeds: [embed] });
    } catch (err) {
        console.error('[Logger] Failed to log:', err.message);
    }
}

// Convenience wrappers
async function logVerification(client, user, action) {
    await stmts.logVerification(user.id, user.tag, action);
    await log(client, {
        title: 'πŸ” Verification',
        description: `**${user.tag}** (${user.id})`,
        fields: [{ name: 'Action', value: action, inline: true }],
        color: action === 'verified' ? Colors.SUCCESS : Colors.WARNING,
    });
}

async function logTicket(client, { user, action, channelName }) {
    await log(client, {
        title: '🎫 Ticket',
        description: `**${user.tag}** (${user.id})`,
        fields: [
            { name: 'Action', value: action, inline: true },
            { name: 'Channel', value: channelName || 'N/A', inline: true },
        ],
        color: Colors.INFO,
    });
}

async function logCommand(client, command) {
    await log(client, {
        title: 'βš™οΈ Command Executed',
        description: `\`${command}\``,
        fields: [{ name: 'Executed by', value: 'Owner (DM)', inline: true }],
        color: Colors.PRIMARY,
    });
}

async function logRoleChange(client, { user, role, action }) {
    await log(client, {
        title: 'πŸ‘€ Role Change',
        description: `**${user.tag}** (${user.id})`,
        fields: [
            { name: 'Role', value: role, inline: true },
            { name: 'Action', value: action, inline: true },
        ],
        color: action === 'added' ? Colors.SUCCESS : Colors.WARNING,
    });
}

module.exports = { log, logVerification, logTicket, logCommand, logRoleChange };