-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
70 lines (57 loc) · 1.72 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
const fs = require('fs');
//Package config.
class Bot {
constructor(discordClient, twitchClient, config) {
this.discordClient = discordClient;
this.twitchClient = twitchClient;
this.config = config;
this.commands = new Map();
this.aliases = new Map();
}
discordClient() {
return this.discordClient;
}
twitchClient() {
return this.twitchClient;
}
config() {
return this.config;
}
commands() {
return this.commands;
}
aliases() {
return this.aliases;
}
}
const config = require('./config.js');
//Discord Client
const Discord = require('discord.js');
//Twitch Client
const tmi = require('tmi.js');
//Creating New Bot Class
let joined = JSON.parse(fs.readFileSync("./data/twitchChannels.json"));
if (!joined || !joined.toJoin) {
if (!joined) joined = {};
if (!joined.toJoin) joined.toJoin = [];
fs.writeFileSync("./data/twitchChannels.json", JSON.stringify(joined, null, 2));
}
const bot = new Bot(new Discord.Client(),
new tmi.Client({
options: {debug: true},
connection: {
reconnect: true,
secure: true
},
identity: {
username: config.twitchUsername,
password: `oauth:${config.twitchToken}`
},
channels: joined.toJoin
}),
config);
bot.discordClient.login(bot.config.discordToken).catch(console.error);
bot.twitchClient.connect().catch(console.error);
//Loaders
require('./loaders/cmdLoader.js')(bot);
require('./loaders/eventLoader.js')(bot);