<commit_before>Chachara.MessageHandler = function(options) {
  options || (options ={});
  this.initialize(options);
}

_.extend(Chachara.MessageHandler.prototype, Backbone.Events, {
  initialize: function(options) {
    _.bindAll(this, "processMessage");
    this.options = options;
    this.handlers = options.handlers;
  },

  embeddable: function(regex, body) {
    var matches = regex.exec(body);
    return (matches != null) ? true : false;
  },

  url: function(body) {
    var regex = /((http|https):\/\/(\S*?\.\S*?))(\s|\;|\)|\]|\[|\{|\}|,|\"|'|:|\<|$|\.\s)/;
    return regex.exec(body)[0];
  },

  processMessage: function(message) {
    var self = this;
    var embeddable = false;

    for (var i = 0; i < this.handlers.length; i++) {
      if (this.embeddable(this.handlers[i].regex, message.body)) {
        $.embedly(this.url(message.body),
          { maxWidth : 800, maxHeight: 500,
            success  : function(oembed, dict) {
              console.log(oembed);
              if (oembed.html5)     message.html = oembed.html5;
              else if (oembed.html) message.html = oembed.html;
              else                  message.html = oembed.code;
              self.trigger("embedded", message);
        }});
      }
    }
  }

});

Chachara.YoutubeHandler = function(name) {
  this.name = name;<commit_msg>Looks like iframes are going to be a problem then, avoid them for now.<commit_after>Chachara.MessageHandler = function(options) {
  options || (options ={});
  this.initialize(options);
}

_.extend(Chachara.MessageHandler.prototype, Backbone.Events, {
  initialize: function(options) {
    _.bindAll(this, "processMessage");
    this.options = options;
    this.handlers = options.handlers;
  },

  embeddable: function(regex, body) {
    var matches = regex.exec(body);
    return (matches != null) ? true : false;
  },

  url: function(body) {
    var regex = /((http|https):\/\/(\S*?\.\S*?))(\s|\;|\)|\]|\[|\{|\}|,|\"|'|:|\<|$|\.\s)/;
    return regex.exec(body)[0];
  },

  processMessage: function(message) {
    var self = this;
    var embeddable = false;

    for (var i = 0; i < this.handlers.length; i++) {
      if (this.embeddable(this.handlers[i].regex, message.body)) {
        $.embedly(this.url(message.body),
          { maxWidth : 800, maxHeight: 500,
            success  : function(oembed, dict) {
              console.log(oembed);
              if (oembed.html) message.html = oembed.html;
              else             message.html = oembed.code;
              self.trigger("embedded", message);
        }});
      }
    }
  }

});

Chachara.YoutubeHandler = function(name) {
  this.name = name;
{'fraction_non_alphanumeric': 0.17808734939759036, 'fraction_numerical': 0.00677710843373494, 'mean_word_length': 2.5006587615283267, 'pattern_counts': {'":': 0, '<': 7, '<?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': '393042', 'n_tokens_mistral': 907, 'n_tokens_neox': 869, 'n_words': 163}