-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
88 lines (74 loc) · 2.53 KB
/
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
const Eris = require('eris');
const DB = require('./Database');
const fs = require('fs');
const path = require('path');
const { cleanGuild, cleanChannel, cleanRole } = require('./utils');
const { v4: uuid } = require('uuid')
require('dotenv').config();
const bot = new Eris(process.env.TOKEN);
const db = new DB(process.env.DB);
const proxy = new Proxy(db, {
get: (target, prop, receiver) => {
return target._models[prop];
}
});
bot.on('ready', async () => {
console.log('Git ready to log!');
bot.guilds.map(guild => guild).forEach(async guild => {
let guildCommits = await proxy.Log.find({ guildID: guild.id });
if (guildCommits.length === 0) {
console.log('Creating commits for', guild.id);
const guildJSON = cleanGuild(guild);
await proxy.Log.create({
guildID: guild.id,
change: 'create',
guildPart: 'guild',
partID: guild.id,
perpID: bot.user.id,
oldValue: {},
newValue: {},
commitID: uuid()
});
for (let channel of guild.channels.map(channel => channel)) {
const channelJSON = cleanChannel(channel);
await proxy.Log.create({
guildID: guild.id,
change: 'create',
guildPart: 'channel',
partID: channel.id,
perpID: bot.user.id,
oldValue: {},
newValue: channelJSON,
commitID: uuid()
});
}
for (let role of guild.roles.map(role => role)) {
const roleJSON = cleanRole(role);
await proxy.Log.create({
guildID: guild.id,
change: 'create',
guildPart: 'role',
partID: role.id,
perpID: bot.user.id,
oldValue: {},
newValue: roleJSON,
commitID: uuid()
});
}
}
});
});
fs.readdir(path.join(__dirname, 'events'), (err, files) => {
if (err) {
return console.log(err);
} else {
for (let file of files) {
let eventName = file.split('.')[0];
let handler = require(path.join(__dirname, 'events', file));
bot.on(eventName, (...params) => {
handler(bot, proxy, ...params);
});
}
}
});
bot.connect();