<commit_before>/**
 * Copyright 2015 <NAME>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */



var async = require('async');
var lib = require('./lib');
var util = require('util');
var _ = require('lodash');

// Constructor for the whole darn thing
var Bub = function (config) {
  'use strict';
  var BASE_URL = 'https://api.telegram.org/bot' + config.token;
  var TIMEOUT = config.timeout || 864000;
  var offset = null;

  // A reference to `this`, required for emitting events
  var self = this;

  function handleUpdates(body) {
    body.result.forEach(function (result) {
      // Convenience method for quick responses
      result.respond = function (content) {
        if (_.isString(content)) {
          self.sendMessage({
            chat_id: result.message.chat.id,
            text: content
          });
          return;
        }
        async.parallel([
          function (callback) {
            var message = {
              chat_id: result.message.chat.id,
              photo: content
            };
            self.sendPhoto(message, function (response) {
              callback(null, response);
            });
          },
          function (callback) {
            var message = {
              chat_id: result.message.chat.id,
              audio: content
            };
            self.sendAudio(message, function (response) {
              callback(null, response);
            });
          },
          function (callback) {
            var message = {
              chat_id: result.message.chat.id,
              video: content
            };
            self.sendVideo(message, function (response) {
              callback(null, response);
            });
          }
        ], function (err, responses) {
          if (err) {
            console.error(err);
          }
          if (_.every(responses, 'ok', false)) {
            var message = {
              chat_id: result.message.chat.id,
              document: content
            };
            self.sendDocument(message);
          }
        });
      };

      // Handle text messages
      if (result.message.text) {
        var command = result.message.text.split(' ')[0];
        var listeners = util.inspect(self.listeners(command));
        if (listeners !== '[]') {
          self.emit(command, result);
        } else {
          self.emit('_default', result);<commit_msg>Closures FTW<commit_after>/**
 * Copyright 2015 <NAME>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */



var async = require('async');
var lib = require('./lib');
var util = require('util');
var _ = require('lodash');

// Constructor for the whole darn thing
var Bub = function (config) {
  'use strict';
  var BASE_URL = 'https://api.telegram.org/bot' + config.token;
  var TIMEOUT = config.timeout || 864000;
  var offset = null;

  // A reference to `this`, required for emitting events
  var self = this;

  function getRespond(id) {
    return function (content) {
      if (_.isString(content)) {
        self.sendMessage({
          chat_id: id,
          text: content
        });
        return;
      }
      async.parallel([
        function (callback) {
          self.sendPhoto({
            chat_id: id,
            photo: content
          }, function (response) {
            callback(null, response);
          });
        },
        function (callback) {
          self.sendAudio({
            chat_id: id,
            audio: content
          }, function (response) {
            callback(null, response);
          });
        },
        function (callback) {
          self.sendVideo({
            chat_id: id,
            video: content
          }, function (response) {
            callback(null, response);
          });
        }
      ], function (err, responses) {
        if (err) {
          console.error(err);
        }
        if (_.every(responses, 'ok', false)) {
          self.sendDocument({
            chat_id: id,
            document: content
          });
        }
      });
    };
  }

  function handleUpdates(body) {
    body.result.forEach(function (result) {
      // Convenience method for quick responses
      result.respond = getRespond(result.message.chat.id);

      // Handle text messages
      if (result.message.text) {
        var command = result.message.text.split(' ')[0];
        var listeners = util.inspect(self.listeners(command));
        if (listeners !== '[]') {
          self.emit(command, result);
        } else {
          self.emit('_default', result);
{'fraction_non_alphanumeric': 0.11484897811539158, 'fraction_numerical': 0.005425935973955507, 'mean_word_length': 1.8907475169890224, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, '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': '6902915', 'n_tokens_mistral': 1484, 'n_tokens_neox': 1447, 'n_words': 442}