<commit_before>var Datastore = require('nedb');
var Handlebars = require('handlebars');
var moment = require("moment");

var db = new Datastore({
  filename: 'words.db',
  autoload: true
});

var util = require("util");

var debug = function (thing) {
  console.log(util.inspect(thing, {
    depth: 10
  }))

}

var server = require('http').createServer(),
  WebSocketServer = require('ws').Server,
  ws = new WebSocketServer({
    server: server
  }),
  express = require('express'),
  app = express(),
  bodyParser = require('body-parser'),
  port = 7777;

app.use(bodyParser.urlencoded({
  extended: false
}));

app.use(bodyParser.json());

var session = require('express-session');

app.use(session({
  secret: 'keyboard cat',
  resave: false,
  saveUninitialized: true
}));

var Hashids = require('hashids');
var hashids = new Hashids();

app.use(function (req, res, next) {

  if (!req.session.user) {

    req.session.user = "user-" + hashids.encode(Date.now());

  }

  next();

});

var messageParse = function (message, currentTags, currentUser) {

  // Reply is all tags

  message.reply = JSON.parse(JSON.stringify(message.tags));

  message.parent = message.tags.filter(function (item) {

    return item !== message.author && item !== message.id;

  })

  message.tags = message.tags.filter(function (item) {

    return item !== message.author && item !== message.id && currentTags.indexOf(item) === -1;

  })


  message.date = moment(message.date).fromNow();

  // Check if person has upvoted

  if (message.upvoted && message.downvoted) {

    if (message.upvoted.indexOf(currentUser) !== -1) {

      message.votedUp = true;

    }

    if (message.downvoted.indexOf(currentUser) !== -1) {

      message.votedDown = true;

    }

  }

  return message;

}

app.use(express.static('static'));

var fs = require("fs");

var messagesFromTags = function (tags, user) {

  return new Promise(function (resolve, reject) {

    var currentTags = [];

    var search;

    if (!tags || tags === "") {

      search = {};

    } else {

      var parsedTags = tags.split(",");

      var positive = [];
      var negative = [];

      parsedTags.forEach(function (tag) {

        // Check if first character is exclamation point, therefore negate

        if (tag[0] === "!") {

          negative.push(tag.substring(1));

        } else {

          positive.push(tag);

        }

        search = {
          "$and": [],
          "$not": []
        };

        positive.forEach(function (item) {

          search["$and"].push({
            tags: {
              $elemMatch: item
            }
          })

        })

        search["$not"].push({
          tags: {
            $size: 0
          }
        })

        negative.forEach(function (item) {

          search["$not"].push({
            tags: {
              $elemMatch: item
            }
          })

        })

      });

      currentTags = positive;

    }

    db.find(search).sort({
      date: -1
    }).exec(function (err, messages) {

      messages.forEach(function (message) {

        message = messageParse(message, currentTags, user)

      });


      messages.reverse();

      resolve(messages);

    });

  })

};

app.get("/:tags?", function (req, res) {

  var templateFile = fs.readFileSync(__dirname + "/index.html", "utf8");
  var messagesTemplateFile = fs.readFileSync(__dirname + "/messages.html", "utf8");
  var messageTemplateFile = fs.readFileSync(__dirname + "/message.html", "utf8");<commit_msg>Fix object assignment bugs<commit_after>var Datastore = require('nedb');
var Handlebars = require('handlebars');
var moment = require("moment");

var db = new Datastore({
  filename: 'words.db',
  autoload: true
});

var util = require("util");

var debug = function (thing) {
  console.log(util.inspect(thing, {
    depth: 10
  }))

}

var server = require('http').createServer(),
  WebSocketServer = require('ws').Server,
  ws = new WebSocketServer({
    server: server
  }),
  express = require('express'),
  app = express(),
  bodyParser = require('body-parser'),
  port = 7777;

app.use(bodyParser.urlencoded({
  extended: false
}));

app.use(bodyParser.json());

var session = require('express-session');

app.use(session({
  secret: 'keyboard cat',
  resave: false,
  saveUninitialized: true
}));

var Hashids = require('hashids');
var hashids = new Hashids();

app.use(function (req, res, next) {

  if (!req.session.user) {

    req.session.user = "user-" + hashids.encode(Date.now());

  }

  next();

});

var messageParse = function (rawMessage, currentTags, currentUser) {

  var message = {}

  Object.assign(message, rawMessage);

  // Reply is all tags

  message.reply = JSON.parse(JSON.stringify(message.tags));

  message.parent = message.tags.filter(function (item) {

    return item !== message.author && item !== message.id;

  })

  message.tags = message.tags.filter(function (item) {

    return item !== message.author && item !== message.id && currentTags.indexOf(item) === -1;

  })

  message.date = moment(message.date).fromNow();

  // Check if person has upvoted

  if (message.upvoted && message.downvoted) {

    if (message.upvoted.indexOf(currentUser) !== -1) {

      message.votedUp = true;

    }

    if (message.downvoted.indexOf(currentUser) !== -1) {

      message.votedDown = true;

    }

  }

  return message;

}

app.use(express.static('static'));

var fs = require("fs");

var messagesFromTags = function (tags, user) {

  return new Promise(function (resolve, reject) {

    var currentTags = [];

    var search;

    if (!tags || tags === "") {

      search = {};

    } else {

      var parsedTags = tags.split(",");

      var positive = [];
      var negative = [];

      parsedTags.forEach(function (tag) {

        // Check if first character is exclamation point, therefore negate

        if (tag[0] === "!") {

          negative.push(tag.substring(1));

        } else {

          positive.push(tag);

        }

        search = {
          "$and": [],
          "$not": []
        };

        positive.forEach(function (item) {

          search["$and"].push({
            tags: {
              $elemMatch: item
            }
          })

        })

        search["$not"].push({
          tags: {
            $size: 0
          }
        })

        negative.forEach(function (item) {

          search["$not"].push({
            tags: {
              $elemMatch: item
            }
          })

        })

      });

      currentTags = positive;

    }

    db.find(search).sort({
      date: -1
    }).exec(function (err, messages) {

      messages.forEach(function (message, index) {

        messages[index] = messageParse(message, currentTags, user)

      });


      messages.reverse();

      resolve(messages);

    });

  })

};

app.get("/:tags?", function (req, res) {

  var templateFile = fs.readFileSync(__dirname + "/index.html", "utf8");
  var messagesTemplateFile = fs.readFileSync(__dirname + "/messages.html", "utf8");
  var messageTemplateFile = fs.readFileSync(__dirname + "/message.html", "utf8");
{'fraction_non_alphanumeric': 0.16232577784034916, 'fraction_numerical': 0.004505138673799803, 'mean_word_length': 2.430226943505553, 'pattern_counts': {'":': 4, '<': 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': '427130', 'n_tokens_mistral': 2276, 'n_tokens_neox': 2138, 'n_words': 465}