<commit_before>(function(module) {
  "use strict";
  var anon = {},
    settings = {},
    banList = [],
    regexPhrase = /\[\[ANON\]\]/,
    breakLine = '\r\n\r\n',
    signTitle = '###### sign: ',
    winston = module.parent.require('winston'),
    meta = module.parent.require('./meta'),
    crypto = require('crypto');

  anon.init = function(params, callback) {
    var router = params.router,
      hostMiddleware = params.middleware;

    router.get('/admin/plugins/anon', hostMiddleware.admin.buildHeader, render);
    router.get('/api/admin/plugins/anon', render);

    callback();
  }

  anon.filter = function(data, callback) {
    if (settings != null) {
      if (regexPhrase.test(data.content)) {
        var sign = getSign(data.uid);

        if (existInBanList(sign) && hasAccessCategory(data.cid)) {
          return callback(new Error('[[error:no-privileges]]'))
        }

        data.content = data.content.replace(regexPhrase, '') + breakLine + signTitle + sign;
        data.uid = settings.uid;
      }
    }
    
    return callback(null, data);
  }

  anon.addAdminNavigation = function(header, callback) {
    header.plugins.push({
      route: '/plugins/anon',
      icon: 'fa-tint',
      name: 'Anon'
    });

    callback(null, header);
  }

  function hasAccessCategory(cid) {
    var accessArrayCategory = settings.accessCategory.splice(', ');
    return accessArrayCategory.indexOf(cid);
  }

  function existInBanList(sign) {
    return banList.indexOf(sign) === -1;
  }

  function getSign(uid) {
    return crypto.createHash('sha256').update(uid + settings.salt).digest('base64');
  }

  function render(req, res) {
    res.render('admin/plugins/anon', {});
  }

  function saveSettings() {<commit_msg>Finish init<commit_after>(function(module) {
  "use strict";
  var anon = {},
    settings = {},
    banList = [],
    regexPhrase = /\[\[ANON\]\]/,
    breakLine = '\r\n\r\n',
    signTitle = '###### sign: ',
    winston = module.parent.require('winston'),
    meta = module.parent.require('./meta'),
    crypto = require('crypto');

  anon.init = function(params, callback) {
    var router = params.router,
      hostMiddleware = params.middleware;

    router.get('/admin/plugins/anon', hostMiddleware.admin.buildHeader, render);
    router.get('/api/admin/plugins/anon', render);

    loadSettings()
      .then(function() {
        winston.info('[nodebb-plugin-anon] Settings loaded');
      });

    loadBanList()
      .then(function() {
        winston.info('[nodebb-plugin-anon] Ban list loaded');
      });

    callback();
  }

  anon.filter = function(data, callback) {
    if (settings != null) {
      if (regexPhrase.test(data.content)) {
        var sign = getSign(data.uid);

        if (existInBanList(sign) && hasAccessCategory(data.cid)) {
          return callback(new Error('[[error:no-privileges]]'))
        }

        data.content = data.content.replace(regexPhrase, '') + breakLine + signTitle + sign;
        data.uid = settings.uid;
      }
    }

    return callback(null, data);
  }

  anon.addAdminNavigation = function(header, callback) {
    header.plugins.push({
      route: '/plugins/anon',
      icon: 'fa-tint',
      name: 'Anon'
    });

    callback(null, header);
  }

  function hasAccessCategory(cid) {
    var accessArrayCategory = settings.accessCategory.splice(', ');
    return accessArrayCategory.indexOf(cid);
  }

  function existInBanList(sign) {
    return banList.indexOf(sign) === -1;
  }

  function getSign(uid) {
    return crypto.createHash('sha256').update(uid + settings.salt).digest('base64');
  }

  function render(req, res) {
    res.render('admin/plugins/anon', {});
  }

  function saveSettings() {
{'fraction_non_alphanumeric': 0.16572199730094467, 'fraction_numerical': 0.0032388663967611335, 'mean_word_length': 2.905163329820864, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '6216628', 'n_tokens_mistral': 1209, 'n_tokens_neox': 1153, 'n_words': 202}