-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtwitch.js
More file actions
65 lines (53 loc) · 2.12 KB
/
twitch.js
File metadata and controls
65 lines (53 loc) · 2.12 KB
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
const config = require('./config');
const tmi = require('tmi.js');
const opts = {
identity: {
username: config.botConfig.bot_username,
password: config.botConfig.bot_token,
},
channels: [
config.botConfig.channel_name
]
};
const client = tmi.Client(opts);
var LinkSpamMiddleWare = require('./middlewares/linkSpamCheck').linkSpamMiddleware;
var linkSpamMiddleWare = new LinkSpamMiddleWare({
excludedRoles: config.botConfig.link_spam_protection.excludedRoles,
excludedLinks: config.botConfig.link_spam_protection.excludedLinks,
timeout: config.botConfig.link_spam_protection.timeout,
}, client);
var BlacklistMiddleware = require('./middlewares/blacklistCheck').blacklistMiddleware;
var blacklistMiddleware = new BlacklistMiddleware({
channel_name: config.botConfig.channel_name,
timeout: config.botConfig.blacklist_protection.timeout,
}, client);
var AnnounceMiddleware = require('./middlewares/announceSystem').announceMiddleware;
var announceMiddleware = new AnnounceMiddleware({
channel_name: config.botConfig.channel_name,
}, client);
var CommandsMiddleware = require('./middlewares/commands').commandsMiddleware;
var commandsMiddleware = new CommandsMiddleware({
channel_name: config.botConfig.channel_name,
client_id: config.botConfig.client_id,
spotifyConfig: config.spotifyConfig,
twitchConfig: config.twitchConfig,
serverConfig: config.serverConfig,
isLocal: config.botConfig.isLocal,
timeout: config.botConfig.spam_protection.timeout,
}, client, linkSpamMiddleWare, blacklistMiddleware, announceMiddleware);
const messageHandler = (target, context, msg, self) => {
if (self) return;
if (!linkSpamMiddleWare.runMiddleware(msg, context, target))
return;
if (!blacklistMiddleware.runMiddleware(msg, context, target))
return;
if (!commandsMiddleware.runMiddleware(msg, context, target))
return;
}
const connectedHandler = (addr, port) => {
console.log('Twitch Bot is ready and up!');
}
client.on('message', messageHandler);
client.on('connected', connectedHandler);
client.connect();
exports.twitchClient = client;