<commit_before>const debug = require('debug')('node-telegram-bot-api');
const https = require('https');
const http = require('http');
const fs = require('fs');
const bl = require('bl');

class TelegramBotWebHook {

  constructor(token, options, callback) {
    this.token = token;
    this.callback = callback;
    this.regex = new RegExp(this.token);

    // define opts
    if (typeof options === 'boolean') {
      options = {}; // eslint-disable-line no-param-reassign
    }
    options.port = options.port || 8443;

    if (options.key && options.cert) { // HTTPS Server
      debug('HTTPS WebHook enabled');
      const opts = {
        key: fs.readFileSync(options.key),
        cert: fs.readFileSync(options.cert)
      };
      this._webServer = https.createServer(opts, this._requestListener);
    } else {
      debug('HTTP WebHook enabled');
      this._webServer = http.createServer(this._requestListener);
    }

    this._webServer.listen(options.port, options.host, () => {
      debug('WebHook listening on port %s', options.port);
    });
  }

  // used so that other funcs are not non-optimizable
  _safeParse(json) {
    try {
      return JSON.parse(json);
    } catch (err) {
      debug(err);
      return null;
    }
  }

  // pipe+parse body
  _parseBody = (err, body) => {
    if (err) {
      return debug(err);
    }

    const data = this._safeParse(body);
    if (data) {
      return this.callback(data);
    }

    return null;
  }

  // bound req listener
  _requestListener = (req, res) => {
    debug('WebHook request URL:', req.url);
    debug('WebHook request headers: %j', req.headers);

    // If there isn't token on URL
    if (!this.regex.test(req.url)) {
      debug('WebHook request unauthorized');
      res.statusCode = 401;
      res.end();<commit_msg>Fix ES6 syntax errors<commit_after>const debug = require('debug')('node-telegram-bot-api');
const https = require('https');
const http = require('http');
const fs = require('fs');
const bl = require('bl');

class TelegramBotWebHook {

  constructor(token, options, callback) {
    this.token = token;
    this.callback = callback;
    this.regex = new RegExp(this.token);

    // define opts
    if (typeof options === 'boolean') {
      options = {}; // eslint-disable-line no-param-reassign
    }
    options.port = options.port || 8443;

    if (options.key && options.cert) { // HTTPS Server
      debug('HTTPS WebHook enabled');
      const opts = {
        key: fs.readFileSync(options.key),
        cert: fs.readFileSync(options.cert)
      };
      this._webServer = https.createServer(opts, this._requestListener);
    } else {
      debug('HTTP WebHook enabled');
      this._webServer = http.createServer(this._requestListener);
    }

    this._webServer.listen(options.port, options.host, () => {
      debug('WebHook listening on port %s', options.port);
    });
  }

  // used so that other funcs are not non-optimizable
  _safeParse(json) {
    try {
      return JSON.parse(json);
    } catch (err) {
      debug(err);
      return null;
    }
  }

  // pipe+parse body
  _parseBody(err, body) {
    if (err) {
      return debug(err);
    }

    const data = this._safeParse(body);
    if (data) {
      return this.callback(data);
    }

    return null;
  }

  // bound req listener
  _requestListener(req, res) {
    debug('WebHook request URL:', req.url);
    debug('WebHook request headers: %j', req.headers);

    // If there isn't token on URL
    if (!this.regex.test(req.url)) {
      debug('WebHook request unauthorized');
      res.statusCode = 401;
      res.end();
{'fraction_non_alphanumeric': 0.14524207011686144, 'fraction_numerical': 0.004173622704507512, 'mean_word_length': 2.6758691206543967, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '5249944', 'n_tokens_mistral': 1141, 'n_tokens_neox': 1104, 'n_words': 268}