-
-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathindex.js
79 lines (62 loc) · 2.07 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
/* Config */
const twitchTvHandle = "bdougieYO";
const PAUSE_DURATION = 30 * 1000; // 30 seconds
const DISPLAY_DURATION = 10 * 1000; // 10 seconds
/* DOM */
const container = document.querySelector(".alerts");
const img = new Image();
const queue = new Queue();
/* Sound Effects */
const pewAudio = new Audio("horn.wav");
const magicChime = new Audio("Magic_Chime.mp3");
/* GIFs */
const beyGif = "https://media.giphy.com/media/VxkNDa92gcsRq/giphy.gif";
const welcomeGif = "https://media.giphy.com/media/l3V0doGbp2EDaLHJC/giphy.gif";
const pizzaGif = "https://media.giphy.com/media/3o6nUXaNE4wdhq8Foc/giphy.gif";
// Resolve promise after duration
const wait = async duration => {
return new Promise(resolve => setTimeout(resolve, duration));
};
const pauseSpotify = () => {
fetch("https://serve.onegraph.com/graphql?app_id=cdf2ebe1-3ad3-408a-81c0-1ed675d76411", {body: '{"doc_id": "10fccd15-1a55-4a27-877a-a63106b4bd11"}', method: "POST"})
}
ComfyJS.Init(twitchTvHandle);
ComfyJS.onCommand = (user, command, message, flags, extra) => {
console.log(`!${command} was typed in chat`);
if (command == "yo") {
new gifAlert(user, beyGif, pewAudio, command);
}
if (command == "welcome") {
new gifAlert(message, welcomeGif, magicChime, command);
}
if (flags.broadcaster && command == "pizza") {
new gifAlert(message, pizzaGif, magicChime, command);
}
if (flags.broadcaster && command == "pause") {
// Clear GIF queue and pause for PAUSE_DURATION
queue.clear();
queue.pause(PAUSE_DURATION);
}
};
ComfyJS.onChat = (user, message, flags, self, extra) => {
console.log(user + ":", message);
};
const generateTitle = {
yo: " is hype!",
welcome: " needs a welcome!",
pizza: " needed a pizza party!",
};
function gifAlert(user, gif, audio, type) {
queue.add(async () => {
audio.play();
container.innerHTML = `
<h1 class="text-shadows">${user + generateTitle[type]}</h1>
<img src="${gif}" />
`;
container.style.opacity = 1;
await wait(DISPLAY_DURATION);
if (!queue.isLooping) {
container.style.opacity = 0;
}
});
}