<commit_before>'use strict';

let TelegramBot = require('node-telegram-bot-api');
let request = require('request-promise');

let TelegramBotToken = process.env.TELEGRAM_BOT_TOKEN;
let telegramBot = new TelegramBot(TelegramBotToken, { polling: true });

let registeredUsers = [], previousTopStories = [];

function getTopStory(){
    return request('https://hacker-news.firebaseio.com/v0/topstories.json').then(data => 
        request('https://hacker-news.firebaseio.com/v0/item/' + JSON.parse(data)[0] + '.json?print=pretty')
    );
};

function pushTopStory(story){
    registeredUsers.forEach(user => telegramBot.sendMessage(user, story.title + ' - ' + story.url));
    currentTopStory = story.id;
}

setInterval(() => {
     getTopStory().then(data => {
        data = JSON.parse(data);

        if(!previousTopStories.includes(data.id)){
            pushTopStory(data);
            previousTopStories.push(msg.from.id);
        }
     });
}, 10000);

telegramBot.onText(/\/start/, msg => {
    registeredUsers.push(msg.from.id);
    telegramBot.sendMessage(msg.from.id, 'Thanks, you\'re now registered, you\'ll get a message when the top story changes!');
});<commit_msg>Fix logic bug<commit_after>'use strict';

let TelegramBot = require('node-telegram-bot-api');
let request = require('request-promise');

let TelegramBotToken = process.env.TELEGRAM_BOT_TOKEN;
let telegramBot = new TelegramBot(TelegramBotToken, { polling: true });

let registeredUsers = [], previousTopStories = [];

function getTopStory(){
    return request('https://hacker-news.firebaseio.com/v0/topstories.json').then(data => 
        request('https://hacker-news.firebaseio.com/v0/item/' + JSON.parse(data)[0] + '.json?print=pretty')
    );
};

function pushTopStory(story){
    registeredUsers.forEach(user => telegramBot.sendMessage(user, story.title + ' - ' + story.url));
    currentTopStory = story.id;
}

setInterval(() => {
     getTopStory().then(data => {
        data = JSON.parse(data);

        if(previousTopStories.includes(data.id)){
            pushTopStory(data);
            previousTopStories.push(msg.from.id);
        }
     });
}, 10000);

telegramBot.onText(/\/start/, msg => {
    registeredUsers.push(msg.from.id);
    telegramBot.sendMessage(msg.from.id, 'Thanks, you\'re now registered, you\'ll get a message when the top story changes!');
});
{'fraction_non_alphanumeric': 0.16376010208421948, 'fraction_numerical': 0.006805614632071459, 'mean_word_length': 3.8098159509202456, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, 'https://': 4, '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': '540976', 'n_tokens_mistral': 777, 'n_tokens_neox': 748, 'n_words': 122}