@L11K/

CommunityChannels

Nodejs

Community Channels Bot

fork
loading
Files
  • index.js
  • commands
  • images
  • functions.js
  • json.sqlite
  • package-lock.json
index.js
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
// Require Packages
const Discord = require('discord.js'),
    db = require('quick.db'),
    fs = require('fs'),
    client = new Discord.Client(),
    tools = require('./functions.js'),
    prefix = '~',
    moment = require('moment');

const http = require('http');
http.createServer(function (req, res) {
  res.write("Ready");
  res.end();
}).listen(8080);


function timeout(ms) {
    return new Promise(resolve => setTimeout(resolve, ms));
}

client.on('ready', () => {
    let categories = client.guilds.get('305115851814862848').channels.filter(c => c.type === 'category' && c.name === 'Passione');
    categories.forEach(c => {
        c.children.forEach(async channel => {
            let alert = await db.fetch(`merchantsoftAlert_${channel.id}`);
            let sentMessage;
            let message;
            const embed = new Discord.RichEmbed()
                .setColor(0xB51319)
                .setFooter('Patented Merchantsoft Tracking Tools Enabled.\nYou\'re safe knowing that Merchantsoft is watching!')
try {
            if (alert) message = await channel.messages.fetch(alert);
}catch(e){}

            if (!alert || !message) {
                sentMessage = await tools.send(channel, embed, {
                    name: 'Merchantsoft',
                    icon: 'https://i.imgur.com/ms0GSQk.png'
                })
                await db.set(`merchantsoftAlert_${channel.id}`, sentMessage.id);
            }
            if (sentMessage) message = sentMessage;
            await timeout(2000);
        })
    })
    client.on('messageDelete', async message => {
        let alert = await db.fetch(`merchantsoftAlert_${message.channel.id}`);
        if (alert === message.id) {
            const embed = new Discord.RichEmbed()
                .setColor(0xB51319)
                .setFooter('Patented Merchantsoft Tracking Tools Enabled.\nYou\'re safe knowing that Merchantsoft is watching!')
            const embed2 = new Discord.RichEmbed()
                .setColor(0xB51319)
                .setFooter('Removal of  Patented Merchantsoft Tracking Tools is a violation of Hypnospace T&C. Please refrain.')
            await tools.send(message.channel, embed2, {
                name: 'Merchantsoft',
                icon: 'https://i.imgur.com/ms0GSQk.png'
            }).then(m => {
                try{
                m.delete({timeout: 10000})
                }catch(e){}
            })
            let sentMessage = await tools.send(message.channel, embed, {
                name: 'Merchantsoft',
                icon: 'https://i.imgur.com/ms0GSQk.png'
            });
            db.set(`merchantsoftAlert_${message.channel.id}`, sentMessage.id);
        }
    })
})

// Listener Events
client.on('message', async message => {
    return;
    // Variable
    let args = message.content.slice(prefix.length).trim().split(" ");

    // Fetch Guild Settings
    let fetched = await db.fetch(`autoCreate_${message.guild.id}`);

    // Return If Settings Null
    if (fetched === null || !fetched.channelID || !client.channels.get(fetched.channelID)) return;

    // Return Statement
    if (fetched.channelID !== message.channel.id) return;

    // Return Statement
    if (message.content.toLowerCase().trim() !== fetched.msg && fetched.msg !== null) return message.delete({
        timeout: 1000
    });

    let guildChannels = message.guild.channels.array();
    console.log(guildChannels.length)
    for (var i in guildChannels) {
        db.fetch(`channelOwner_${guildChannels[i].id}`).then(channelInfo => {
            if (channelInfo === null) return;
            else if (channelInfo === message.author.id) {
                callback(true);
            } else if (i === guildChannels.length - 1) callback(false);
        })
    }

    function callback(found) {

        if (found) {

            const embed = new Discord.RichEmbed()
                .setFooter(`Sorry, you already have a channel. Please ask an administrator if you would like a second channel.`);

            return tools.send(message.channel, embed, {
                color: true,
                name: 'Channel Found',
                icon: 'https://cdn2.iconfinder.com/data/icons/circle-icons-1/64/bookshelf-128.png'
            });

        } else {

            let commandFile = require(`./commands/create.js`);
            commandFile.run(client, message, args, tools, true);

        }

    }

})

client.on('message', async message => {

    if (!message.guild || message.author.bot) return;

    if (message.channel.id === '521062526465736704' && message.content.toLowerCase() === 'enter') {

        const embed = new Discord.RichEmbed()
            .setFooter(`I'm adding you to the main server, welcome to DJJ Development!`);

        await tools.send(message.channel, embed, {
            name: `Welcome ${message.author.username}`,
            icon: 'https://cdn2.iconfinder.com/data/icons/circle-icons-1/64/arrow-up-128.png',
            color: true,
            delete: 10000
        })

        let giveaways = message.guild.roles.find('name', 'Giveaways');
        let giveawaysOnly = message.guild.roles.find('name', 'Giveaways-Only');

        message.member.roles.remove(giveawaysOnly);
        if (!message.member.roles.has(giveaways)) message.member.roles.add(giveaways);

    }

    // Variables
    let msg = message.content.toUpperCase(),
        raw = msg.toLowerCase(),
        args = message.content.slice(prefix.length).trim().split(" "),
        cmd = args.shift().toLowerCase(),
        completed = true;

    let delList = await db.fetch(`autoDelete_${message.guild.id}`);
    try {
        if (delList !== null && delList.includes(message.channel.id) && !message.author.bot) message.delete({
            timeout: 1000
        })
    } catch (e) {
        console.log(e)
    }

    let keywords = ['enlarge', 'traffic', 'data', 'money', 'purchase', 'satisfied', 'apply', 'celebrity', 'claim', 'credit', '$', 'offshore', 'valium', 'viagra', 'warranty', 'xanax', 'drugs'],
        found = false;

    for (var i in keywords) {
        if (message.guild.id !== '305115851814862848' || message.author.bot);
        else if (raw.includes(keywords[i]) && !found) {
            found = true;
            tools.sendAd(message.channel, true);
        }
    }

    if (message.guild.id === '305115851814862848' && message.channel.id !== '521063487175393300' && msg.includes('HELP') && cmd !== 'help') {
        console.log('Ran Help')
        let commandFile = require(`./commands/professor-helper.js`);
        commandFile.run(client, message, args, tools);

    }

    // Return Statement
    if (!msg.startsWith(prefix) || message.author.bot) return;

    // Aliases
    let aliases = { // cmd: target
        'channeldescription': 'channeldesc',
        'mods': 'moderators',
        'mod': 'addmod',
        'delmod': 'removemod',
        'help': 'channel',
        'commands': 'channel',
        'cmdlist': 'channel',
        'setname': 'channelname',
        'setdesc': 'channeldesc',
        'statistics': 'stats',
        'delete': 'purge',
        'clear': 'purge',
        'inviteurl': 'invitelink'
    }

    // Set Alias
    if (aliases[cmd] !== undefined) cmd = aliases[cmd];

    // Command Handler
    try { // Initialize

        if (false && message.channel.id === '521063487175393300' && !['join', 'leave'].includes(cmd));
        else {
            if (cmd === 'canvas-test') delete require.cache[require.resolve(`./commands/${cmd}.js`)];
            let commandFile = require(`./commands/${cmd}.js`);
            commandFile.run(client, message, args, tools);
        }
    } catch (e) { // Catch Errors

        console.log(e.stack)
        completed = false;

    } finally { // Run Last

        // Log Commands
        if (completed) {
            //console.log(`[${message.guild.name}] ${message.author.tag} ran the command: ${message.content}`);
            db.add(`commands`, 1, {
                target: 'total'
            });
            db.add(`commands`, 1, {
                target: `${cmd}`
            })
        } else console.log(`[${message.guild.name}] ${message.author.tag} attempted to run the command: ${message.content}`);

    }

});

client.on('guildCreate', guild => {

    let memberCount = 0;
    client.guilds.map(g => memberCount += g.memberCount)

    const embed = new Discord.RichEmbed()
        .setTitle(guild.name)
        .setFooter(`+${guild.memberCount} members (${memberCount} total) | +1 guild (${client.guilds.size} total) | +${guild.channels.size} channels (${client.channels.size} total)`)

    tools.send(client.channels.get('410150933549547540'), embed, {
        color: true,
        icon: 'https://cdn2.iconfinder.com/data/icons/circle-icons-1/64/arrow-up-128.png',
        name: 'Guild Joined'
    })

})

client.on('guildDelete', guild => {

    let memberCount = 0;
    client.guilds.map(g => memberCount += g.memberCount)


    const embed = new Discord.RichEmbed()
        .setTitle(guild.name)
        .setFooter(`-${guild.memberCount} members (${memberCount} total) | -1 guild (${client.guilds.size} total) | ${client.channels.size} channels remaining`)

    tools.send(client.channels.get('410150933549547540'), embed, {
        color: true,
        icon: 'https://cdn2.iconfinder.com/data/icons/circle-icons-1/64/bomb-128.png',
        name: 'Guild Left'
    })

})

client.on('guildMemberAdd', async member => {

    // Fetch Cached Invites
    let cached = await db.fetch(`invites_${member.guild.id}`);
    if (cached === null) return;

    // Fetch Active invites
    let active = await member.guild.fetchInvites();
    active.array();

    // Compare
    let updated = {};
    active.forEach(async function(invite) {
        if (invite.inviter.id !== '386059740805070848' || !cached[invite.channel.id]) return;
        if (cached[invite.channel.id].uses < invite.uses) {
            tools.addUserToChannel(member.user, invite.channel);
            const embed = new Discord.RichEmbed()
                .setFooter(`${member.user.tag} has joined through the invite URL ${invite.url}`)

            if (invite.url === 'Invite') {

                member.roles.add(member.guild.roles.find('name', 'Member'));
                let memberCount = client.channels.get('449045892327145502').members.size.toString();

                embed.setFooter(`Welcome to Plexi Development ${member.user.tag}, you are the ${memberCount}th member!`);

                tools.send(invite.channel, embed, {
                    color: true,
                    name: 'User Joined',
                    icon: 'https://cdn2.iconfinder.com/data/icons/circle-icons-1/64/arrow-up-128.png'
                })

            } else if (invite.url === 'Invite') {

                member.roles.add(member.guild.roles.find('name', 'Giveaways Only'));
                let memberCount = client.channels.get('457298323548930048').members.size.toString();

                let suffix = 'th'
                if (memberCount.toString().endsWith('1')) suffix = 'st'
                else if (memberCount.toString().endsWith('2')) suffix = 'nd'
                else if (memberCount.toString().endsWith('3')) suffix = 'rd'

                embed.setFooter(`Welcome to Plexi Development Giveaways ${member.user.tag}, you are the ${memberCount}${suffix} member!`);

                tools.send(client.channels.get('457300187107295242'), embed, {
                    color: true,
                    name: 'User Joined',
                    icon: 'https://cdn2.iconfinder.com/data/icons/circle-icons-1/64/arrow-up-128.png'
                })

            } else {
                tools.send(invite.channel, embed, {
                    color: true,
                    name: 'User Joined',
                    icon: 'https://cdn2.iconfinder.com/data/icons/circle-icons-1/64/mail-128.png'
                })
            }
        }
        db.set(`invites_${member.guild.id}`, invite.uses, {
            target: `.${invite.channel.id}.uses`
        })
    })

})


client.on('ready', () => {
    //client.user.setActivity(`Something`);
      console.log("I'm in!");
      console.log(client.user.username);
    function updateClock() {
        let channel = client.channels.get('521063487175393300');
        let local = `Time in the Organization: ${moment().format('LLLL')}`
        channel.setTopic(local);

    }

    function repeatEvery(func, interval) {
        // Check current time and calculate the delay until next interval
        var now = new Date(),
            delay = interval - now % interval;

        function start() {
            // Execute function now...
            func();
            // ... and every interval
            setInterval(func, interval);
        }

        // Delay execution until it's an even interval
        setTimeout(start, delay);
    }

    repeatEvery(updateClock, 60000);
})
// Login
client.login(process.env.TOKEN);
node v10.16.0