<commit_before>'use strict';
function arrayContainsObjectWithSameDescription( list, obj ){
    var i;
    for( i = 0; i < list.length; i = i + 1 ){
        if( obj.description === list[ i ].description ){
            return true;
        }
    }

    return false;
}

/*
function defaultFormatter( description ){
    return description;
}

function emptyFormatter( description ){
    return '';
}
*/

function EBFormatter( item ){
    var statusRegex = new RegExp( 'Status:(.+?)\<.+?', 'gim' ),
        sourceRegex = new RegExp( 'Source:.+?href="(.+?)"', 'gim' ),
        status = statusRegex.exec( item.description ),
        source = sourceRegex.exec( item.description ),
        extend = require( 'util' )._extend,
        returnObject = extend( {}, item );

    returnObject.formattedTitle = status[ 1 ].trim() + ' | ' + item.title;

    returnObject.formattedDescription = false;

    returnObject.formattedLink = source[ 1 ].trim();;

    return returnObject;
}

var feedparser = require( 'feedparser' ),
    request = require( 'request' ),
    rss = {
        bot : false,
        feeds : [
            {
                title: 'LIF Transfers',
                url: 'http://www.eliteprospects.com/rss_team.php?team=28',
                formatter: EBFormatter
            }
        ],
        setup : function( bot ){
            var _this = this;

            _this.bot = bot;

            _this.loadFeeds();
        },
        loadFeed : function( index ){
            var _this = this,
                currentRequest = request( this.feeds[ index ].url ),
                currentFeedParser = new feedparser(),
                printed = 0;

            currentRequest.on( 'error', function( error ){
                console.log( error );
            });

            currentRequest.on( 'response', function( response ){
                var stream = this;

                if( response.statusCode !== 200 ){
                    console.log( 'Bad status code' );
                }

                stream.pipe( currentFeedParser );
            });

            currentFeedParser.on( 'error', function( error ){
                console.log( error );
            });

            currentFeedParser.on( 'readable', function(){
                var stream = this,
                    item,
                    message,
                    formattedItem;

                if( typeof _this.feeds[ index ].items === 'undefined' ){
                    _this.feeds[ index ].items = [];
                }

                while( item = stream.read() ){

                    // Only print if we haven't seen the item before
                    if( arrayContainsObjectWithSameDescription( _this.feeds[ index ].items, item ) ){
                        console.log( 'Skipping' );
                        continue;
                    }

                    _this.feeds[ index ].items.push( item );

                    // Only print max one item per feed
                    if( printed <= 0 ){
                        formattedItem = _this.feeds[ index ].formatter( item );
                        message = '\u0002' + _this.feeds[ index ].title + '\u000F | ' + formattedItem.formattedTitle;

                        if( formattedItem.formattedDescription ){
                            message = message + '\n' + formattedItem.formattedDescription
                        }

                        if( formattedItem.formattedLink ){
                            message = message + '\n' + formattedItem.formattedLink;
                        }
<commit_msg>Fix codestyle<commit_after>'use strict';
function arrayContainsObjectWithSameDescription( list, obj ){
    var i;
    for( i = 0; i < list.length; i = i + 1 ){
        if( obj.description === list[ i ].description ){
            return true;
        }
    }

    return false;
}

/*
function defaultFormatter( description ){
    return description;
}

function emptyFormatter( description ){
    return '';
}
*/

function EBFormatter( item ){
    var statusRegex = new RegExp( 'Status:(.+?)\<.+?', 'gim' ),
        sourceRegex = new RegExp( 'Source:.+?href="(.+?)"', 'gim' ),
        status = statusRegex.exec( item.description ),
        source = sourceRegex.exec( item.description ),
        extend = require( 'util' )._extend,
        returnObject = extend( {}, item );

    returnObject.formattedTitle = status[ 1 ].trim() + ' | ' + item.title;

    returnObject.formattedDescription = false;

    returnObject.formattedLink = source[ 1 ].trim();

    return returnObject;
}

var feedparser = require( 'feedparser' ),
    request = require( 'request' ),
    rss = {
        bot : false,
        feeds : [
            {
                title: 'LIF Transfers',
                url: 'http://www.eliteprospects.com/rss_team.php?team=28',
                formatter: EBFormatter
            }
        ],
        setup : function( bot ){
            var _this = this;

            _this.bot = bot;

            _this.loadFeeds();
        },
        loadFeed : function( index ){
            var _this = this,
                currentRequest = request( this.feeds[ index ].url ),
                currentFeedParser = new feedparser(),
                printed = 0;

            currentRequest.on( 'error', function( error ){
                console.log( error );
            });

            currentRequest.on( 'response', function( response ){
                var stream = this;

                if( response.statusCode !== 200 ){
                    console.log( 'Bad status code' );
                }

                stream.pipe( currentFeedParser );
            });

            currentFeedParser.on( 'error', function( error ){
                console.log( error );
            });

            currentFeedParser.on( 'readable', function(){
                var stream = this,
                    item,
                    message,
                    formattedItem;

                if( typeof _this.feeds[ index ].items === 'undefined' ){
                    _this.feeds[ index ].items = [];
                }

                while( ( item = stream.read() ) !== null ){

                    // Only print if we haven't seen the item before
                    if( arrayContainsObjectWithSameDescription( _this.feeds[ index ].items, item ) ){
                        console.log( 'Skipping' );
                        continue;
                    }

                    _this.feeds[ index ].items.push( item );

                    // Only print max one item per feed
                    if( printed <= 0 ){
                        formattedItem = _this.feeds[ index ].formatter( item );
                        message = '\u0002' + _this.feeds[ index ].title + '\u000F | ' + formattedItem.formattedTitle;

                        if( formattedItem.formattedDescription ){
                            message = message + '\n' + formattedItem.formattedDescription;
                        }

                        if( formattedItem.formattedLink ){
                            message = message + '\n' + formattedItem.formattedLink;
                        }

{'fraction_non_alphanumeric': 0.11689407792938529, 'fraction_numerical': 0.00506400337600225, 'mean_word_length': 1.405277401894452, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '2678723', 'n_tokens_mistral': 1909, 'n_tokens_neox': 1736, 'n_words': 446}