Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function shuffle(array) {
- if(!Array.isArray(array) return; // don't even read the rest of code here
- for (let i = array.length - 1; i > 0; i--) {
- const j = Math.floor(Math.random() * (i + 1));
- [ array[ i ], array[ j ] ] = [ array[ j ], array[ i ] ];
- }
- // pick first item of shuffled array
- return array[ 0 ];
- let alertDuration = {alertDuration};
- alertCoolDown = {alertCooldown};
- stopCommand = "!stopalert";
- canAlert = true;
- aVolume = {alertVolume} * .01;
- audio = null;
- var onCoolDown =[];
- /*
- - Tutorials here: https://www.youtube.com/_zanzer (theres one on how to get images / video links)
- - You can have multiple images/videos and pick a random one for a command see !test-
- use "image" for any gifs/images; use "video" for a video
- 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 osf 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
- "!EXAMPLE": {
- "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": 6000, *set the length for that .mp4 or gif in ms*
- "volume": 50,
- "cooldown": 10000,
- "delaysound": 1000,
- "delayimage": 2000
- "sub": 0, // if you want the command to be subscriber only
- "mod": 0, // if you want the command to be mod / broadcaster only
- "user": ["megalewdslime", "Rory"],
- "sound": ["linke #1","link #2","link #3"],
- "video": ["linke #1","link #2","link #3"],
- "image": ["linke #1","link #2","link #3"], }, */
- alertCommands ={
- /* TEST */
- /* 01 */ "!pip1": { "cooldown": 0,
- "video": "https://cdn.discordapp.com/attachments/1198583469698195466/1198583497401573467/y2mate.is_-_MMDhololive_-wtH_gnF4LiU-720p-1705834951.mp4" },
- /* 02 */ "!pip2": { "cooldown": 0,
- "video": "https://cdn.discordapp.com/attachments/1198583469698195466/1198583777199390811/y2mate.is_-_Honkai_Star_Rail_MMD_4KTHE_METAL_SHEET_-_Seele_Bronya-mNZpS80ktXk-720p-1705835031.mp4" },
- /* END */
- };
- // ===============================================================================================================================================
- // ===============================================================================================================================================
- // ===============================================================================================================================================
- // ===============================================================================================================================================
- // ------------------------------- TIMER ------------------------------- // ------------------------------- TIMER -------------------------------
- var IntervallId = null;
- var timerC = 0;
- var start_timer = true;
- // ------------------------------- TIMER ------------------------------- // ------------------------------- TIMER -------------------------------
- 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 senderName = event["data"]["displayName"].toLowerCase();
- 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 === stopCommand && isMod)
- {
- stopVideo();
- }
- if(command in alertCommands && canAlert && onCoolDown.length <= 0){
- if('sub' in alertCommands[command] && !isSub)
- return;
- if('mod' in alertCommands[command] && !isMod)
- return;
- if('user' in alertCommands[command] && !alertCommands[command]["user"].includes(senderName))
- return;
- // ------------------------------- TIMER ------------------------------- // ------------------------------- TIMER -------------------------------
- timerC = 0;
- $("#timer").html("");
- if(IntervallId != null){
- $("#timer").fadeTo(1000,0); // NOT WORKING - SET THE DURATION OF THE FADE OUT FOR THE TIMER
- //IntervallId.forEach(element => clearInterval(element));
- //IntervallId.forEach(element => console.log(element));
- //clearInterval(IntervallId);
- }
- // ------------------------------- TIMER ------------------------------- // ------------------------------- TIMER -------------------------------
- alertCoolDown = {alertCooldown};
- if("volume" in alertCommands[command])
- aVolume = alertCommands[command]["volume"] * .01;
- if("cooldown" in alertCommands[command])
- alertCoolDown = alertCommands[command]["cooldown"];
- if("length" in alertCommands[command])
- alertDuration = alertCommands[command]["length"];
- if("sound" in alertCommands[command]){
- var playThis = alertCommands[command]["sound"];
- if(Array.isArray(playThis))
- playThis = playThis[Math.floor(Math.random() * playThis.length)];
- if("delaysound" in alertCommands[command]){
- setTimeout(function () {
- playAudio(playThis, alertDuration);
- }, alertCommands[command]['delaysound'] - alertCommands[command]['delaysound']);
- }
- else
- playAudio(playThis, alertDuration);
- }
- if("image" in alertCommands[command]){
- var showThis = alertCommands[command]["image"];
- if(Array.isArray(showThis))
- showThis = showThis[Math.floor(Math.random() * showThis.length)];
- if('delayimage' in alertCommands[command]){
- setTimeout(function () {
- showImage(showThis,alertDuration - alertCommands[command]['delayimage'] );
- }, alertCommands[command]['delayimage']);
- }
- else
- showImage(showThis,alertDuration );
- }
- if("video" in alertCommands[command]){
- // do stuff in here for video
- var showThis = alertCommands[command]["video"];
- };
- if(Array.isArray(showThis))
- showThis = shuffle(showThis);
- // ------------------------------- TIMER ------------------------------- // ------------------------------- TIMER -------------------------------
- // ADDED ---- , alertCoolDown, command); ---- TO THE LINE
- playVideo(showThis, alertCoolDown, command);
- // ------------------------------- TIMER ------------------------------- // ------------------------------- TIMER -------------------------------
- if("length" in alertCommands[command])
- alertDuration = alertCommands[command]["length"];
- if("sound" in alertCommands[command])
- if("delaysound" in alertCommands[command]){
- setTimeout(function () {
- playAudio(alertCommands[command]["sound"], alertDuration - alertCommands[command]['delaysound'] );
- }, alertCommands[command]['delaysound']);
- }
- else
- playAudio(alertCommands[command]["sound"], alertDuration);
- }
- canAlert = false;
- onCoolDown.push(command);
- // ------------------------------- TIMER -------------DOWN------------------ // ------------------------------- TIMER -------------------------------
- setTimeout(function () {
- // onCoolDown = onCoolDown.filter(function(onCoolDown) { ------ this was deleted
- //return onCoolDown !== command}) ------ this was deleted
- // }, alertCoolDown); ------ this was deleted
- // setTimeout(function () { ------ this was deleted
- canAlert = true;
- alertDuration = {alertDuration};
- aVolume = {alertVolume} * .01;
- }, alertDuration + 1000);
- }
- });
- // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ TIMER -------------UP------------------ // ------------------------------- TIMER -------------------------------
- function playAudio(sound, alertD){
- 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 stopVideo(){
- var video = document.getElementById("vid");
- var img = document.getElementById("img");
- $("#img").fadeOut("slow");
- $("#vid").fadeTo("slow",0);
- $("#vid")[0].pause();
- audio.pause();
- }
- // ------------------------------- TIMER --------------DOWN----------------- // ------------------------------- TIMER -------------------------------
- function startTimer(duration) {
- timerC = alertCoolDown;
- var minutes = 0;
- var seconds = 0;
- /*
- var TimeOut = function () {
- minutes = parseInt(timerC / 60000, 10);
- seconds = parseInt((timerC % 60000) / 1000, 10);
- minutes = minutes < 10 ? "0" + minutes : minutes;
- seconds = seconds < 10 ? "0" + seconds : seconds;
- if (seconds > 100) {
- seconds = seconds < 100 ? "0" + seconds : seconds;
- };
- function convert(minutes) { return 60 * minutes; };
- display.innerHTML = seconds;
- timerC = timerC - 1000;
- if (timerC < 0) {
- //timer = duration;
- $("#timer").fadeTo("slow",0);
- display.innerHTML = "00";
- IntervallId.forEach(element => clearInterval(element));
- }
- };*/
- var TimeOut = function () {
- seconds = parseInt(timerC / 1000, 10);
- seconds = seconds < 10 ? "0" + seconds : seconds;
- //display.innerHTML = seconds;
- $("#timer").html(seconds);
- timerC = timerC - 1000;
- if (timerC < 0) {
- //timer = duration;
- $("#timer").fadeTo(1000,0, function(){ $("#timer").html(""); start_timer = true; clearInterval(IntervallId); }); // FADE OUT - END of the timer
- }
- };
- //IntervallId.push(setInterval(TimeOut, 1000));
- if(IntervallId != null){
- clearInterval(IntervallId);
- }
- IntervallId = setInterval(TimeOut, 1000);
- }
- /*
- function startTimer(duration, display) {
- timerC = duration;
- var minutes = 0;
- var seconds = 0;
- var TimeOut = function () {
- minutes = parseInt(timerC / 60000, 10);
- seconds = parseInt((timerC % 60000) / 1000, 10);
- minutes = minutes < 10 ? "0" + minutes : minutes;
- seconds = seconds < 10 ? "0" + seconds : seconds;
- display.innerHTML = minutes + ":" + seconds;
- timerC = timerC - 1000;
- if (timerC < 0) {
- //timer = duration;
- $("#timer").fadeTo("slow",0);
- display.innerHTML = "00:00";
- IntervallId.forEach(element => clearInterval(element));
- }
- };
- IntervallId.push(setInterval(TimeOut, 1000));
- }
- */
- // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ TIMER -------------UP------------------ // ------------------------------- TIMER -------------------------------
- // ------------------------------ TIMER --------------DOWN----------------- // ------------------------------- TIMER -------------------------------
- function playVideo(videoSRC, duration, command){
- var vid = document.getElementById("vid");
- var cd = alertCoolDown;
- $('#vid').attr('src',videoSRC).hide().fadeIn("fast"); // SET - 0 - TO 'SLOW in "slow" ' for transition in the beninning
- vid.volume = aVolume;
- vid.play();
- $("#vid").fadeTo("fast",1); // TRUE TRANSITION OR FALSE???? SET - 0 - TO 'SLOW' for transition in the beninning
- $('#vid').on('ended', function () {
- $("#vid").fadeTo("slow",0, function(){
- });
- if(start_timer){
- /*var to_show = cd/1000;
- if(to_show > 0){
- to_show = to_show < 10 ? "0" + to_show : to_show;
- $("#timer").html(to_show);
- }*/
- $("#timer").fadeTo(2000, 1); // FADE IN - START of the timer
- start_timer = false;
- startTimer(cd);
- }
- $("#vid")[0].pause();
- setTimeout(function () {
- onCoolDown = onCoolDown.filter(function(onCoolDown) {
- return onCoolDown !== command})
- }, cd);
- });
- }
- // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ TIMER --------------UP----------------- // ------------------------------- TIMER -------------------------------
- /*
- // ORIGINAL PLAY VIDEO
- 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();
- });
- }
- */
- var senderNameBlob = event["data"]["displayName"].toLowerCase();
- var commandBlob = event["data"]["text"].split(" ")[0].toLowerCase();
- var textBlob = "!speak'text'".replace('!speak','');
- if(text="!speak")
- {
- displayText("haha");
- };
- document.write("My message");
Advertisement
Add Comment
Please, Sign In to add comment