File size: 7,192 Bytes
0740360
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
const { PermissionFlagsBits, ChannelType } = require('discord.js');
const { stmts } = require('../database');
const { successEmbed, errorEmbed } = require('../utils/embeds');
const { Colors, Roles } = require('../config');

module.exports = {
    async execute(client, message) {
        const guild = await client.guilds.fetch(process.env.GUILD_ID);
        await guild.roles.fetch();
        await guild.channels.fetch();

        const log = [];

        // ── 1. Create missing roles ──────────────────────────────
        const newRoles = ['@@ Server Manager', '@@ Moderator'];
        for (const roleName of newRoles) {
            const existing = guild.roles.cache.find(r => r.name === roleName);
            if (existing) {
                log.push(`⏭️ Role **${roleName}** already exists`);
                continue;
            }
            const def = Roles.find(r => r.name === roleName);
            if (!def) continue;

            // Find position: place below Co-Owner, above Staff
            const staffRole = guild.roles.cache.find(r => r.name === '@@ Staff');
            const pos = staffRole ? staffRole.position + 1 : 1;

            await guild.roles.create({
                name: def.name,
                color: def.color,
                permissions: def.permissions,
                hoist: def.hoist,
                mentionable: def.mentionable,
                position: pos,
            });
            log.push(`βœ… Created role **${roleName}**`);
        }

        // ── 2. Create owner-chat in STAFF ONLY category ──────────
        const staffCategory = guild.channels.cache.find(
            c => c.type === ChannelType.GuildCategory && c.name.includes('STAFF ONLY')
        );
        const ownerChatExists = guild.channels.cache.find(c => c.name === 'πŸ‘‘γƒ»owner-chat');

        if (ownerChatExists) {
            log.push(`⏭️ Channel **πŸ‘‘γƒ»owner-chat** already exists`);
        } else if (!staffCategory) {
            log.push(`⚠️ STAFF ONLY category not found β€” skipped owner-chat`);
        } else {
            // Fetch roles for permissions
            const everyoneRole = guild.roles.everyone;
            const ownerRole = guild.roles.cache.find(r => r.name === '@@ Owner');
            const coOwnerRole = guild.roles.cache.find(r => r.name === '@@ Co-Owner');
            const svrMgrRole = guild.roles.cache.find(r => r.name === '@@ Server Manager');

            const overwrites = [
                { id: everyoneRole.id, deny: [PermissionFlagsBits.ViewChannel] },
            ];
            if (ownerRole) overwrites.push({ id: ownerRole.id, allow: [PermissionFlagsBits.ViewChannel, PermissionFlagsBits.SendMessages] });
            if (coOwnerRole) overwrites.push({ id: coOwnerRole.id, allow: [PermissionFlagsBits.ViewChannel, PermissionFlagsBits.SendMessages] });
            if (svrMgrRole) overwrites.push({ id: svrMgrRole.id, allow: [PermissionFlagsBits.ViewChannel, PermissionFlagsBits.SendMessages] });

            // Get staff-chat to position owner-chat above it
            const staffChat = guild.channels.cache.find(c => c.name === 'πŸ›‘οΈγƒ»staff-chat');

            const ownerChat = await guild.channels.create({
                name: 'πŸ‘‘γƒ»owner-chat',
                type: ChannelType.GuildText,
                parent: staffCategory.id,
                permissionOverwrites: overwrites,
            });

            // Move above staff-chat
            if (staffChat) {
                await ownerChat.setPosition(staffChat.position);
            }

            stmts.setState.run('channel_πŸ‘‘γƒ»owner-chat', ownerChat.id);
            log.push(`βœ… Created **πŸ‘‘γƒ»owner-chat** (above staff-chat)`);
        }

        // ── 3. Lock Resources channels to owner-only send ────────
        const resourceChannels = ['πŸŒγƒ»resources', 'πŸŒγƒ»free-assets', 'πŸŒγƒ»scripts', 'πŸŒγƒ»drivers'];
        const everyoneRole = guild.roles.everyone;
        const ownerRole = guild.roles.cache.find(r => r.name === '@@ Owner');
        const verifiedRole = guild.roles.cache.find(r => r.name === '@@ Verified');
        const staffRole = guild.roles.cache.find(r => r.name === '@@ Staff');
        const boosterRole = guild.roles.cache.find(r => r.name === '@@ Booster');

        for (const chName of resourceChannels) {
            const ch = guild.channels.cache.find(c => c.name === chName);
            if (!ch) {
                log.push(`⚠️ Channel **${chName}** not found β€” skipped`);
                continue;
            }

            const overwrites = [
                { id: everyoneRole.id, deny: [PermissionFlagsBits.ViewChannel, PermissionFlagsBits.SendMessages] },
            ];
            if (verifiedRole) overwrites.push({ id: verifiedRole.id, allow: [PermissionFlagsBits.ViewChannel], deny: [PermissionFlagsBits.SendMessages, PermissionFlagsBits.AttachFiles] });
            if (boosterRole) overwrites.push({ id: boosterRole.id, allow: [PermissionFlagsBits.ViewChannel], deny: [PermissionFlagsBits.SendMessages, PermissionFlagsBits.AttachFiles] });
            if (staffRole) overwrites.push({ id: staffRole.id, allow: [PermissionFlagsBits.ViewChannel], deny: [PermissionFlagsBits.SendMessages, PermissionFlagsBits.AttachFiles] });
            if (ownerRole) overwrites.push({ id: ownerRole.id, allow: [PermissionFlagsBits.ViewChannel, PermissionFlagsBits.SendMessages, PermissionFlagsBits.AttachFiles] });

            await ch.permissionOverwrites.set(overwrites);
            log.push(`πŸ”’ Locked **${chName}** β€” owner-only send`);
        }

        // ── 4. Lock booster-rewards to owner-only send ───────────
        const boosterRewards = guild.channels.cache.find(c => c.name === 'πŸ’Žγƒ»booster-rewards');
        if (boosterRewards) {
            const overwrites = [
                { id: everyoneRole.id, deny: [PermissionFlagsBits.ViewChannel, PermissionFlagsBits.SendMessages] },
            ];
            if (boosterRole) overwrites.push({ id: boosterRole.id, allow: [PermissionFlagsBits.ViewChannel], deny: [PermissionFlagsBits.SendMessages, PermissionFlagsBits.AttachFiles] });
            if (staffRole) overwrites.push({ id: staffRole.id, allow: [PermissionFlagsBits.ViewChannel], deny: [PermissionFlagsBits.SendMessages, PermissionFlagsBits.AttachFiles] });
            if (ownerRole) overwrites.push({ id: ownerRole.id, allow: [PermissionFlagsBits.ViewChannel, PermissionFlagsBits.SendMessages, PermissionFlagsBits.AttachFiles] });

            await boosterRewards.permissionOverwrites.set(overwrites);
            log.push(`πŸ”’ Locked **πŸ’Žγƒ»booster-rewards** β€” owner-only send`);
        } else {
            log.push(`⚠️ Channel **πŸ’Žγƒ»booster-rewards** not found β€” skipped`);
        }

        // ── Done ─────────────────────────────────────────────────
        await message.reply({
            embeds: [successEmbed('βœ… Updates Applied', log.join('\n'))],
        });
    },
};