<commit_before>import os from 'os';
import { wit } from '../index';
import http from 'http';
import bodyParser from 'body-parser';

import models from '../../../app/models';

import { randomInt } from '../../lib/botResponses';
import { convertResponseObjectsToTaskArray, convertArrayToTaskListMessage, convertTimeStringToMinutes } from '../../lib/messageHelpers';

const FINISH_WORD = 'done';

// base controller for tasks
export default function(controller) {

	/**
	* 	START OF YOUR DAY
	*/

	controller.hears(['start_day'], 'direct_message', wit.hears, (bot, message) => {

		const SlackUserId = message.user;

		// find user then reply
		models.SlackUser.find({
			where: { SlackUserId },
			include: [
				models.User
			]
		})
		.then((slackUser) => {
			
			bot.send({
        type: "typing",
        channel: message.channel
	    });
	    setTimeout(()=>{
	    	bot.startConversation(message, (err, convo) => {
	    		var name = slackUser.User.nickName || slackUser.User.email;

	    		// configure necessary properties on convo object
	    		convo.name = name;

	    		// object with values that are important to me
	    		convo.dayStart = {
	    			UserId: slackUser.User.id
	    		};

	    		// start the flow
	    		askForDayTasks(err, convo);

	    		// on finish conversation
	    		convo.on('end', (convo) => {

    				var responses = convo.extractResponses();
    				console.log('done!')
    				console.log(responses);
    				console.log("here is day start object:");
    				console.log(convo.dayStart);

	    			// store the user's tasks
    				var { UserId, prioritizedTaskArray } = convo.dayStart;
    				prioritizedTaskArray.forEach((task, index) => {
    					const { text, minutes} = task;
    					var priority = index + 1;
    					models.Task.create({
    						text,
    						minutes,
    						priority,
    						UserId
    					});
    				});

	    			if (convo.status == 'completed') {
	    				bot.reply(message,"thx for finishing");

	    			} else {
	    				// if convo gets ended prematurely
	    				bot.reply(message, "Okay then, never mind!");
	    			}
	    		});

	    	});
	    }, randomInt(1000, 1750));
		});

	});

};

function askForDayTasks(response, convo){

	const { task }                = convo;
	const { bot, source_message } = task;

	console.log("in ask for day tasks");;
	console.log(convo.name);

	convo.say(`Hey ${convo.name}! What tasks would you like to work on today? :pencil:`);
	convo.say(`You can enter everything in one line separated by commas, or send me each task in a separate line`);

	convo.ask(`Then just tell me when you're done by saying \`${FINISH_WORD}\``, (response, convo) => {
		console.log("response is:");
		console.log(response);
		if (response.text == FINISH_WORD) {
			convo.say("Awesome! You can always add more tasks later by telling me, `I'd like to add a task` or something along those lines :grinning:");
			displayTaskList(response, convo);
			convo.next();
		}
	}, { 'key' : 'tasks', 'multiple': true});
<commit_msg>Quit early on START_DAY conversation flow<commit_after>import os from 'os';
import { wit } from '../index';
import http from 'http';
import bodyParser from 'body-parser';

import models from '../../../app/models';

import { randomInt } from '../../lib/botResponses';
import { convertResponseObjectsToTaskArray, convertArrayToTaskListMessage, convertTimeStringToMinutes } from '../../lib/messageHelpers';

const FINISH_WORD = 'done';
const EXIT_EARLY_WORDS = ['exit', 'stop','never mind','quit'];

// base controller for tasks
export default function(controller) {

	/**
	* 	START OF YOUR DAY
	*/

	controller.hears(['start_day'], 'direct_message', wit.hears, (bot, message) => {

		const SlackUserId = message.user;

		// find user then reply
		models.SlackUser.find({
			where: { SlackUserId },
			include: [
				models.User
			]
		})
		.then((slackUser) => {
			
			bot.send({
        type: "typing",
        channel: message.channel
	    });
	    setTimeout(()=>{
	    	bot.startConversation(message, (err, convo) => {
	    		var name = slackUser.User.nickName || slackUser.User.email;

	    		// configure necessary properties on convo object
	    		convo.name = name;

	    		// object with values that are important to me
	    		convo.dayStart = {
	    			UserId: slackUser.User.id
	    		};

	    		// start the flow
	    		askForDayTasks(err, convo);

	    		// on finish conversation
	    		convo.on('end', (convo) => {

    				var responses = convo.extractResponses();
    				console.log('done!')
    				console.log(responses);
    				console.log("here is day start object:");
    				console.log(convo.dayStart);

	    			if (convo.status == 'completed') {

	    				// store the user's tasks
	    				var { UserId, prioritizedTaskArray } = convo.dayStart;
	    				prioritizedTaskArray.forEach((task, index) => {
	    					const { text, minutes} = task;
	    					var priority = index + 1;
	    					models.Task.create({
	    						text,
	    						minutes,
	    						priority,
	    						UserId
	    					});
	    				});

	    				// confirm completion of DAY_START flow
	    				bot.reply(message,"thx for finishing");

	    			} else {
	    				// if convo gets ended prematurely
	    				bot.reply(message,"Okay! Exiting now. Let me know when you want to start your day");
	    			}
	    		});

	    	});
	    }, randomInt(1000, 1750));
		});

	});

};

function askForDayTasks(response, convo){

	const { task }                = convo;
	const { bot, source_message } = task;

	console.log("in ask for day tasks");;
	console.log(convo.name);

	convo.say(`Hey ${convo.name}! What tasks would you like to work on today? :pencil:`);
	convo.say(`You can enter everything in one line separated by commas, or send me each task in a separate line`);
	convo.ask(`Then just tell me when you're done by saying \`${FINISH_WORD}\``, (response, convo) => {

		for (var i = 0; i < EXIT_EARLY_WORDS.length; i++) {
			console.log(`in exit early words loop! ${EXIT_EARLY_WORDS[i]}`);
			if (response.text == EXIT_EARLY_WORDS[i])
				convo.stop();
		}

		console.log("response is:");
		console.log(response);
		if (response.text == FINISH_WORD) {
			convo.say("Awesome! You can always add more tasks later by telling me, `I'd like to add a task` or something along those lines :grinning:");
			displayTaskList(response, convo);
			convo.next();
		}
	}, { 'key' : 'tasks', 'multiple': true});

{'fraction_non_alphanumeric': 0.13931357254290172, 'fraction_numerical': 0.00296411856474259, 'mean_word_length': 2.5775669642857144, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6707697', 'n_tokens_mistral': 2389, 'n_tokens_neox': 2080, 'n_words': 544}