Nodejs

No description

fork
loading
Files
  • index.js
  • commands
  • data
  • Events
  • guilds
  • logger
  • pages
  • server
  • additionalSourcesPack.js
  • anticuss.json
  • botInfo.js
  • JSC.js
  • Jsonfile.json
  • package-lock.json
  • package.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
const JSC = require(`./JSC.js`);

const Discord = require("discord.js");
const client = JSC.IMPORT.CONSTANTS.client;

const fs = require("fs");

const config = require("./Jsonfile.json");
const logger = require(`./logger/logger.js`);

const STDIN = require(`/home/runner/Events/stdin.js`);
const EXPRESS = require(`/home/runner/Events/Express.js`);

const functions = JSC.IMPORT.FUNCTIONS;
const version = JSC.IMPORT.CONSTANTS.VERSION;
const posOut = [`on`, `yes`, `true`, `1`, `y`, `t`];
const negOut = [`off`, `no`, `false`, `0`, `n`, `f`];


const Enmap = require("enmap");
const bettersqlitepool = require("better-sqlite-pool");

client.settings = new Enmap({
  name: "settings",
  fetchAll: false,
  autoFetch: true,
  cloneLevel: "deep"
});

client.gameSettings = new Enmap({
  name: "gameSettings",
  fetchAll: false,
  autoFetch: true,
  cloneLevel: "deep"
});


const CON = JSC.IMPORT.CONSTANTS;

const FUNC = JSC.IMPORT.FUNCTIONS;

client.commandInfo = new Discord.Collection();

client.extcommands = new Discord.Collection();

BotCommands = [];


fs.readdir(`./commands`, (err, file) => {
  if (err) console.log(err);
  
  let jsfile = file.filter(f => f.split(`.`).pop() === `js`);
  let folder = [];
  
  jsfile.forEach(f => {
    let props = require(`/home/runner/commands/${f}`);
    
    client.commandInfo.set(props.help.name, props.help);
    
    console.log(`/home/runner/commands/${f}\n`);
    
    client.extcommands.set(props.help.name, props);
  });
  
  file.forEach(f => {
    if (f.split(`.`).pop() !== `js`) {
      folder.push(f);
    }
  });
  
  folder.forEach(i => {
    fs.readdir(`/home/runner/commands/${i}`, (err, file) => {
      if (err) console.log(err);
      
      client[`${i}commands`] = new Discord.Collection();
      BotCommands.push(client[`${i}commands`]);
      
      let jsfile = file.filter(f => f.split(`.`).pop() === `js`);
      
      jsfile.forEach((f,e) => {
        let props = require(`/home/runner/commands/${i}/${f}`);
        
        client.commandInfo.set(props.help.name, props.help);
        
        console.log(`/home/runner/commands/${i}/${f}\n`);

        client[`${i}commands`].set(props.help.name, props);
      });
    });
  });
});


client.on(`ready`, () => {
  client.guilds.forEach(guild => {
    logger.makeLog(`./guilds/`, `${guild.name.replace(/[\ \`[email protected]#$%^&*\(\)-=+\\|\]\}\[\{’”;:/?.><,\'\"]/g, '_')}__${guild.id.replace(/[[email protected]<>]/g)}__.js`);
  });
  
  function readyMessage(BOTNAME, DATELENGTH, LINE1STRING, LINE2STRING, LINE3STRING) {
    
    line1len = (DATELENGTH - (String(BOTNAME + ` | Online`).length)) / 2;
    line2len = DATELENGTH;
    line3len = (DATELENGTH - String(`Members: ` + client.users.size + ` | Guilds: ` + client.guilds.size).length) / 2;
    
    array1 = [];
    array2 = [];
    array3 = [];
    
    while (line1len > 0) {
      array1.push(LINE1STRING);
      line1len = line1len - 1;
    }
    
    while (line2len > 0) {
      array2.push(LINE2STRING);
      line2len = line2len - 1;
    }
    
    while (line3len > 0) {
      array3.push(LINE3STRING);
      line3len = line3len - 1;
    }
    
    return console.log(array1.join(``) + `${client.user.username} | Online\n` + array2.join(``) + `\nDate: ${CON.activationDate}\n` + array3.join(``) + `Members: ${client.users.size} | Guilds: ${client.guilds.size}`);
  }
  
  datelength = String(`Date: ` + CON.activationDate).length;
  console.log(`\n`);
  readyMessage(client.user.username, datelength, ` `, `=`, ` `);
  
  client.user.setPresence({game: {
    name: `type __help for help | v${version}`,
    type: `Playing`,
    status: `online`
  }});
  
  console.log(`\n\n-—-—-—-—-—-—-—-—-—-—-\n\n`);
  console.log(client.commandInfo);
  console.log(`\n\n-—-—-—-—-—-—-—-—-—-—-\n\n\n`);
  client.commandInfo.forEach(command => {
    console.log(`${command.name} => ${command.permissionLevel}\n`);
  });
  console.log(`\n\n-—-—-—-—-—-—-—-—-—-—-\n\n\n`);
  client.commandInfo.forEach(command => {
    console.log(`${command.name} => ${command.syntax}\n`);
  });
  console.log(`\n\n-—-—-—-—-—-—-—-—-—-—-\n\n\n`);
  client.commandInfo.forEach(command => {
    console.log(`${command.name} => ${command.desc}\n`);
  });
  console.log(`\n\n-—-—-—-—-—-—-—-—-—-—-\n\n`);
  
  
});

client.on(`guildCreate`, guild => {
  client.users.find(`username`, `Silveradoz`).send(`Joined ${guild.name} at ${new Date()}`);
  client.users.find(`username`, `Silveradoz`).send(guild);
  logger.makeLog(`./guilds/`, `${guild.name.replace(/[\ \`[email protected]#$%^&*\(\)-=+\\|\]\}\[\{’”;:/?.><,\'\"]/g, '_')}__${guild.id.replace(/[[email protected]<>]/g)}__.js`);
});

client.on(`guildDelete`, guild => {
  client.settings.delete(guild.id);
});

client.on(`guildMemberAdd`, member => {
  const guildConf = client.settings.ensure(member.guild.id, CON.defaultSettings);
  
  const welcomemessage = client.settings.get(member.guild.id, "welcomeMessage");
  const welcomeMessage = welcomemessage.replace(`{user}`, member.user.tag).replace(`{guild}`, member.guild.name);
  member.guild.channel(guildConf.welcomeChannel).send(welcomeMessage);
  
  member.guild.channels
    .find("name", client.settings.get(member.guild.id, "welcomeChannel"))
    .send(welcomeMessage)
    .catch(console.error);
  
  logWelcomeMsg = logwelcomemessage
    .replace(`{user}`, member.user.username)
    .replace(`{userID}`, member.user.id)
    .replace(`{userMention}`, member.user.tag)
    .replace(`{userDiscriminator}`, `#${member.user.discriminator}`)
    .replace(`{userAccountCreationDate}`, member.user.createdAt)
    .replace(`{userPresence}`, member.presence)
    .replace(`{date}`, new Date())
    .replace(`{guild}`, member.guild.name)
    .replace(`{guildID}`, member.guild.id)
    .replace(`{members}`, member.guild.members.size);
  
  member.guild.channels
    .find("name", client.settings.get(member.guild.id, "logChannel"))
    .send(logWelcomeMsg)
    .catch(console.error);
  
});

client.on(`message`, message => {
  CON.lastMsgChannel = message.channel;
  CON.lastMsg = message;
  if (message.guild) {
    if (CON.MSGs) console.log(`[${message.guild.name}][${message.channel.name}][${message.author.username}]: ${message.content}`);
  } else {
    if (CON.MSGs) console.log(`[null][null][${message.author.username}]: ${message.content}`);
  }
  
  if (!message.guild) return;
  
  //required constants
  const guildConf = client.settings.ensure(message.guild.id, CON.defaultSettings);
  const guildGames = client.gameSettings.ensure(message.guild.id, CON.defaultGameSettings);
  //
  
  if (CON.showDiagnoseNums) console.log(`1gen`);
  
  // Logging
  logger.appendLog(`/home/runner/guilds/${message.guild.name.replace(/[\`[email protected]#$%^&*\(\)-=+\\|\]\}\[\{’”;:/?.><,\'\"]/g, '_')}__${message.guild.id.replace(/[[email protected]<>]/g)}__.js`, `[${new Date()}]| {${message.channel.name}, ID: [${message.channel.id}]} (${message.author.username}, ID: [${message.author.id}]): ${message.content}`);
  //
  
  //anticuss
  if (posOut.includes(guildConf.anticuss)) {
    newcontent = message.content
      .replace(/[1!()|]/g, `i`)
      .replace(/[@4]/g, `a`)
      .replace(/[#]/g, `h`)
      .replace(/[$5]/g, `s`)
      .replace(/[%^&*()_+\-=\][|}{\\’”;:\/?.>,<]/g, ``);
    if (CON.showDiagnoseNums) console.log(`1AC`);
    if (guildConf.anticussLevel === `1`) {
      if (CON.showDiagnoseNums) console.log(`2ACa`);
      msgContent = newcontent.toLowerCase().split(/\ +/g);
      if (CON.swearWords.some(word => msgContent.some(msgWord => msgWord === word))) {
        message.delete();
        return message.reply(`that language is not allowed here.`).then(sentmessage => {sentmessage.delete(7500)});
      }
    }
    if (guildConf.anticussLevel === `2`) {
      if (CON.showDiagnoseNums) console.log(`2ACb`);
      if (CON.swearWords.some(word => newcontent.toLowerCase().includes(word))) {
        message.delete();
        if (newcontent.toLowerCase().includes(`hub`)) return message.reply(`due to a great majority of websites relating to that word, it has been banned... I hope you can understand.`).then(sentMessage => {sentMessage.delete(10000)});
        message.reply(`That language isn‘t allowed here.`).then(sentMessage => {
	        sentMessage.delete(5000);
	      });
      }
    }
    if (guildConf.anticussLevel === `3`) {
      if (CON.showDiagnoseNums) console.log(`2ACc`);
      if (CON.swearWords.some(word => newcontent.toLowerCase().replace(/[\`[email protected]#$%^&*()_+\-=\\[\]{};’:”,.<>/?"']/g, ``).split(` `).join(``).includes(word))) {
        message.delete();
        return message.reply(`Be aware of foul language!`).then(sentMessage => {
	        sentMessage.delete(5000);
	      });
      }
      
      if (CON.swearWords.some(word => message.content.toLowerCase().replace(/[\`[email protected]#$%^&*()_+\-=\\[\]{};’:”,.<>/?"']/g, ``).split(` `).join(``).includes(word))) {
        message.delete();
        return message.reply(`Be aware of foul language!`).then(sentMessage => {
	        sentMessage.delete(5000);
	      });
      }
    }
  }
  //
  
  //automatic nickname
  me = message.guild.members.get(client.user.id);
  me.setNickname(`${client.user.username} [${guildConf.prefix}]`);
  //
  
  //Command setup
  const args = message.content.split(/\ +/g);
  const command = args.shift().slice(guildConf.prefix.length).toLowerCase();
  if (CON.ARGS) console.log(`Command: ‘${command}’\nARGS: [‘${args}’]`);
  //
  
  
  if (CON.showDiagnoseNums) console.log(`2gen`);
  
  
  //Bot checker
  if(!message.guild || message.author.bot) return;
  //
  
  //command groups
  const funcommandfile = client.funcommands.get(command);
  const modcommandfile = client.modcommands.get(command);
  const admcommandfile = client.admincommands.get(command);
  const devcommandfile = client.devcommands.get(command);
  const extcommandfile = client.extcommands.get(command);
  const owncommandfile = client.ownercommands.get(command);
  //
  
  //Command runner
  if (message.content.startsWith(`__help`)) {
    if (CON.showDiagnoseNums) console.log(`3help`);
    console.log(client.extcommands);
    diffArgs = message.content.split(` `);
    diffArgs.shift();
    console.log(`[”${diffArgs}”]`);
    if (CON.showDiagnoseNums) console.log(`4help`);
    return client.extcommands.get(`help`).run(client, message, diffArgs, guildConf);
  }
  
  if (message.content.startsWith(`__config`)) {
    if (CON.showDiagnoseNums) console.log(`3config`);
    prefix2 = `__`;
    console.log(args);
    if (!message.member.hasPermission(`ADMINISTRATOR`)) return message.reply(`you are not an admin. (this is a quickly written message that will be changed.)`)
    if (CON.showDiagnoseNums) console.log(`4config`);
    return client.admincommands.get(`config`).run(client, message, args);
  }
  
  if (!message.content.startsWith(guildConf.prefix)) return;
  
  if (CON.showDiagnoseNums) console.log(`3gen`);
  
  if (funcommandfile) return funcommandfile.run(client, message, args);
  if (extcommandfile) return extcommandfile.run(client, message, args, guildConf);
  
  if (config.ownerIDS.includes(message.author.id)) {
    if (modcommandfile) return modcommandfile.run(client, message, args);
    if (admcommandfile) return admcommandfile.run(client, message, args);
    if (devcommandfile) return devcommandfile.run(client, message, args);
    if (owncommandfile) return owncommandfile.run(client, message, args);
  }
  
  if (config.developers.includes(message.author.id)) {
    if (modcommandfile) return modcommandfile.run(client, message, args);
    if (admcommandfile) return admcommandfile.run(client, message, args);
    if (devcommandfile) return devcommandfile.run(client, message, args);
  }
  
  if (CON.showDiagnoseNums) console.log(`4gen`);
  
  if (message.member.roles.find(role => role === guildConf.adminRole) || message.member.hasPermission(`ADMINISTRATOR`)) {
    if (modcommandfile) return modcommandfile.run(client, message, args);
    if (admcommandfile) return admcommandfile.run(client, message, args);
  }
  
  if (message.member.roles.find(role => role === guildConf.modRole)) {
    if (modcommandfile) return modcommandfile.run(client, message, args);
  }
  
  if (modcommandfile) return message.reply("you are not an admin.");
  if (devcommandfile) return message.reply("you are not one of my developers. You have to be one of my developers to use that.");
  if (owncommandfile) return message.reply("you are not one of my makers. You have to be one of my makers to use this command.");
  //
  else return;
});

client.login(process.env.token);
node v10.16.0