This repository has been archived by the owner on Feb 16, 2021. It is now read-only.
forked from FreeCodeCampOKC/twitch_slack_bot
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathRelay.js
59 lines (54 loc) · 1.68 KB
/
Relay.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
class Relay {
constructor(slackChannel, twitchChannel) {
this.slackBot;
this.twitchBot;
this.slackChannel = slackChannel;
this.twitchChannel = twitchChannel;
}
createBot(bot, type) {
switch (type.toLowerCase()) {
case 'slack':
this.slackBot = bot;
break;
case 'twitch':
this.twitchBot = bot;
break;
default:
console.error('Unsupported bot type. Only Slack and Twitch bots are allowed');
}
}
sendMessage(user, message, destination) {
console.log('Relay has received message: ', message);
console.log('From:', user);
console.log('To:', destination);
function getMessageForTwitch()
{
var regex = /^<@.*\|.*> (has (joined|left) the channel|set the channel (purpose|topic))/;
if (message.match(regex))
{
console.log(message);
return undefined;
}
else
{
return `On Slack, ${ user } said: ${ message }`;
}
}
switch (destination.toLowerCase()) {
case 'slack':
message = `On Twitch, *${ user }* said: \n>>>${ message }`;
this.slackBot.postMessageToChannel(this.slackChannel, message);
break;
case 'twitch':
message = getMessageForTwitch();
if (message)
{
this.twitchBot.action(this.twitchChannel, message);
}
break;
default:
console.error('Trying to send message to unknown destination.');
}
}
}
module.exports = Relay;