Advertisement
t2wave

Not Quite Random

Feb 9th, 2020
342
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.36 KB | None | 0 0
  1. let alertDuration = {alertDuration};
  2. alertCoolDown = {alertCooldown};
  3. canAlert = true;
  4. aVolume = {alertVolume} * .01;
  5. var onCoolDown =[];
  6.  
  7.  
  8. /*
  9. use "image" for any gifs/images
  10. use "video" for a video
  11. use "mod": 0 if you want the command to be mod / broadcaster only
  12. use "sub": 0 if you want the command to be subscriber only
  13. use "sound" if you want a sound with your video, if your video has sound - this will play BOTH. and sound will
  14. play for the duration of your default alert duration or overide ie: Set Length to length of video ;)
  15.  
  16. ---- Image only Parameters ---
  17. use "volume" 1-100 to adjust the volume of a specific command
  18. Use "length" to set a length overide on the command (play longer or shorter than default)
  19. use "sound" to add a sound to your command
  20.  
  21.  
  22. ---- Play a random image, video, or sound ---
  23. This is an example for playing a random video on command. The first portion defines the videos
  24. that you would like to be in the pool, called an array. Each line must be separated by a , but you do
  25. not need one after the last value. If you wish to make another pool of videos simply copy the example
  26. below and change the "exampleArray" and "exampleOutput" to something else
  27. (ie. "exampleArray" to "hypeArray" and "exampleOutput" to "hypeOutput").
  28. Note that when changing the name of the array and output that you will also need to change it in the second
  29. portion after the "exampleRandom = " sign and toward the end before the ".length)];" and the the command
  30. section. I have identified them above the values with "// ARRAY NAME //" and "// OUTPUT NAME //". Just make
  31. sure the array names match each other and the output names match each other. Finally in the list of commands
  32. make sure to repalce the video link with the OUTPUT NAME. The same logic goes for images and sounds. */
  33.  
  34.  
  35. // -------------------------------- //
  36. // BEGIN RANDOM VIDEO ARRAY EXAMPLE //
  37. // -------------------------------- //
  38.  
  39. // ARRAY NAME //
  40. var exampleArray = ["https://cdn.streamelements.com/uploads/a64a9a9b-bc20-43aa-9018-d6f678112349.mp4",
  41. "https://cdn.streamelements.com/uploads/9c1afdd5-27c2-466b-91d0-238a9a4366ad.mp4",
  42. "https://cdn.streamelements.com/uploads/176cde36-97f6-4655-90ab-86064008978d.mp4"
  43. ];
  44.  
  45. // OUTPUT NAME /// ARRAY NAME // // ARRAY NAME //
  46. var exampleOutput = exampleArray[Math.floor(Math.random() * exampleArray.length)];
  47.  
  48. // -------------------------------- //
  49. // END RANDOM VIDEO ARRAY EXAMPLE //
  50. // -------------------------------- //
  51.  
  52.  
  53. //!!!!!!!!!!!!!!!!!!! MIXER -- The SUB/MoB restriction currently doesnt' work//
  54. alertCommands ={
  55. "!hype": {
  56. "image": "https://cdn.streamelements.com/uploads/f3918cf4-3a29-42c2-8708-e7c1495b4601.gif",
  57. "sound": "https://cdn.streamelements.com/uploads/ffb21cb9-3520-42f6-b69f-d875ddd1eae3.mp3",
  58. "length": 3000,
  59. "volume": 10
  60. },
  61. "!robin": {
  62. "video": "https://cdn.streamelements.com/uploads/a64a9a9b-bc20-43aa-9018-d6f678112349.mp4",
  63. "sub": 0
  64. },
  65. "!blue":{
  66. "image":"https://cdn.streamelements.com/uploads/c5190306-16d5-4484-91fe-8c81c4205db8.gif",
  67. "volume": 10,
  68. "length": 3000,
  69. "mod": 0
  70. },
  71. "!test":{
  72. "video": "https://cdn.streamelements.com/uploads/176cde36-97f6-4655-90ab-86064008978d.mp4"
  73. },
  74. // Random video example //
  75. "!randomvid":{
  76. // OUTPUT NAME//
  77. "video": exampleOutput
  78. }
  79. };
  80.  
  81.  
  82.  
  83. window.addEventListener('onEventReceived', function (obj) {
  84. if (!obj.detail.event) {
  85. return;
  86. }
  87. const event = obj.detail.event;
  88.  
  89. if (obj.detail.listener !== "message") return;
  90. var command = event["data"]["text"].split(" ")[0].toLowerCase();
  91. var data = obj.detail.event.data;
  92. var notCooldown = onCoolDown.includes(command);
  93.  
  94. if(event["data"]["badges"].length > 0) //Twitch Functionality Only
  95. var badge = event["data"]["badges"][0]["type"];
  96.  
  97. var isMod = (badge === 'moderator' || badge === 'broadcaster');
  98. var isSub = (badge === 'subscriber'|| badge === 'broadcaster' || badge === 'moderator' );
  99.  
  100. if(command in alertCommands && canAlert && !notCooldown){
  101.  
  102. if('sub' in alertCommands[command] && !isSub)
  103. return;
  104. if('mod' in alertCommands[command] && !isMod)
  105. return;
  106.  
  107. canAlert = false;
  108.  
  109. if("volume" in alertCommands[command])
  110. aVolume = alertCommands[command]["volume"] * .01;
  111. if("length" in alertCommands[command])
  112. alertDuration = alertCommands[command]["length"];
  113. if("sound" in alertCommands[command])
  114. playAudio(alertCommands[command]["sound"], alertDuration);
  115. if("image" in alertCommands[command]){
  116. showImage(alertCommands[command]["image"],alertDuration );
  117. }
  118. else{
  119. // do stuff in here for video
  120. playVideo(alertCommands[command]["video"]);
  121. if("length" in alertCommands[command])
  122. alertDuration = alertCommands[command]["length"];
  123. if("sound" in alertCommands[command])
  124. playAudio(alertCommands[command]["sound"], alertDuration);
  125. }
  126.  
  127.  
  128. onCoolDown.push(command);
  129.  
  130. setTimeout(function () {
  131. onCoolDown.shift();
  132. }, alertCoolDown);
  133.  
  134. setTimeout(function () {
  135. canAlert = true;
  136. alertDuration = {alertDuration};
  137. aVolume = {alertVolume} * .01;
  138. }, alertDuration + 1000);
  139. }
  140.  
  141. });
  142.  
  143.  
  144. function playAudio(sound, alertD){
  145.  
  146. let audio = new Audio(sound);
  147. audio.volume = aVolume;
  148. audio.play();
  149. setTimeout(function () {
  150. audio.pause();
  151. }, alertD);
  152. }
  153.  
  154. function showImage(imageSRC, alertD){
  155.  
  156. $('#img').attr('src',imageSRC).hide().fadeIn("slow");
  157. //$('#img').attr('src',imageSRC).hide().slideDown(1500);
  158.  
  159. setTimeout(function () {
  160. $('img').fadeOut("slow");
  161. }, alertD);
  162. }
  163.  
  164. function playVideo(videoSRC){
  165. var vid = document.getElementById("vid");
  166. $('#vid').attr('src',videoSRC).hide().fadeIn("slow");
  167.  
  168. vid.volume = aVolume;
  169. vid.play();
  170.  
  171. $("#vid").fadeTo("slow",1);
  172. $('#vid').on('ended', function () {
  173. $("#vid").fadeTo("slow",0);
  174. $("#vid")[0].pause();
  175. });
  176.  
  177. }
  178. shuffle(exampleArray);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement