function buildEmojiRotator(detail, i = 0) { //emojiRotator module builder, called on widgetload
  return new Promise((res, rej) => { //return promise; verify that user added at least 1 reward;
    const verifyRewards = () => { //function to check amount of rewards
      const amountLoaded = Object.keys(eventTriggers).length;
      if (amountLoaded > 0) res(`${amountLoaded} Emoji Rotator Rewards Loaded`); //if 1 or more reward, resolve
      else rej('No Rewards Are Filled In'); //if no rewards then reject and prevent websocket connection
    }

    formatFieldData(detail); //call function below

    function formatFieldData(detail, i = 0) { //function to loop and build master Object
      i++; //reward and loop counter
      if (i > 11) return verifyRewards(); //get reward info; field data locked to 5 only, but headroom for users that try to sneek in more
      const fieldData = detail.fieldData; //field data passed from widgetLoad
      const rewardText = fieldData[`reward${i}_rewardText`];

      if (!rewardText) return formatFieldData(detail, i) //skip empty segments
      else if (eventTriggers[rewardText]) { //check if a duplicate
        widget.info(`${rewardText} is a duplicate, reward #${i} skipped`, true); //send message to info panel
        return formatFieldData(detail, i); //skip duplicates
      };

      const rewardObject = { //build Object that 'emojiRotator' is looking for
        index: i,
        name: rewardText, //reward name
        inputString: fieldData[`reward${i}_emojis`] || '', //get user input, set to empty if nothing. Error handling done in emojiRotator.verify()
        duration: fieldData[`reward${i}_duration`],
        speed: fieldData[`reward${i}_speed`],
        audio: fieldData[`reward${i}_audio`],
        audioDelay: fieldData[`reward${i}_audioDelay`],
        volume: fieldData[`reward${i}_audioVolume`],
        chatMsg: fieldData[`reward${i}_chatMsg`],
        chatMsgDelay: fieldData[`reward${i}_chatMsgDelay`],
      };
      const reward = new emojiRotator(rewardObject); //build new "reward"
      reward.verify().then(() => { //verify the reward has valid inputs; see emojiRotator.verify();
          eventTriggers[rewardText] = reward; //if it is ok; then add the reward Object to eventTriggers with the Key name of the reward text
          widget.info(`${rewardText} Added`, false); //send success message to be put into info panel
          if (rewardObject.chatMsg) widget.loadJebaited(fieldData[`jebaitedAPIToken`]); //if there is a msg input from the user, then load Jebaited. Instance handling done in loadJebaited()
          if (widget.isEditorMode && fieldData[`reward${i}_showOnLoad`]) eventTriggers[rewardText].run(); //show example on load/change if setting enabled
        }).catch(e => widget.info(`Could not load reward: ${rewardText}: ${e}`, true, true)) //catch and log reward error. [x] maybe: add visual for this?
        .finally(_ => formatFieldData(detail, i)); //loop
    };
  });
}
//emojiRotator Module loader. Build the event triggers
emojiRotator Module loader. Build the event triggers
emojiRotator Module loader . Build the event triggers
function buildEmojiRotator(detail, i = 0) { 
  return new Promise((res, rej) => { 
    const verifyRewards = () => { 
      const amountLoaded = Object.keys(eventTriggers).length;
      if (amountLoaded > 0) res(`${amountLoaded} Emoji Rotator Rewards Loaded`); 
      else rej('No Rewards Are Filled In'); 
    }
    formatFieldData(detail); 
    function formatFieldData(detail, i = 0) { 
      i++; 
      if (i > 11) return verifyRewards(); 
      const fieldData = detail.fieldData; 
      const rewardText = fieldData[`reward${i}_rewardText`];
      if (!rewardText) return formatFieldData(detail, i) 
      else if (eventTriggers[rewardText]) { 
        widget.info(`${rewardText} is a duplicate, reward #${i} skipped`, true); 
        return formatFieldData(detail, i); 
      };
      const rewardObject = { 
        index: i,
        name: rewardText, 
        inputString: fieldData[`reward${i}_emojis`] || '', 
        duration: fieldData[`reward${i}_duration`],
        speed: fieldData[`reward${i}_speed`],
        audio: fieldData[`reward${i}_audio`],
        audioDelay: fieldData[`reward${i}_audioDelay`],
        volume: fieldData[`reward${i}_audioVolume`],
        chatMsg: fieldData[`reward${i}_chatMsg`],
        chatMsgDelay: fieldData[`reward${i}_chatMsgDelay`],
      };
      const reward = new emojiRotator(rewardObject); 
      reward.verify().then(() => { 
          eventTriggers[rewardText] = reward; 
          widget.info(`${rewardText} Added`, false); 
          if (rewardObject.chatMsg) widget.loadJebaited(fieldData[`jebaitedAPIToken`]); 
          if (widget.isEditorMode && fieldData[`reward${i}_showOnLoad`]) eventTriggers[rewardText].run(); 
        }).catch(e => widget.info(`Could not load reward: ${rewardText}: ${e}`, true, true)) 
        .finally(_ => formatFieldData(detail, i)); 
    };
  });
}
function buildEmojiRotator ( detail , i = 0 ) { return new Promise ( ( res , rej ) => { const verifyRewards = ( ) => { const amountLoaded = Object . keys ( eventTriggers ) . length ; if ( amountLoaded > 0 ) res ( ` ${ amountLoaded } ` ) ; else rej ( 'No Rewards Are Filled In' ) ; } formatFieldData ( detail ) ; function formatFieldData ( detail , i = 0 ) { i ++ ; if ( i > 11 ) return verifyRewards ( ) ; const fieldData = detail . fieldData ; const rewardText = fieldData [ ` ${ i } ` ] ; if ( ! rewardText ) return formatFieldData ( detail , i ) else if ( eventTriggers [ rewardText ] ) { widget . info ( ` ${ rewardText } ${ i } ` , true ) ; return formatFieldData ( detail , i ) ; } ; const rewardObject = { index : i , name : rewardText , inputString : fieldData [ ` ${ i } ` ] || '' , duration : fieldData [ ` ${ i } ` ] , speed : fieldData [ ` ${ i } ` ] , audio : fieldData [ ` ${ i } ` ] , audioDelay : fieldData [ ` ${ i } ` ] , volume : fieldData [ ` ${ i } ` ] , chatMsg : fieldData [ ` ${ i } ` ] , chatMsgDelay : fieldData [ ` ${ i } ` ] , } ; const reward = new emojiRotator ( rewardObject ) ; reward . verify ( ) . then ( ( ) => { eventTriggers [ rewardText ] = reward ; widget . info ( ` ${ rewardText } ` , false ) ; if ( rewardObject . chatMsg ) widget . loadJebaited ( fieldData [ ` ` ] ) ; if ( widget . isEditorMode && fieldData [ ` ${ i } ` ] ) eventTriggers [ rewardText ] . run ( ) ; } ) . catch ( e => widget . info ( ` ${ rewardText } ${ e } ` , true , true ) ) . finally ( _ => formatFieldData ( detail , i ) ) ; } ; } ) ; }
emojiRotator Module loader.
emojiRotator Module loader .
//emojiRotator module builder, called on widgetload //return promise; verify that user added at least 1 reward; //function to check amount of rewards //if 1 or more reward, resolve //if no rewards then reject and prevent websocket connection //call function below //function to loop and build master Object //reward and loop counter //get reward info; field data locked to 5 only, but headroom for users that try to sneek in more //field data passed from widgetLoad //skip empty segments //check if a duplicate //send message to info panel //skip duplicates //build Object that 'emojiRotator' is looking for //reward name //get user input, set to empty if nothing. Error handling done in emojiRotator.verify() //build new "reward" //verify the reward has valid inputs; see emojiRotator.verify(); //if it is ok; then add the reward Object to eventTriggers with the Key name of the reward text //send success message to be put into info panel //if there is a msg input from the user, then load Jebaited. Instance handling done in loadJebaited() //show example on load/change if setting enabled //catch and log reward error. [x] maybe: add visual for this? //loop