Advertisement
Guest User

Untitled

a guest
Jan 26th, 2020
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const maxWaitingTimeNoMsg = 10000;
  2. const maxWaitingTimeNoResponse = 20000;
  3.  
  4.  
  5. // PROCESS STATISTICS
  6. // Start from minus one, simplest way to use current flow
  7. let numberConvos = -1;
  8. let secsRunning = 0;
  9. let botsFound = 0;
  10. let malesIdentified = 0;
  11.  
  12.  
  13. // Conversation ongoing is firing when searching - not ongoing.
  14.  
  15.  
  16. // CURRENT DATA
  17. let currentConvoDuration = 0;
  18. let currentConvoEvents = [];
  19. let lastMessage = null;
  20.  
  21.  
  22.  
  23.  
  24. // Javascript only log something once no matter how many times it's called in a loop
  25.  
  26.  
  27. // WEBSITE DATA PARSING + INTERACTION
  28.   const getMessages = () => document.querySelectorAll('.strangermsg');
  29.   const getFirstMessage = () => {
  30.     const first = getMessages()[0] || null;
  31.     return first;
  32.   };
  33.   const getLastMessage = () => {
  34.     const last = getMessages()[getMessages().length - 1] || null;
  35.     return last;
  36.   };
  37.   const getFirstMessageText = () => {
  38.     const first = getFirstMessage();
  39.     return getMessageText(first);
  40.   }
  41.   const getMessageText = (message) => {
  42.     let text = (message !== null) ? message.innerText : ''; // .slice()
  43.     return text;
  44.   }
  45.   const isConversationOngoing = () => {
  46.  
  47.     // Not ongoing if Connecting.
  48.     const logText = document.querySelector('.statuslog').innerText;
  49.  
  50.     return getDscButtonText() === 'Stop';
  51.   };
  52.  
  53.   const startNewConversation = (reason = '?') => {
  54.     // Update statistics.
  55.     numberConvos++;
  56.  
  57.     // Reset data.
  58.     currentConvoEvents = [];
  59.     currentConvoDuration = 0;
  60.  
  61.     // Start new conversation by clicking button twice.
  62.     getDscButton().click();
  63.     getDscButton().click();
  64.  
  65.     console.log(`START_NEW: (Reason: ${reason})`)
  66.  
  67.     // Trigger onStart hooks.
  68.     onConversationStart();
  69.   }
  70.   const getDscButton = () => document.querySelector('.disconnectbtn');
  71.   const getDscButtonText = () => {
  72.     return getDscButton().innerText.slice(0, 4);
  73.   };
  74.  
  75. // ACTIONS + INTERACTION
  76.   const writeIntrodution = () => {
  77.     // Add line breaks
  78.     const introductionText = `Hi! I'm automated.\n
  79.      # CONVOS: ${numberConvos} | # Secs Running: ${secsRunning / 1000}
  80.    `;
  81.    // Trigger keyboardpress event to trigger typing notification / look real.
  82.    document.querySelector('.chatmsg').value = introductionText;
  83.  
  84.    // Could write an itnerval to confirm message is added.
  85.    setTimeout(() => { document.querySelector('.sendbtn').click() }, 2000);
  86.  };
  87.  
  88.  
  89. // LOGGING & DEVELOPER RELATED.
  90.  
  91.  // Limit logging to every five seconds in a loop running every second.
  92.  const shouldLog = () => (currentConvoDuration % 5000 === 0);
  93.  
  94.  const condLog = (cond, log) => { if (cond) console.log(log); }
  95.  
  96.  const runAtSecond = (secTarget, action) => {
  97.    if (currentConvoDuration >= secTarget) action();
  98.  }
  99.  
  100.  const logStats = () => {
  101.    if (shouldLog('ONGOING')) {
  102.      console.log(`ONGOING | Age: ${currentConvoDuration} | HasMsg: ${!!getFirstMessage()} | TOTAL: ${numberConvos}`);
  103.    }
  104.  }
  105.  
  106.  
  107.  
  108. // APPLICATION FUNCTIONALITY
  109.  
  110.  const conversationStateTracker = setInterval(() => {
  111.  
  112.    if (!isConversationOngoing() && currentConvoDuration > 0) {
  113.      console.log('Conversation ended.');
  114.      startNewConversation();
  115.    }
  116.  
  117.    // Check if a new conversation is required.
  118.    if (!isConversationOngoing()) {
  119.      console.log(`NON-ONGOING | Age: ${currentConvoDuration}`);
  120.  
  121.  
  122.    } else {
  123.      // Process ongoing conversation.
  124.      ongoingConversationHandler();
  125.    }
  126.  
  127.    secsRunning = secsRunning + 1000;
  128.    currentConvoDuration = currentConvoDuration + 1000;
  129.  }, 1000);
  130.  
  131.  const filterByIntroduction = () => {
  132.    // RUSHED CONVERSATION INTRODUCTION - BOT OR CRAZY/HORNY PERSON
  133.    if (currentConvoDuration < 3000 && currentConvoDuration >= 2000) {
  134.      condLog(getFirstMessage(), 'FIRST_MESSAGE: ' + getFirstMessageText());
  135.    }
  136.  
  137.    // Run a test on first incoming message regardless of when it occurs.
  138.    // Stranger: | You've come upon a chat room.
  139.  
  140.  
  141.     // Filter by firstMessage contains a link.
  142.  
  143.     const latestMessage = getLastMessage()
  144.     // console.log()
  145.     if (!lastMessage && latestMessage) {
  146.       // If first message is within filter array startNewConversation
  147.       const filterPatterns = [
  148.           'M<NUMBER>',
  149.           'M',
  150.           'M <NUMBER>'
  151.       ];
  152.       // Stranger: Asl?
  153.  
  154.  
  155.       // If message passes filter, set lastMessage
  156.     }
  157.  
  158.  
  159.   }
  160.  
  161.   /**
  162.     ongoingConversationHandler
  163.  
  164.     Execution order:
  165.       1. Log statistics.
  166.       2. Eliminate based on introduction
  167.         Sets the first message after analysing it.
  168.       3. Optimisation
  169.  
  170.   */
  171.   const ongoingConversationHandler = () => {
  172.  
  173.     // 1. Log Statistics
  174.       logStats();
  175.  
  176.  
  177.     // 2. Eliminate based on introduction.
  178.     if (currentConvoDuration < maxWaitingTimeNoMsg / 2) filterByIntroduction();
  179.  
  180.  
  181.     // 3. Post filtering stage.
  182.     if (currentConvoDuration > maxWaitingTimeNoMsg) {
  183.  
  184.       // NO MESSAGE PAST WAITING TIME.
  185.       if (!getFirstMessage()) startNewConversation('NO MESSAGE AFTER MAX WAITING TIME - RESTARTING.');
  186.     }
  187.  
  188.   }
  189.  
  190.  
  191.  
  192.  
  193. // EXECUTION:
  194.   // Check if existing conversation or new required.
  195.   const onConversationStart = () => {
  196.     // Refactor and add accurary to detection.
  197.     console.log('CONVERSATION_STARTED');
  198.     writeIntrodution();
  199.   }
  200.  
  201.   // Run
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement