<commit_before>const Discord = require('discord.js');
const UserRecord = require('./UserRecord.js');
const SimpleMsg = require('./SimpleMessage.js');
const BST = require('./BST.js');
const LINE = require('@line/bot-sdk');
const fs = require('fs');

// imgur setup
const config = require('../config.json');
const request = require('request');

// LINE setup
const LINEclient = new LINE.Client({
  channelAccessToken: config.LINEchannelAccessToken
});

module.exports = class Server {
    constructor(guild) {
      this.guild = guild;
      this.hiddenChannels = [];
      this.users = {};
      this.deletedMessages = [];
      this.today = 0;
      this.watchedUsers = {}; // surveillance
      this.newUsers = [];
      if (fs.existsSync(`./.${this.guild.id}_restore.json`)) {
        let json = JSON.parse(fs.readFileSync(`./.${this.guild.id}_restore.json`, 'utf8'));
        this.hiddenChannels = json['hiddenChannels'];
        this.today = json['today'];
        this.newUsers = json['newUsers'];
        for (var user in json['users']) {
          let uRec = json['users'][user]
          this.users[user] = new UserRecord(uRec['record'], uRec['thirty'],
            uRec['jp'], uRec['chans']); // TODO fix to new var names
        }
        for (var msg in json['deletedMessages']) {
          let dm = json['deletedMessages'][msg];
          this.deletedMessages.push(new SimpleMsg(dm.id, dm.del, dm.a, dm.atag, dm.aid, dm.apfp, dm.con, dm.acon, dm.ch, dm.chid, dm.time, dm.dur, dm.img));
        }
        for (var wu in json['watchedUsers']) {
          this.watchedUsers[wu] = [];
          // Uncomment below for restoring them
          // let dms = json['watchedUsers'][wu];
          // for (var i in dms) {
          //   let dm = json['watchedUsers'][wu][i];
          //   this.watchedUsers[wu].push(new SimpleMsg(dm.id, dm.del, dm.a, dm.atag, dm.aid, dm.apfp, dm.con, dm.acon, dm.ch, dm.chid, dm.time, dm.dur, dm.img));
          // }
        }
      }
    }

    hideChannel(channel) {
      if (this.hiddenChannels.includes(channel)) return;
      this.hiddenChannels.push(channel);
    }

    addMessage(message) {
      let author = message.author.id;
      let channel = message.channel.id;
      if (!this.users[author]) {
        this.users[author] = new UserRecord();
      }
      let userRec = this.users[author];
      userRec.add(message.content, channel, this.today);

      // Notify via LINE
      if (message.mentions.members[bot.owner_ID] || message.mentions.roles['240647591770062848']) {
        if (message.content.startsWith('t!')) return; // ignore tatsumaki
        const LINEmsg = [];
        LINEmsg.push({
          type: 'text',
          text: `${message.content}`
        });
        LINEmsg.push({
          type: 'text',
          text: `In #${message.channel.name} by ${message.author.username}`
        });
        LINEclient.pushMessage(config.LINEuserID, LINEmsg)
          .catch((err) => {
            throw new Error(err);
          });
      }
    }

    addDeletedMessage(message) {
      let con = message.content;
      if (con.startsWith('.') || con.startsWith('t!') ||
        con.startsWith('!') || con.startsWith(':') ||
        con.startsWith('&') || con.startsWith(',')) return; // no bot messages
      var imageURL = '';
      if (message.attachments.size > 0) {
        imageURL = message.attachments.first().url;
        message.content += `\n{Attachment (expires soon): ${imageURL} }`;
      } else if (message.content.length < 3) {
        return;
      }
      let simple = new SimpleMsg(message);<commit_msg>line notif working<commit_after>const Discord = require('discord.js');
const UserRecord = require('./UserRecord.js');
const SimpleMsg = require('./SimpleMessage.js');
const BST = require('./BST.js');
const LINE = require('@line/bot-sdk');
const fs = require('fs');

// imgur setup
const config = require('../config.json');
const request = require('request');

// LINE setup
const LINEclient = new LINE.Client({
  channelAccessToken: config.LINEchannelAccessToken
});

module.exports = class Server {
    constructor(guild) {
      this.guild = guild;
      this.hiddenChannels = [];
      this.users = {};
      this.deletedMessages = [];
      this.today = 0;
      this.watchedUsers = {}; // surveillance
      this.newUsers = [];
      if (fs.existsSync(`./.${this.guild.id}_restore.json`)) {
        let json = JSON.parse(fs.readFileSync(`./.${this.guild.id}_restore.json`, 'utf8'));
        this.hiddenChannels = json['hiddenChannels'];
        this.today = json['today'];
        this.newUsers = json['newUsers'];
        for (var user in json['users']) {
          let uRec = json['users'][user]
          this.users[user] = new UserRecord(uRec['record'], uRec['thirty'],
            uRec['jp'], uRec['chans']); // TODO fix to new var names
        }
        for (var msg in json['deletedMessages']) {
          let dm = json['deletedMessages'][msg];
          this.deletedMessages.push(new SimpleMsg(dm.id, dm.del, dm.a, dm.atag, dm.aid, dm.apfp, dm.con, dm.acon, dm.ch, dm.chid, dm.time, dm.dur, dm.img));
        }
        for (var wu in json['watchedUsers']) {
          this.watchedUsers[wu] = [];
          // Uncomment below for restoring them
          // let dms = json['watchedUsers'][wu];
          // for (var i in dms) {
          //   let dm = json['watchedUsers'][wu][i];
          //   this.watchedUsers[wu].push(new SimpleMsg(dm.id, dm.del, dm.a, dm.atag, dm.aid, dm.apfp, dm.con, dm.acon, dm.ch, dm.chid, dm.time, dm.dur, dm.img));
          // }
        }
      }
    }

    hideChannel(channel) {
      if (this.hiddenChannels.includes(channel)) return;
      this.hiddenChannels.push(channel);
    }

    addMessage(message) {
      let author = message.author.id;
      let channel = message.channel.id;
      if (!this.users[author]) {
        this.users[author] = new UserRecord();
      }
      let userRec = this.users[author];
      userRec.add(message.content, channel, this.today);

      // Notify via LINE
      if (message.mentions.users.has(config.owner_ID) || message.mentions.roles.has('240647591770062848')) {
        this.guild.fetchMember(config.owner_ID)
          .then((member) => {
            if (member.presence.status != 'offline') return; // if I'm offline
            if (message.content.startsWith('t!')) return; // ignore tatsumaki
            const LINEmsg = [];
            LINEmsg.push({
              type: 'text',
              text: `${message.cleanContent}`
            });
            LINEmsg.push({
              type: 'text',
              text: `In #${message.channel.name} by ${message.author.username}`
            });
            LINEclient.pushMessage(config.LINEuserID, LINEmsg)
            .catch((err) => {
              throw new Error(err);
            });
          });
      }
    }

    addDeletedMessage(message) {
      let con = message.content;
      if (con.startsWith('.') || con.startsWith('t!') ||
        con.startsWith('!') || con.startsWith(':') ||
        con.startsWith('&') || con.startsWith(',')) return; // no bot messages
      var imageURL = '';
      if (message.attachments.size > 0) {
        imageURL = message.attachments.first().url;
        message.content += `\n{Attachment (expires soon): ${imageURL} }`;
      } else if (message.content.length < 3) {
        return;
      }
      let simple = new SimpleMsg(message);
{'fraction_non_alphanumeric': 0.16806155507559395, 'fraction_numerical': 0.005939524838012959, 'mean_word_length': 2.3179579041648006, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 8, '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': '302306', 'n_tokens_mistral': 2411, 'n_tokens_neox': 2316, 'n_words': 468}