<commit_before>var jf = require('jsonfile');
var TelegramBot = require('node-telegram-bot-api');
var chalk = require('chalk');
var readline = require('readline');
var credentialsFilePath = './private/telegram_credentials.json';
var logger = require('./logger');
var weather = require('./weather');
var traffic = require('./traffic');
var feedback = require('./feedback');
var do_not_open = require('./do_not_open');
var broadcast = require('./broadcast');

var CREDENTIALS = jf.readFileSync(credentialsFilePath);
var bot = new TelegramBot(CREDENTIALS.token, {
    polling: true
});

console.log(chalk.blue("============================"));
console.log(chalk.blue("                            "));
console.log(chalk.blue("      CinnaBot Started      "));
console.log(chalk.blue("                            "));
console.log(chalk.blue("============================"));
console.log(chalk.blue("                            "));

var sessions = {};
var session;

// start CLI app
var rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout,
    terminal: false
});

rl.on('line', function(line) {
    parseCommand(line);
});

function parseCommand(command) {
    chatIds = [49892469, 102675141];
    switch (command) {
        case 'bcast':
            return broadcast.broadcast_input(chatIds, bot);
        case 'exit':
            return process.exit();
    }
}

// Any kind of message
bot.on('message', function(msg) {
    console.log(msg);
    var chatId = msg.chat.id;
    var msgId = msg.message_id;
    var body = msg.text;
    var command = body;
    var args = body;
    if (body.charAt(0) === '/') {
        command = body.split(' ')[0].substr(1);
        args = body.split(' ')[1];
    }
    // manage commands
    switch (command) {
        case "start":
            return help(chatId);
        case "help":
            return help(chatId);
        case "psi":
            return psi(chatId);
        case "bus":
            var busstop = args;
            return bus(msgId, chatId, busstop);
        case "feedback":
            session = sessions[chatId] || new Session(chatId);
            return ask_dining_feedback(chatId);
        case "cat":
            return catfact(chatId);
        case "cancel":
            return cancel(chatId);
    }

    // manage markups
    switch (body) {
        case 'I wanna go <NAME>':
            return bus(msgId, chatId, 19051);
        case 'I wanna go Clementi':
            return bus(msgId, chatId, 19059);
        default:
            session = sessions[chatId] || new Session(chatId);
            if (session.inThread.status) {
                return session.inThread.next(body, chatId);
            }
            return default_msg(chatId);
    }
});

function cancel(chatId) {
    session = new Session(chatId);
    bot.sendMessage(chatId, "Canceled.", {
        reply_markup: JSON.stringify({<commit_msg>Fix traffic response strings.<commit_after>var jf = require('jsonfile');
var TelegramBot = require('node-telegram-bot-api');
var chalk = require('chalk');
var readline = require('readline');
var credentialsFilePath = './private/telegram_credentials.json';
var logger = require('./logger');
var weather = require('./weather');
var traffic = require('./traffic');
var feedback = require('./feedback');
var do_not_open = require('./do_not_open');
var broadcast = require('./broadcast');

var CREDENTIALS = jf.readFileSync(credentialsFilePath);
var bot = new TelegramBot(CREDENTIALS.token, {
    polling: true
});

console.log(chalk.blue("============================"));
console.log(chalk.blue("                            "));
console.log(chalk.blue("      CinnaBot Started      "));
console.log(chalk.blue("                            "));
console.log(chalk.blue("============================"));
console.log(chalk.blue("                            "));

var sessions = {};
var session;

// start CLI app
var rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout,
    terminal: false
});

rl.on('line', function(line) {
    parseCommand(line);
});

function parseCommand(command) {
    chatIds = [49892469, 102675141];
    switch (command) {
        case 'bcast':
            return broadcast.broadcast_input(chatIds, bot);
        case 'exit':
            return process.exit();
    }
}

// Any kind of message
bot.on('message', function(msg) {
    console.log(msg);
    var chatId = msg.chat.id;
    var msgId = msg.message_id;
    var body = msg.text;
    var command = body;
    var args = body;
    if (body.charAt(0) === '/') {
        command = body.split(' ')[0].substr(1);
        args = body.split(' ')[1];
    }
    // manage commands
    switch (command) {
        case "start":
            return help(chatId);
        case "help":
            return help(chatId);
        case "psi":
            return psi(chatId);
        case "bus":
            var busstop = args;
            return bus(msgId, chatId, busstop);
        case "feedback":
            session = sessions[chatId] || new Session(chatId);
            return ask_dining_feedback(chatId);
        case "cat":
            return catfact(chatId);
        case "cancel":
            return cancel(chatId);
    }

    // manage markups
    switch (body) {
        case 'Towards <NAME>':
            return bus(msgId, chatId, 19051);
        case 'Towards Clementi':
            return bus(msgId, chatId, 19059);
        default:
            session = sessions[chatId] || new Session(chatId);
            if (session.inThread.status) {
                return session.inThread.next(body, chatId);
            }
            return default_msg(chatId);
    }
});

function cancel(chatId) {
    session = new Session(chatId);
    bot.sendMessage(chatId, "Canceled.", {
        reply_markup: JSON.stringify({
{'fraction_non_alphanumeric': 0.16051724137931034, 'fraction_numerical': 0.010689655172413793, 'mean_word_length': 2.3707147007553746, 'pattern_counts': {'":': 14, '<': 5, '<?xml version=': 0, '>': 5, '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': '1800416', 'n_tokens_mistral': 1750, 'n_tokens_neox': 1691, 'n_words': 398}