This repository has been archived by the owner on Jan 31, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
64 lines (53 loc) · 1.49 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
const Discord=require('discord.js');
const shared=require('./api/shared');
const config=require('./api/config');
const commands=require('./api/commands');
const autorespond=require('./api/autoresponders');
const Calendar=require('./api/calendar');
const Loader=require('./api/loader');
const bot=new Discord.Client();
shared.bot=bot;
bot.on('ready', () => {
bot.user.setActivity(config('bot.prefix')+'help');
console.log("Logged in!");
});
bot.on('warning', (warn) => {
console.error('Bot warning', warn);
});
bot.on('error', (err) => {
console.error('Bot error', err);
});
if(config('bot.debug')) {
bot.on('debug', (txt) => {
console.error('Bot debug', txt);
});
}
bot.on('message', msg => {
try {
if(msg.content.startsWith(config('bot.prefix')) && !msg.author.bot && msg.content!=config('bot.prefix')) {
commands(msg);
}
autorespond(msg);
} catch(e) {
console.error(e);
msg.reply('ERROR');
}
});
bot.login(config('bot.token'));
shared.calendars={};
for(let i=0; i<config('groups.length'); i++) {
let group=config('groups.'+i);
shared.calendars[group.name]=new Calendar(group.calendar, group.name);
shared.calendars[group.name].on('update', () => console.log('updated calendar '+group.name));
}
let loader=new Loader('./modules');
loader.loadAll().then(() => {
console.log('Loaded all modules');
}).catch((e) => {
console.error(e);
});
let repl=require('repl').start('> ');
repl.context.shared=shared;
repl.context.config=config;
repl.context.bot=bot;
repl.context.loader=loader;