Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const maxWaitingTimeNoMsg = 10000;
- const maxWaitingTimeNoResponse = 20000;
- // PROCESS STATISTICS
- // Start from minus one, simplest way to use current flow
- let numberConvos = -1;
- let secsRunning = 0;
- let botsFound = 0;
- let malesIdentified = 0;
- // Conversation ongoing is firing when searching - not ongoing.
- // CURRENT DATA
- let currentConvoDuration = 0;
- let currentConvoEvents = [];
- let lastMessage = null;
- // Javascript only log something once no matter how many times it's called in a loop
- // WEBSITE DATA PARSING + INTERACTION
- const getMessages = () => document.querySelectorAll('.strangermsg');
- const getFirstMessage = () => {
- const first = getMessages()[0] || null;
- return first;
- };
- const getLastMessage = () => {
- const last = getMessages()[getMessages().length - 1] || null;
- return last;
- };
- const getFirstMessageText = () => {
- const first = getFirstMessage();
- return getMessageText(first);
- }
- const getMessageText = (message) => {
- let text = (message !== null) ? message.innerText : ''; // .slice()
- return text;
- }
- const isConversationOngoing = () => {
- // Not ongoing if Connecting.
- const logText = document.querySelector('.statuslog').innerText;
- return getDscButtonText() === 'Stop';
- };
- const startNewConversation = (reason = '?') => {
- // Update statistics.
- numberConvos++;
- // Reset data.
- currentConvoEvents = [];
- currentConvoDuration = 0;
- // Start new conversation by clicking button twice.
- getDscButton().click();
- getDscButton().click();
- console.log(`START_NEW: (Reason: ${reason})`)
- // Trigger onStart hooks.
- onConversationStart();
- }
- const getDscButton = () => document.querySelector('.disconnectbtn');
- const getDscButtonText = () => {
- return getDscButton().innerText.slice(0, 4);
- };
- // ACTIONS + INTERACTION
- const writeIntrodution = () => {
- // Add line breaks
- const introductionText = `Hi! I'm automated.\n
- # CONVOS: ${numberConvos} | # Secs Running: ${secsRunning / 1000}
- `;
- // Trigger keyboardpress event to trigger typing notification / look real.
- document.querySelector('.chatmsg').value = introductionText;
- // Could write an itnerval to confirm message is added.
- setTimeout(() => { document.querySelector('.sendbtn').click() }, 2000);
- };
- // LOGGING & DEVELOPER RELATED.
- // Limit logging to every five seconds in a loop running every second.
- const shouldLog = () => (currentConvoDuration % 5000 === 0);
- const condLog = (cond, log) => { if (cond) console.log(log); }
- const runAtSecond = (secTarget, action) => {
- if (currentConvoDuration >= secTarget) action();
- }
- const logStats = () => {
- if (shouldLog('ONGOING')) {
- console.log(`ONGOING | Age: ${currentConvoDuration} | HasMsg: ${!!getFirstMessage()} | TOTAL: ${numberConvos}`);
- }
- }
- // APPLICATION FUNCTIONALITY
- const conversationStateTracker = setInterval(() => {
- if (!isConversationOngoing() && currentConvoDuration > 0) {
- console.log('Conversation ended.');
- startNewConversation();
- }
- // Check if a new conversation is required.
- if (!isConversationOngoing()) {
- console.log(`NON-ONGOING | Age: ${currentConvoDuration}`);
- } else {
- // Process ongoing conversation.
- ongoingConversationHandler();
- }
- secsRunning = secsRunning + 1000;
- currentConvoDuration = currentConvoDuration + 1000;
- }, 1000);
- const filterByIntroduction = () => {
- // RUSHED CONVERSATION INTRODUCTION - BOT OR CRAZY/HORNY PERSON
- if (currentConvoDuration < 3000 && currentConvoDuration >= 2000) {
- condLog(getFirstMessage(), 'FIRST_MESSAGE: ' + getFirstMessageText());
- }
- // Run a test on first incoming message regardless of when it occurs.
- // Stranger: | You've come upon a chat room.
- // Filter by firstMessage contains a link.
- const latestMessage = getLastMessage()
- // console.log()
- if (!lastMessage && latestMessage) {
- // If first message is within filter array startNewConversation
- const filterPatterns = [
- 'M<NUMBER>',
- 'M',
- 'M <NUMBER>'
- ];
- // Stranger: Asl?
- // If message passes filter, set lastMessage
- }
- }
- /**
- ongoingConversationHandler
- Execution order:
- 1. Log statistics.
- 2. Eliminate based on introduction
- Sets the first message after analysing it.
- 3. Optimisation
- */
- const ongoingConversationHandler = () => {
- // 1. Log Statistics
- logStats();
- // 2. Eliminate based on introduction.
- if (currentConvoDuration < maxWaitingTimeNoMsg / 2) filterByIntroduction();
- // 3. Post filtering stage.
- if (currentConvoDuration > maxWaitingTimeNoMsg) {
- // NO MESSAGE PAST WAITING TIME.
- if (!getFirstMessage()) startNewConversation('NO MESSAGE AFTER MAX WAITING TIME - RESTARTING.');
- }
- }
- // EXECUTION:
- // Check if existing conversation or new required.
- const onConversationStart = () => {
- // Refactor and add accurary to detection.
- console.log('CONVERSATION_STARTED');
- writeIntrodution();
- }
- // Run
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement