forked from gillesheinesch/LenoxBot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnewreadyevent.js
445 lines (388 loc) · 21.6 KB
/
newreadyevent.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
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
const Discord = require('discord.js');
module.exports = {
run: () => {
const chalk = require('chalk');
const users = [];
for (const discordUser of client.users.array()) {
const user = {
id: discordUser.id,
username: discordUser.username,
discriminator: discordUser.discriminator,
avatar: discordUser.avatar
};
users.push(user);
}
const bulkMessage = {
type: 'bulk',
data: users
};
process.send(bulkMessage);
client.ready = true;
if (client.provider.isReady) {
console.log(chalk.green('LenoxBot is ready!'));
require('../bin/www');
}
else {
client.provider.whenReady(async () => {
console.log(chalk.green('LenoxBot is ready!'));
console.log('tzestz');
// require('../bin/www');
console.log('zesz');
var http = require('http');
// The following 4 are the actual values that pertain to your account and this specific metric.
var apiKey = 'bf5c8a5f-0db4-4de8-b857-e7cbef2396e1';
var pageId = 'h9w5z6ysgc7f';
var metricId = 'ylj331dftyzq';
var apiBase = 'https://api.statuspage.io/v1';
var url = `${apiBase}/pages/${pageId}/metrics/${metricId}/data.json`;
var authHeader = { Authorization: `OAuth ${apiKey}` };
var options = { method: 'POST', headers: authHeader };
// Need at least 1 data point for every 5 minutes.
// Submit random data for the whole day.
var totalPoints = 60 / 5 * 24;
var epochInSeconds = Math.floor(new Date() / 1000);
// This function gets called every second.
function submit(count) {
count += 1;
if (count > totalPoints) return;
console.log(2);
var currentTimestamp = epochInSeconds - (count - 1) * 5 * 60;
var randomValue = Math.floor(Math.random() * 1000);
console.log(22);
var data = {
timestamp: currentTimestamp,
value: randomValue
};
console.log(222);
var request = http.request(url, options, (res) => {
console.log(res);
res.on('data', () => {
console.log(`Submitted point ${count} of ${totalPoints}`);
});
console.log(2222);
res.on('end', () => {
console.log(232);
setTimeout(() => { submit(count); }, 1000);
});
});
console.log(111)
request.end(JSON.stringify({ data }));
}
// Initial call to start submitting data.
console.log(1)
submit(100);
console.log(21);
// Sets all marketitems
const marketconfs = require('../marketitems-keys.json');
await client.provider.setBotsettings('botconfs', 'market', marketconfs);
// Sets the prefix for every guild
for (let i = 0; i < client.guilds.array().length; i += 1) {
if (client.provider.getGuild(client.guilds.array()[i].id, 'prefix')) {
client.guilds.array()[i]._commandPrefix = client.provider.getGuild(client.guilds.array()[i].id, 'prefix');
}
}
await client.provider.setBotsettings('botconfs', 'botstats', {
botguildscount: client.guilds.size,
botmemberscount: client.users.size,
botcommands: client.provider.getBotsettings('botconfs', 'commandsexecuted'),
botcommandsincrement: Math.floor(client.provider.getBotsettings('botconfs', 'commandsexecuted') / 170) + 1,
botmemberscountincrement: Math.floor(client.users.size / 170) + 1,
botguildscountincrement: Math.floor(client.guilds.size / 170) + 1
});
function timeoutForReminder(reminder, timeoutTime) {
setTimeout(async () => {
const currentReminder2 = client.provider.getUser(reminder.userId, 'currentReminder');
const indexOfRemind = currentReminder2.indexOf(reminder.id);
currentReminder2.splice(indexOfRemind, 1);
await client.provider.setUser(reminder.userId, 'currentReminder', currentReminder2);
const currentReminders2 = client.provider.getBotsettings('botconfs', 'reminder');
delete currentReminders2[reminder.id];
await client.provider.setBotsettings('botconfs', 'reminder', currentReminders2);
const langSet = client.provider.getGuild(reminder.guildId, 'language');
const lang = require(`../languages/${langSet}.json`);
const remindPassedEmbed = new Discord.MessageEmbed()
.setColor('BLUE')
.setTimestamp()
.setTitle(lang.remind_embedremindpassed)
.setDescription(`${lang.remind_addembedtext}: ${reminder.text}`);
client.channels.get(reminder.channelId).send({
reply: reminder.userId,
embed: remindPassedEmbed
});
}, timeoutTime);
}
if (typeof client.provider.getBotsettings('botconfs', 'reminder') !== 'undefined') {
if (Object.keys(client.provider.getBotsettings('botconfs', 'reminder')).length !== 0) {
/* eslint guard-for-in: 0 */
for (const index in client.provider.getBotsettings('botconfs', 'reminder')) {
const timeoutTime = client.provider.getBotsettings('botconfs', 'reminder')[index].remindEndDate - Date.now();
timeoutForReminder(client.provider.getBotsettings('botconfs', 'reminder')[index], timeoutTime);
}
}
}
function timeoutForDaily(dailyreminder, timeoutTime) {
setTimeout(async () => {
client.users.get(dailyreminder.userID).send('Don\'t forget to pick up your daily reward');
const currentDailyreminder = client.provider.getBotsettings('botconfs', 'dailyreminder');
delete currentDailyreminder[dailyreminder.userID];
await client.provider.setBotsettings('botconfs', 'dailyreminder', currentDailyreminder);
}, timeoutTime);
}
if (typeof client.provider.getBotsettings('botconfs', 'dailyreminder') !== 'undefined') {
if (Object.keys(client.provider.getBotsettings('botconfs', 'dailyreminder')).length !== 0) {
/* eslint guard-for-in: 0 */
for (const index in client.provider.getBotsettings('botconfs', 'dailyreminder')) {
const timeoutTime = client.provider.getBotsettings('botconfs', 'dailyreminder')[index].remind - Date.now();
timeoutForDaily(client.provider.getBotsettings('botconfs', 'dailyreminder')[index], timeoutTime);
}
}
}
function timeoutForJob(jobreminder, timeoutTime) {
setTimeout(async () => {
await client.provider.setUser(jobreminder.userID, 'jobstatus', false);
const newCurrentJobreminder = client.provider.getBotsettings('botconfs', 'jobreminder');
delete newCurrentJobreminder[jobreminder.userID];
await client.provider.setBotsettings('botconfs', 'jobreminder', newCurrentJobreminder);
let currentCredits = client.provider.getUser(jobreminder.userID, 'credits');
currentCredits += jobreminder.amount;
await client.provider.setUser(jobreminder.userID, 'credits', currentCredits);
const jobfinish = `Congratulations! You have successfully completed your job. You earned a total of ${jobreminder.amount} credits`;
client.users.get(jobreminder.userID).send(jobfinish);
const activityEmbed2 = new Discord.MessageEmbed()
.setAuthor(`${client.users.get(jobreminder.userID).tag} (${jobreminder.userID})`, client.users.get(jobreminder.userID).displayAvatarURL())
.setDescription(`**Job:** ${jobreminder.job} \n**Duration:** ${jobreminder.jobtime} minutes \n**Amount:** ${jobreminder.amount} credits`)
.addField('Guild', `${client.guilds.get(jobreminder.discordServerID).name} (${jobreminder.discordServerID})`)
.addField('Channel', `${client.channels.get(jobreminder.channelID).name} (${jobreminder.channelID})`)
.setColor('AQUA')
.setFooter('JOB FINISHED')
.setTimestamp();
if (client.provider.getBotsettings('botconfs', 'activity') === true) {
const messagechannel = client.channels.get(client.provider.getBotsettings('botconfs', 'activitychannel'));
messagechannel.send({
embed: activityEmbed2
});
}
}, timeoutTime);
}
if (typeof client.provider.getBotsettings('botconfs', 'jobreminder') !== 'undefined') {
if (Object.keys(client.provider.getBotsettings('botconfs', 'jobreminder')).length !== 0) {
/* eslint guard-for-in: 0 */
for (const index in client.provider.getBotsettings('botconfs', 'jobreminder')) {
const timeoutTime = client.provider.getBotsettings('botconfs', 'jobreminder')[index].remind - Date.now();
timeoutForJob(client.provider.getBotsettings('botconfs', 'jobreminder')[index], timeoutTime);
}
}
}
function timeoutForBan(bansconf, newBanTime, fetchedbansfromfunction) {
setTimeout(async () => {
const langSet = client.provider.getGuild(bansconf.discordserverid, 'language');
const lang = require(`../languages/${langSet}.json`);
const fetchedbans = fetchedbansfromfunction;
if (fetchedbans.has(bansconf.memberid)) {
const user = client.users.get(bansconf.memberid);
client.guilds.get(bansconf.discordserverid).members.unban(bansconf.memberid);
const unbannedby = lang.unban_unbannedby.replace('%authortag', `${client.user.tag}`);
const automaticbandescription = lang.temporaryban_automaticbandescription.replace('%usertag', `${user.username}#${user.discriminator}`).replace('%userid', user.id);
const unmutedembed = new Discord.MessageEmbed()
.setAuthor(unbannedby, client.user.displayAvatarURL())
.setThumbnail(user.displayAvatarURL())
.setColor('#FF0000')
.setTimestamp()
.setDescription(automaticbandescription);
if (client.provider.getGuild(bansconf.discordserverid, 'modlog') === 'true') {
const modlogchannel = client.channels.get(client.provider.getGuild(bansconf.discordserverid, 'modlogchannel'));
modlogchannel.send({
embed: unmutedembed
});
}
const currentPunishments = client.provider.getGuild(bansconf.discordserverid, 'punishments');
const punishmentConfig = {
id: currentPunishments.length + 1,
userId: user.id,
reason: lang.temporaryban_automaticunban,
date: Date.now(),
moderatorId: client.user.id,
type: 'unban'
};
currentPunishments.push(punishmentConfig);
await client.provider.setGuild(bansconf.discordserverid, 'punishments', currentPunishments);
}
const newbansconf = client.provider.getBotsettings('botconfs', 'bans');
delete newbansconf[client.provider.getBotsettings('botconfs', 'banscount')];
await client.provider.setBotsettings('botconfs', 'bans', newbansconf);
}, newBanTime);
}
function timeoutForMute(muteconf, newMuteTime) {
setTimeout(async () => {
const guild = client.guilds.get(muteconf.discordserverid);
if (!guild) return;
const membermention = await guild.members.fetch(muteconf.memberid).catch(() => undefined);
if (!membermention) return undefined;
const role = client.guilds.get(muteconf.discordserverid).roles.get(muteconf.roleid);
if (!role) return undefined;
const user = client.users.get(muteconf.memberid);
if (!user) return undefined;
const langSet = client.provider.getGuild(muteconf.discordserverid, 'language');
const lang = require(`../languages/${langSet}.json`);
if (client.provider.getGuild(muteconf.discordserverid, 'muterole') !== '' && membermention.roles.has(client.provider.getGuild(muteconf.discordserverid, 'muterole'))) {
membermention.roles.remove(role);
const unmutedby = lang.unmute_unmutedby.replace('%authortag', `${client.user.tag}`);
const automaticunmutedescription = lang.unmute_automaticunmutedescription.replace('%usertag', `${user.username}#${user.discriminator}`).replace('%userid', user.id);
const unmutedembed = new Discord.MessageEmbed()
.setAuthor(unmutedby, client.user.displayAvatarURL())
.setThumbnail(user.displayAvatarURL())
.setColor('#FF0000')
.setTimestamp()
.setDescription(automaticunmutedescription);
user.send({
embed: unmutedembed
});
if (client.provider.getGuild(muteconf.discordserverid, 'modlog') === 'true') {
const modlogchannel = client.channels.get(client.provider.getGuild(muteconf.discordserverid, 'modlogchannel'));
modlogchannel.send({
embed: unmutedembed
});
}
const currentPunishments = client.provider.getGuild(muteconf.discordserverid, 'punishments');
const punishmentConfig = {
id: currentPunishments.length + 1,
userId: user.id,
reason: lang.mute_automaticunmute,
date: Date.now(),
moderatorId: client.user.id,
type: 'unmute'
};
currentPunishments.push(punishmentConfig);
await client.provider.setGuild(muteconf.discordserverid, 'punishments', currentPunishments);
}
const newmuteconf = client.provider.getBotsettings('botconfs', 'mutes');
delete newmuteconf[muteconf.mutescount];
await client.provider.setBotsettings('botconfs', 'mutes', newmuteconf);
}, newMuteTime);
}
if (typeof client.provider.getBotsettings('botconfs', 'bans') !== 'undefined') {
if (Object.keys(client.provider.getBotsettings('botconfs', 'bans')).length !== 0) {
for (const index in client.provider.getBotsettings('botconfs', 'bans')) {
const newBanTime = client.provider.getBotsettings('botconfs', 'bans')[index].banEndDate - Date.now();
const fetchedbans = await client.guilds.get(client.provider.getBotsettings('botconfs', 'bans')[index].discordserverid).fetchBans();
timeoutForBan(client.provider.getBotsettings('botconfs', 'bans')[index], newBanTime, fetchedbans);
}
}
}
if (typeof client.provider.getBotsettings('botconfs', 'mutes') !== 'undefined') {
if (Object.keys(client.provider.getBotsettings('botconfs', 'mutes')).length !== 0) {
for (const index2 in client.provider.getBotsettings('botconfs', 'mutes')) {
const newMuteTime = client.provider.getBotsettings('botconfs', 'mutes')[index2].muteEndDate - Date.now();
timeoutForMute(client.provider.getBotsettings('botconfs', 'mutes')[index2], newMuteTime);
}
}
}
setInterval(() => {
client.guilds.filter((g) => client.provider.getGuild(g.id, 'prefix')).forEach(async (g) => {
if (client.provider.getGuild(g.id, 'premium')) {
if (client.provider.getGuild(g.id, 'premium').status === true) {
if (new Date().getTime() >= Date.parse(client.provider.getGuild(g.id, 'premium').end)) {
const currentPremium = client.provider.getGuild(g.id, 'premium');
currentPremium.status = false;
currentPremium.bought = [];
currentPremium.end = '';
await client.provider.setGuild(g.id, 'premium', currentPremium);
}
}
}
});
}, 86400000);
setInterval(() => {
client.users.filter((g) => client.provider.getUser(g.id, 'credits')).forEach(async (g) => {
if (client.provider.getUser(g.id, 'premium')) {
if (client.provider.getUser(g.id, 'premium').status === true) {
if (new Date().getTime() >= Date.parse(client.provider.getUser(g.id, 'premium').end)) {
const currentPremium = client.provider.getUser(g.id, 'premium');
currentPremium.status = false;
currentPremium.bought = [];
currentPremium.end = '';
await client.provider.setUser(g.id, 'premium', currentPremium);
}
}
}
});
}, 86400000);
const validation = ['administration', 'help', 'music', 'fun', 'searches', 'nsfw', 'utility', 'botowner', 'moderation', 'staff', 'application', 'currency', 'partner', 'tickets', 'customcommands'];
const commandsArray = [];
const englishLang = require('../languages/en-US.json');
for (let i = 0; i < validation.length; i += 1) {
for (let index = 0; index < client.registry.commands.filter((c) => c.groupID === validation[i]).array().length; index += 1) {
const commandObject = {};
commandObject.category = client.registry.commands.filter((c) => c.groupID === validation[i]).array()[index].groupID;
commandObject.name = client.registry.commands.filter((c) => c.groupID === validation[i]).array()[index].name;
commandObject.description = englishLang[`${client.registry.commands.filter((c) => c.groupID === validation[i]).array()[index].name}_description`] ? englishLang[`${client.registry.commands.filter((c) => c.groupID === validation[i]).array()[index].name}_description`] : client.registry.commands.filter((c) => c.groupID === validation[i]).array()[index].name.description;
commandObject.newaliases = client.registry.commands.filter((c) => c.groupID === validation[i]).array()[index].aliases;
commandObject.newuserpermissions = client.registry.commands.filter((c) => c.groupID === validation[i]).array()[index].userpermissions;
commandObject.usage = client.registry.commands.filter((c) => c.groupID === validation[i]).array()[index].format;
commandObject.dashboardsettings = client.registry.commands.filter((c) => c.groupID === validation[i]).array()[index].dashboardsettings;
commandsArray.push(commandObject);
}
}
await client.provider.setBotsettings('botconfs', 'commands', commandsArray);
setInterval(async () => {
const commandsArray2 = [];
for (let i = 0; i < validation.length; i += 1) {
for (let index = 0; index < client.registry.commands.filter((c) => c.groupID === validation[i]).array().length; index += 1) {
const commandObject = {};
commandObject.category = client.registry.commands.filter((c) => c.groupID === validation[i]).array()[index].groupID;
commandObject.name = client.registry.commands.filter((c) => c.groupID === validation[i]).array()[index].name;
commandObject.description = englishLang[`${client.registry.commands.filter((c) => c.groupID === validation[i]).array()[index].name}_description`] ? englishLang[`${client.registry.commands.filter((c) => c.groupID === validation[i]).array()[index].name}_description`] : client.registry.commands.filter((c) => c.groupID === validation[i]).array()[index].name.description;
commandObject.newaliases = client.registry.commands.filter((c) => c.groupID === validation[i]).array()[index].aliases;
commandObject.newuserpermissions = client.registry.commands.filter((c) => c.groupID === validation[i]).array()[index].userpermissions;
commandObject.usage = client.registry.commands.filter((c) => c.groupID === validation[i]).array()[index].format;
commandObject.dashboardsettings = client.registry.commands.filter((c) => c.groupID === validation[i]).array()[index].dashboardsettings;
commandsArray2.push(commandObject);
}
}
await client.provider.setBotsettings('botconfs', 'commands', commandsArray2);
}, 86400000);
// Creditsranklist leaderboard
/* let userInfo = [];
const userSettingsList = await client.provider.userSettings;
for (const key of userSettingsList) {
if (!isNaN(key[1].credits) && client.users.get(key[0])) {
const userResult = client.users.get(key[0]);
const userCreditsSettings = {
userId: key[0],
user: userResult ? userResult : key[0],
credits: Number(key[1].credits),
rank: 0
};
if (key[0] !== 'global') {
userInfo.push(userCreditsSettings);
}
}
}
userInfo = userInfo.sort((a, b) => {
if (a.credits < b.credits) {
return 1;
}
if (a.credits > b.credits) {
return -1;
}
return 0;
});
for (let i = 0; i < userInfo.length; i += 1) {
userInfo[i].rank = (i + 1);
}
await client.provider.setBotsettings('botconfs', 'top100credits', userInfo); */
const embed = new Discord.MessageEmbed()
.setTitle('Botrestart')
.setDescription('LenoxBot had a restart and is back again!\nEveryone can now execute commands!')
.setColor('GREEN')
.setTimestamp()
.setAuthor(client.user.tag, client.user.displayAvatarURL());
if (client.user.id === '354712333853130752') {
client.channels.get('497400107109580801').send({
embed
});
}
});
}
}
};