Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- let alertDuration = {alertDuration};
- alertCoolDown = {alertCooldown};
- canAlert = true;
- aVolume = {alertVolume} * .01;
- var onCoolDown =[];
- /*
- use "image" for any gifs/images
- use "video" for a video
- use "mod": 0 if you want the command to be mod / broadcaster only
- use "sub": 0 if you want the command to be subscriber only
- use "sound" if you want a sound with your video, if your video has sound - this will play BOTH. and sound will
- play for the duration of your default alert duration or overide ie: Set Length to length of video ;)
- ---- Image only Parameters ---
- use "volume" 1-100 to adjust the volume of a specific command
- Use "length" to set a length overide on the command (play longer or shorter than default)
- use "sound" to add a sound to your command
- ---- Play a random image, video, or sound ---
- This is an example for playing a random video on command. The first portion defines the videos
- that you would like to be in the pool, called an array. Each line must be separated by a , but you do
- not need one after the last value. If you wish to make another pool of videos simply copy the example
- below and change the "exampleArray" and "exampleOutput" to something else
- (ie. "exampleArray" to "hypeArray" and "exampleOutput" to "hypeOutput").
- Note that when changing the name of the array and output that you will also need to change it in the second
- portion after the "exampleRandom = " sign and toward the end before the ".length)];" and the the command
- section. I have identified them above the values with "// ARRAY NAME //" and "// OUTPUT NAME //". Just make
- sure the array names match each other and the output names match each other. Finally in the list of commands
- make sure to repalce the video link with the OUTPUT NAME. The same logic goes for images and sounds. */
- // -------------------------------- //
- // BEGIN RANDOM VIDEO ARRAY EXAMPLE //
- // -------------------------------- //
- // ARRAY NAME //
- var exampleArray = ["https://cdn.streamelements.com/uploads/a64a9a9b-bc20-43aa-9018-d6f678112349.mp4",
- "https://cdn.streamelements.com/uploads/9c1afdd5-27c2-466b-91d0-238a9a4366ad.mp4",
- "https://cdn.streamelements.com/uploads/176cde36-97f6-4655-90ab-86064008978d.mp4"
- ];
- // OUTPUT NAME /// ARRAY NAME // // ARRAY NAME //
- var exampleOutput = exampleArray[Math.floor(Math.random() * exampleArray.length)];
- // -------------------------------- //
- // END RANDOM VIDEO ARRAY EXAMPLE //
- // -------------------------------- //
- //!!!!!!!!!!!!!!!!!!! MIXER -- The SUB/MoB restriction currently doesnt' work//
- alertCommands ={
- "!hype": {
- "image": "https://cdn.streamelements.com/uploads/f3918cf4-3a29-42c2-8708-e7c1495b4601.gif",
- "sound": "https://cdn.streamelements.com/uploads/ffb21cb9-3520-42f6-b69f-d875ddd1eae3.mp3",
- "length": 3000,
- "volume": 10
- },
- "!robin": {
- "video": "https://cdn.streamelements.com/uploads/a64a9a9b-bc20-43aa-9018-d6f678112349.mp4",
- "sub": 0
- },
- "!blue":{
- "image":"https://cdn.streamelements.com/uploads/c5190306-16d5-4484-91fe-8c81c4205db8.gif",
- "volume": 10,
- "length": 3000,
- "mod": 0
- },
- "!test":{
- "video": "https://cdn.streamelements.com/uploads/176cde36-97f6-4655-90ab-86064008978d.mp4"
- },
- // Random video example //
- "!randomvid":{
- // OUTPUT NAME//
- "video": exampleOutput
- }
- };
- window.addEventListener('onEventReceived', function (obj) {
- if (!obj.detail.event) {
- return;
- }
- const event = obj.detail.event;
- if (obj.detail.listener !== "message") return;
- var command = event["data"]["text"].split(" ")[0].toLowerCase();
- var data = obj.detail.event.data;
- var notCooldown = onCoolDown.includes(command);
- if(event["data"]["badges"].length > 0) //Twitch Functionality Only
- var badge = event["data"]["badges"][0]["type"];
- var isMod = (badge === 'moderator' || badge === 'broadcaster');
- var isSub = (badge === 'subscriber'|| badge === 'broadcaster' || badge === 'moderator' );
- if(command in alertCommands && canAlert && !notCooldown){
- if('sub' in alertCommands[command] && !isSub)
- return;
- if('mod' in alertCommands[command] && !isMod)
- return;
- canAlert = false;
- if("volume" in alertCommands[command])
- aVolume = alertCommands[command]["volume"] * .01;
- if("length" in alertCommands[command])
- alertDuration = alertCommands[command]["length"];
- if("sound" in alertCommands[command])
- playAudio(alertCommands[command]["sound"], alertDuration);
- if("image" in alertCommands[command]){
- showImage(alertCommands[command]["image"],alertDuration );
- }
- else{
- // do stuff in here for video
- playVideo(alertCommands[command]["video"]);
- if("length" in alertCommands[command])
- alertDuration = alertCommands[command]["length"];
- if("sound" in alertCommands[command])
- playAudio(alertCommands[command]["sound"], alertDuration);
- }
- onCoolDown.push(command);
- setTimeout(function () {
- onCoolDown.shift();
- }, alertCoolDown);
- setTimeout(function () {
- canAlert = true;
- alertDuration = {alertDuration};
- aVolume = {alertVolume} * .01;
- }, alertDuration + 1000);
- }
- });
- function playAudio(sound, alertD){
- let audio = new Audio(sound);
- audio.volume = aVolume;
- audio.play();
- setTimeout(function () {
- audio.pause();
- }, alertD);
- }
- function showImage(imageSRC, alertD){
- $('#img').attr('src',imageSRC).hide().fadeIn("slow");
- //$('#img').attr('src',imageSRC).hide().slideDown(1500);
- setTimeout(function () {
- $('img').fadeOut("slow");
- }, alertD);
- }
- function playVideo(videoSRC){
- var vid = document.getElementById("vid");
- $('#vid').attr('src',videoSRC).hide().fadeIn("slow");
- vid.volume = aVolume;
- vid.play();
- $("#vid").fadeTo("slow",1);
- $('#vid').on('ended', function () {
- $("#vid").fadeTo("slow",0);
- $("#vid")[0].pause();
- });
- }
- shuffle(exampleArray);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement