<commit_before>/**
 * @file Handle a report
 * @author <NAME>
 */

/**
 * @summary Handle a report
 * @param {Object} args report arguments
 * @constructor
 * @description Reports just handle the actual report thread itself.
 * Actions stemming from the report are handled elsewhere.
 *
 * @example
 * var report = new Report({
 *     v: variables,
 *     bb: bulletin_board,
 *     thread_id: 123,
 *     title: 'Reported post by <name> [TID: 456] [PID: 7890] [ASSIGNED: J. Random Moderator]'
 * });
 */

function Report(args) {

    if ( args.title ) {
        args.title.replace(     /\[PID: ([0-9]+)\]/, function(match, pid ) { args.target_post_id   = pid });
        args.title.replace(     /\[TID: ([0-9]+)\]/, function(match, tid ) { args.target_thread_id = tid });
        args.title.replace( /\[ASSIGNED: ([^)]+)\]/, function(match, name) { args.assigned         = name });
    }

    this.v  = args.v;
    this.bb = args.bb;

    this.title            = args.title;
    this.thread_id        = args.thread_id;
    this.target_thread_id = args.target_thread_id;
    this.target_post_id   = args.target_post_id;
    this.assigned         = args.assigned;

}

Report.prototype.constructor = Report;
Report.prototype = Object.create(Object, {

    v : { writable: true, configurable: false },
    bb: { writable: true, configurable: false },

    thread_id       : { writable: true, configurable: false },
    target_thread_id: { writable: true, configurable: false },
    target_post_id  : { writable: true, configurable: false },
    assigned        : { writable: true, configurable: false }

});

/*
 * @summary Take a report thread
 * @param {string}   name          name of the moderator who will take the thread
 * @param {boolean=} thread_closed whether to open or close the thread
 *
 * This will load the thread in the current page after taking it.
 */
Report.prototype.take = function( name, thread_closed ) {

    var report = this;
    var expected_title_suffix = report.v.resolve('report process', 'report title suffix', { moderator: name });
    var new_title = this.title.replace(
        new RegExp(
            report.v.resolve('report process', 'report title suffix', { moderator: "\uE000" })
             .replace(/([.*+?^${}()|\[\]\/\\])/g, "\\$1") // escape special characters: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions
             .replace( "\uE000", '.*?' )
             + '$'
        )
    ) + expected_title_suffix;

    report.bb.thread_edit({
        thread_id: report.thread_id,
        title: new_title,
        notes: 'thread taken by ' + name,
        close_thread: thread_closed
    }).then(function() {
        report.bb.thread_reply({
            thread_id: report.thread_id,
            title    : report.v.resolve('report process', 'post title: take report', {}, 'string', undefined, report.thread_id ),
            bbcode   : report.v.resolve('report process', 'post body: take report' , {}, 'string', undefined, report.thread_id ),
            url      : report.bb.url_for.thread_show({ thread_id: report.thread_id, goto: 'newpost' }),
            flip_thread_openness: false
        });
    });

}
<commit_msg>convert target post/thread ID to integer in report.js<commit_after>/**
 * @file Handle a report
 * @author <NAME>
 */

/**
 * @summary Handle a report
 * @param {Object} args report arguments
 * @constructor
 * @description Reports just handle the actual report thread itself.
 * Actions stemming from the report are handled elsewhere.
 *
 * @example
 * var report = new Report({
 *     v: variables,
 *     bb: bulletin_board,
 *     thread_id: 123,
 *     title: 'Reported post by <name> [TID: 456] [PID: 7890] [ASSIGNED: <NAME>erator]'
 * });
 */

function Report(args) {

    if ( args.title ) {
        args.title.replace(     /\[PID: ([0-9]+)\]/, function(match, pid ) { args.target_post_id   = parseInt( pid, 10 ) });
        args.title.replace(     /\[TID: ([0-9]+)\]/, function(match, tid ) { args.target_thread_id = parseInt( tid, 10 ) });
        args.title.replace( /\[ASSIGNED: ([^)]+)\]/, function(match, name) { args.assigned         = name });
    }

    this.v  = args.v;
    this.bb = args.bb;

    this.title            = args.title;
    this.thread_id        = args.thread_id;
    this.target_thread_id = args.target_thread_id;
    this.target_post_id   = args.target_post_id;
    this.assigned         = args.assigned;

}

Report.prototype.constructor = Report;
Report.prototype = Object.create(Object, {

    v : { writable: true, configurable: false },
    bb: { writable: true, configurable: false },

    thread_id       : { writable: true, configurable: false },
    target_thread_id: { writable: true, configurable: false },
    target_post_id  : { writable: true, configurable: false },
    assigned        : { writable: true, configurable: false }

});

/*
 * @summary Take a report thread
 * @param {string}   name          name of the moderator who will take the thread
 * @param {boolean=} thread_closed whether to open or close the thread
 *
 * This will load the thread in the current page after taking it.
 */
Report.prototype.take = function( name, thread_closed ) {

    var report = this;
    var expected_title_suffix = report.v.resolve('report process', 'report title suffix', { moderator: name });
    var new_title = this.title.replace(
        new RegExp(
            report.v.resolve('report process', 'report title suffix', { moderator: "\uE000" })
             .replace(/([.*+?^${}()|\[\]\/\\])/g, "\\$1") // escape special characters: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions
             .replace( "\uE000", '.*?' )
             + '$'
        )
    ) + expected_title_suffix;

    report.bb.thread_edit({
        thread_id: report.thread_id,
        title: new_title,
        notes: 'thread taken by ' + name,
        close_thread: thread_closed
    }).then(function() {
        report.bb.thread_reply({
            thread_id: report.thread_id,
            title    : report.v.resolve('report process', 'post title: take report', {}, 'string', undefined, report.thread_id ),
            bbcode   : report.v.resolve('report process', 'post body: take report' , {}, 'string', undefined, report.thread_id ),
            url      : report.bb.url_for.thread_show({ thread_id: report.thread_id, goto: 'newpost' }),
            flip_thread_openness: false
        });
    });

}

{'fraction_non_alphanumeric': 0.1451138299519901, 'fraction_numerical': 0.007124051417066749, 'mean_word_length': 2.630129286115795, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 8, 'https://': 2, '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': '6385186', 'n_tokens_mistral': 2049, 'n_tokens_neox': 1960, 'n_words': 509}