image_statistics.js 938 B

12345678910111213141516171819202122232425262728
  1. const fs = require("fs");
  2. const util = require("../util.js");
  3. const path = require("path");
  4. const db = require("../db.js");
  5. const statsFilePath = path.resolve(path.dirname(module.filename), "../imagestats.csv");
  6. const statsFile = fs.openSync(statsFilePath, "a");
  7. const onMessage = msg => {
  8. let imagesCount = msg.attachments.filter(v => util.isValidImage(v.filename)).size;
  9. if(imagesCount > 0) {
  10. let now = new Date();
  11. fs.writeSync(statsFile, `${now.getUTCFullYear()}-${now.getUTCMonth()+1}-${now.getUTCDate()} ${now.getUTCHours()}:${now.getUTCMinutes()};${imagesCount};${msg.channel.name}\n`);
  12. if(db.get("faceEditStatistics").has(msg.channel.id).value()) {
  13. let val = db.get("faceEditStatistics").get(msg.channel.id).value();
  14. db.get("faceEditStatistics").set(msg.channel.id, val + 1).write();
  15. }
  16. }
  17. return false;
  18. };
  19. module.exports = {
  20. onMessage: onMessage
  21. };