Guest User

Untitled

a guest
Jan 21st, 2024
16
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.40 KB | None | 0 0
  1. function shuffle(array) {
  2. if(!Array.isArray(array) return; // don't even read the rest of code here
  3. for (let i = array.length - 1; i > 0; i--) {
  4. const j = Math.floor(Math.random() * (i + 1));
  5. [ array[ i ], array[ j ] ] = [ array[ j ], array[ i ] ];
  6. }
  7. // pick first item of shuffled array
  8. return array[ 0 ];
  9.  
  10.  
  11. let alertDuration = {alertDuration};
  12. alertCoolDown = {alertCooldown};
  13. stopCommand = "!stopalert";
  14. canAlert = true;
  15. aVolume = {alertVolume} * .01;
  16. audio = null;
  17. var onCoolDown =[];
  18. /*
  19. - Tutorials here: https://www.youtube.com/_zanzer (theres one on how to get images / video links)
  20. - You can have multiple images/videos and pick a random one for a command see !test-
  21. use "image" for any gifs/images; use "video" for a video
  22.  
  23. use "sound" if you want a sound with your video, if your video has sound - this will play BOTH. and sound will
  24. play for the duration of your default alert duration or overide ie: Set Length to length of video
  25.  
  26. ---- Image only Parameters ---
  27. use "volume" 1-100 to adjust the volume osf a specific command
  28. Use "length" to set a length overide on the command (play longer or shorter than default)
  29. use "sound" to add a sound to your command
  30.  
  31. "!EXAMPLE": {
  32. "image": "https://cdn.streamelements.com/uploads/f3918cf4-3a29-42c2-8708-e7c1495b4601.gif",
  33. "sound": "https://cdn.streamelements.com/uploads/ffb21cb9-3520-42f6-b69f-d875ddd1eae3.mp3",
  34. "length": 6000, *set the length for that .mp4 or gif in ms*
  35. "volume": 50,
  36. "cooldown": 10000,
  37. "delaysound": 1000,
  38. "delayimage": 2000
  39. "sub": 0, // if you want the command to be subscriber only
  40. "mod": 0, // if you want the command to be mod / broadcaster only
  41.  
  42. "user": ["megalewdslime", "Rory"],
  43. "sound": ["linke #1","link #2","link #3"],
  44. "video": ["linke #1","link #2","link #3"],
  45. "image": ["linke #1","link #2","link #3"], }, */
  46.  
  47. alertCommands ={
  48.  
  49. /* TEST */
  50.  
  51. /* 01 */ "!pip1": { "cooldown": 0,
  52. "video": "https://cdn.discordapp.com/attachments/1198583469698195466/1198583497401573467/y2mate.is_-_MMDhololive_-wtH_gnF4LiU-720p-1705834951.mp4" },
  53.  
  54.  
  55. /* 02 */ "!pip2": { "cooldown": 0,
  56. "video": "https://cdn.discordapp.com/attachments/1198583469698195466/1198583777199390811/y2mate.is_-_Honkai_Star_Rail_MMD_4KTHE_METAL_SHEET_-_Seele_Bronya-mNZpS80ktXk-720p-1705835031.mp4" },
  57.  
  58.  
  59. /* END */
  60.  
  61. };
  62.  
  63. // ===============================================================================================================================================
  64. // ===============================================================================================================================================
  65. // ===============================================================================================================================================
  66. // ===============================================================================================================================================
  67.  
  68.  
  69. // ------------------------------- TIMER ------------------------------- // ------------------------------- TIMER -------------------------------
  70. var IntervallId = null;
  71. var timerC = 0;
  72. var start_timer = true;
  73. // ------------------------------- TIMER ------------------------------- // ------------------------------- TIMER -------------------------------
  74.  
  75.  
  76. window.addEventListener('onEventReceived', function (obj) {
  77. if (!obj.detail.event) {
  78. return;
  79. }
  80. const event = obj.detail.event;
  81.  
  82.  
  83. if (obj.detail.listener !== "message") return;
  84.  
  85. var command = event["data"]["text"].split(" ")[0].toLowerCase();
  86. var data = obj.detail.event.data;
  87. var senderName = event["data"]["displayName"].toLowerCase();
  88.  
  89. if(event["data"]["badges"].length > 0) //Twitch Functionality Only
  90. var badge = event["data"]["badges"][0]["type"];
  91.  
  92. var isMod = (badge === 'moderator' || badge === 'broadcaster');
  93. var isSub = (badge === 'subscriber'|| badge === 'broadcaster' || badge === 'moderator' );
  94.  
  95. if(command === stopCommand && isMod)
  96. {
  97. stopVideo();
  98. }
  99. if(command in alertCommands && canAlert && onCoolDown.length <= 0){
  100. if('sub' in alertCommands[command] && !isSub)
  101. return;
  102. if('mod' in alertCommands[command] && !isMod)
  103. return;
  104. if('user' in alertCommands[command] && !alertCommands[command]["user"].includes(senderName))
  105. return;
  106.  
  107.  
  108. // ------------------------------- TIMER ------------------------------- // ------------------------------- TIMER -------------------------------
  109. timerC = 0;
  110. $("#timer").html("");
  111. if(IntervallId != null){
  112. $("#timer").fadeTo(1000,0); // NOT WORKING - SET THE DURATION OF THE FADE OUT FOR THE TIMER
  113.  
  114. //IntervallId.forEach(element => clearInterval(element));
  115. //IntervallId.forEach(element => console.log(element));
  116. //clearInterval(IntervallId);
  117. }
  118. // ------------------------------- TIMER ------------------------------- // ------------------------------- TIMER -------------------------------
  119.  
  120.  
  121. alertCoolDown = {alertCooldown};
  122.  
  123. if("volume" in alertCommands[command])
  124. aVolume = alertCommands[command]["volume"] * .01;
  125. if("cooldown" in alertCommands[command])
  126. alertCoolDown = alertCommands[command]["cooldown"];
  127. if("length" in alertCommands[command])
  128. alertDuration = alertCommands[command]["length"];
  129. if("sound" in alertCommands[command]){
  130.  
  131. var playThis = alertCommands[command]["sound"];
  132. if(Array.isArray(playThis))
  133. playThis = playThis[Math.floor(Math.random() * playThis.length)];
  134.  
  135. if("delaysound" in alertCommands[command]){
  136. setTimeout(function () {
  137. playAudio(playThis, alertDuration);
  138. }, alertCommands[command]['delaysound'] - alertCommands[command]['delaysound']);
  139. }
  140. else
  141. playAudio(playThis, alertDuration);
  142. }
  143. if("image" in alertCommands[command]){
  144. var showThis = alertCommands[command]["image"];
  145. if(Array.isArray(showThis))
  146. showThis = showThis[Math.floor(Math.random() * showThis.length)];
  147.  
  148. if('delayimage' in alertCommands[command]){
  149. setTimeout(function () {
  150. showImage(showThis,alertDuration - alertCommands[command]['delayimage'] );
  151. }, alertCommands[command]['delayimage']);
  152. }
  153. else
  154. showImage(showThis,alertDuration );
  155. }
  156. if("video" in alertCommands[command]){
  157.  
  158. // do stuff in here for video
  159.  
  160.  
  161. var showThis = alertCommands[command]["video"];
  162.  
  163.  
  164. };
  165.  
  166. if(Array.isArray(showThis))
  167. showThis = shuffle(showThis);
  168.  
  169. // ------------------------------- TIMER ------------------------------- // ------------------------------- TIMER -------------------------------
  170. // ADDED ---- , alertCoolDown, command); ---- TO THE LINE
  171. playVideo(showThis, alertCoolDown, command);
  172. // ------------------------------- TIMER ------------------------------- // ------------------------------- TIMER -------------------------------
  173.  
  174. if("length" in alertCommands[command])
  175. alertDuration = alertCommands[command]["length"];
  176. if("sound" in alertCommands[command])
  177. if("delaysound" in alertCommands[command]){
  178. setTimeout(function () {
  179. playAudio(alertCommands[command]["sound"], alertDuration - alertCommands[command]['delaysound'] );
  180. }, alertCommands[command]['delaysound']);
  181. }
  182. else
  183. playAudio(alertCommands[command]["sound"], alertDuration);
  184. }
  185.  
  186.  
  187.  
  188. canAlert = false;
  189. onCoolDown.push(command);
  190. // ------------------------------- TIMER -------------DOWN------------------ // ------------------------------- TIMER -------------------------------
  191. setTimeout(function () {
  192. // onCoolDown = onCoolDown.filter(function(onCoolDown) { ------ this was deleted
  193. //return onCoolDown !== command}) ------ this was deleted
  194. // }, alertCoolDown); ------ this was deleted
  195.  
  196.  
  197.  
  198.  
  199.  
  200. // setTimeout(function () { ------ this was deleted
  201. canAlert = true;
  202. alertDuration = {alertDuration};
  203. aVolume = {alertVolume} * .01;
  204. }, alertDuration + 1000);
  205. }
  206.  
  207. });
  208.  
  209. // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ TIMER -------------UP------------------ // ------------------------------- TIMER -------------------------------
  210.  
  211. function playAudio(sound, alertD){
  212.  
  213. audio = new Audio(sound);
  214. audio.volume = aVolume;
  215. audio.play();
  216. setTimeout(function () {
  217. audio.pause();
  218. }, alertD);
  219. }
  220.  
  221. function showImage(imageSRC, alertD){
  222.  
  223. $('#img').attr('src',imageSRC).hide().fadeIn("slow");
  224. //$('#img').attr('src',imageSRC).hide().slideDown(1500);
  225. setTimeout(function () {
  226. $("#img").fadeOut("slow");
  227. }, alertD);
  228. }
  229. function stopVideo(){
  230. var video = document.getElementById("vid");
  231. var img = document.getElementById("img");
  232. $("#img").fadeOut("slow");
  233.  
  234. $("#vid").fadeTo("slow",0);
  235. $("#vid")[0].pause();
  236. audio.pause();
  237.  
  238. }
  239.  
  240. // ------------------------------- TIMER --------------DOWN----------------- // ------------------------------- TIMER -------------------------------
  241.  
  242. function startTimer(duration) {
  243. timerC = alertCoolDown;
  244. var minutes = 0;
  245. var seconds = 0;
  246.  
  247. /*
  248. var TimeOut = function () {
  249. minutes = parseInt(timerC / 60000, 10);
  250. seconds = parseInt((timerC % 60000) / 1000, 10);
  251.  
  252. minutes = minutes < 10 ? "0" + minutes : minutes;
  253. seconds = seconds < 10 ? "0" + seconds : seconds;
  254.  
  255. if (seconds > 100) {
  256. seconds = seconds < 100 ? "0" + seconds : seconds;
  257. };
  258.  
  259. function convert(minutes) { return 60 * minutes; };
  260.  
  261. display.innerHTML = seconds;
  262.  
  263.  
  264. timerC = timerC - 1000;
  265.  
  266. if (timerC < 0) {
  267. //timer = duration;
  268. $("#timer").fadeTo("slow",0);
  269. display.innerHTML = "00";
  270. IntervallId.forEach(element => clearInterval(element));
  271.  
  272. }
  273. };*/
  274.  
  275. var TimeOut = function () {
  276. seconds = parseInt(timerC / 1000, 10);
  277.  
  278. seconds = seconds < 10 ? "0" + seconds : seconds;
  279.  
  280. //display.innerHTML = seconds;
  281. $("#timer").html(seconds);
  282.  
  283.  
  284. timerC = timerC - 1000;
  285.  
  286. if (timerC < 0) {
  287. //timer = duration;
  288. $("#timer").fadeTo(1000,0, function(){ $("#timer").html(""); start_timer = true; clearInterval(IntervallId); }); // FADE OUT - END of the timer
  289. }
  290. };
  291.  
  292. //IntervallId.push(setInterval(TimeOut, 1000));
  293. if(IntervallId != null){
  294. clearInterval(IntervallId);
  295. }
  296. IntervallId = setInterval(TimeOut, 1000);
  297. }
  298.  
  299.  
  300.  
  301. /*
  302. function startTimer(duration, display) {
  303. timerC = duration;
  304. var minutes = 0;
  305. var seconds = 0;
  306.  
  307.  
  308. var TimeOut = function () {
  309. minutes = parseInt(timerC / 60000, 10);
  310. seconds = parseInt((timerC % 60000) / 1000, 10);
  311.  
  312. minutes = minutes < 10 ? "0" + minutes : minutes;
  313. seconds = seconds < 10 ? "0" + seconds : seconds;
  314.  
  315. display.innerHTML = minutes + ":" + seconds;
  316.  
  317. timerC = timerC - 1000;
  318.  
  319. if (timerC < 0) {
  320. //timer = duration;
  321. $("#timer").fadeTo("slow",0);
  322. display.innerHTML = "00:00";
  323. IntervallId.forEach(element => clearInterval(element));
  324.  
  325. }
  326. };
  327.  
  328. IntervallId.push(setInterval(TimeOut, 1000));
  329. }
  330.  
  331. */
  332.  
  333. // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ TIMER -------------UP------------------ // ------------------------------- TIMER -------------------------------
  334.  
  335.  
  336. // ------------------------------ TIMER --------------DOWN----------------- // ------------------------------- TIMER -------------------------------
  337.  
  338. function playVideo(videoSRC, duration, command){
  339. var vid = document.getElementById("vid");
  340. var cd = alertCoolDown;
  341. $('#vid').attr('src',videoSRC).hide().fadeIn("fast"); // SET - 0 - TO 'SLOW in "slow" ' for transition in the beninning
  342.  
  343. vid.volume = aVolume;
  344. vid.play();
  345.  
  346.  
  347. $("#vid").fadeTo("fast",1); // TRUE TRANSITION OR FALSE???? SET - 0 - TO 'SLOW' for transition in the beninning
  348. $('#vid').on('ended', function () {
  349.  
  350. $("#vid").fadeTo("slow",0, function(){
  351.  
  352. });
  353. if(start_timer){
  354. /*var to_show = cd/1000;
  355. if(to_show > 0){
  356. to_show = to_show < 10 ? "0" + to_show : to_show;
  357.  
  358. $("#timer").html(to_show);
  359. }*/
  360. $("#timer").fadeTo(2000, 1); // FADE IN - START of the timer
  361. start_timer = false;
  362. startTimer(cd);
  363. }
  364. $("#vid")[0].pause();
  365.  
  366. setTimeout(function () {
  367. onCoolDown = onCoolDown.filter(function(onCoolDown) {
  368. return onCoolDown !== command})
  369. }, cd);
  370.  
  371.  
  372.  
  373. });
  374.  
  375. }
  376.  
  377. // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ TIMER --------------UP----------------- // ------------------------------- TIMER -------------------------------
  378. /*
  379.  
  380. // ORIGINAL PLAY VIDEO
  381.  
  382. function playVideo(videoSRC){
  383. var vid = document.getElementById("vid");
  384. $('#vid').attr('src',videoSRC).hide().fadeIn("slow");
  385.  
  386. vid.volume = aVolume;
  387. vid.play();
  388.  
  389. $("#vid").fadeTo("slow",1);
  390. $('#vid').on('ended', function () {
  391. $("#vid").fadeTo("slow",0);
  392. $("#vid")[0].pause();
  393. });
  394.  
  395. }
  396.  
  397. */
  398.  
  399.  
  400.  
  401.  
  402.  
  403. var senderNameBlob = event["data"]["displayName"].toLowerCase();
  404. var commandBlob = event["data"]["text"].split(" ")[0].toLowerCase();
  405. var textBlob = "!speak'text'".replace('!speak','');
  406.  
  407. if(text="!speak")
  408. {
  409. displayText("haha");
  410. };
  411.  
  412. document.write("My message");
  413.  
  414.  
Advertisement
Add Comment
Please, Sign In to add comment