<commit_before>'use strict';

var util = require('../../utilities');
var say_slowly = require('../../say-slowly.js');

function initPoll(db,channel) {
  db.poll = db.poll || [];
  db.poll[channel] = db.poll[channel] || {id:0, polls:[]};
  return db.poll[channel];
}

function usage(db,extraInfo,channel){

  var message = [];
  var channelPolls = {};
  if (extraInfo !== '') {
    message.push('Error: ' + extraInfo + ' ');
  }

  message.push('Usage: @poll <start|close> <message|id>');

  channelPolls = initPoll(db,channel);
  if (channelPolls.polls.length > 0 )  {
    
    channelPolls.polls.forEach(function(poll) {
      message.push('Id: ' + poll.id + ' User: ' + poll.user + ' Question: ' + poll.question + 
                   ' Yeas: ' + poll.yeas + ' Nays: ' + poll.nays+ ' Open: ' +  poll.isOpen);
    });
  }
  return {callback: 
    function(say) {
      say_slowly(say, channel, message);
    }
  };
} 

function findPoll(polls,id) {
  var poll = polls.filter(function(poll) { return (poll.id === id);});
  return poll[0] || null;
}

function voteListener(db, from, channel, message, messageCallback) {

  var match = /^@vote\s+(\d+)\s+(yea|nay)/.exec(message);
  var msg = '';
  var channelPolls = initPoll(db,channel);
  if (match) {

    var id  = parseInt(match[1]);
    var vote = match[2];
    var poll = findPoll(channelPolls.polls,id);
    
    if (poll)  {
      if (poll.isOpen) {<commit_msg>added checks if defined<commit_after>'use strict';

var util = require('../../utilities');
var say_slowly = require('../../say-slowly.js');

function initPoll(db,channel) {
  db.poll = db.poll || [];
  db.poll[channel] = db.poll[channel] || {id:0, polls:[]};
  console.log(db.poll[channel]);
  return db.poll[channel];
}

function usage(db,extraInfo,channel){

  var message = [];
  var channelPolls = {};
  if (extraInfo !== '') {
    message.push('Error: ' + extraInfo + ' ');
  }

  message.push('Usage: @poll <start|close> <message|id>');

  channelPolls = initPoll(db,channel);
  if (channelPolls.polls.length > 0 )  {
    
    channelPolls.polls.forEach(function(poll) {
      if (poll) {
        message.push('Id: ' + poll.id + ' User: ' + poll.user + ' Question: ' + poll.question + 
                     ' Yeas: ' + poll.yeas + ' Nays: ' + poll.nays+ ' Open: ' +  poll.isOpen);
      }
    });
  }
  return {callback: 
    function(say) {
      say_slowly(say, channel, message);
    }
  };
} 

function findPoll(polls,id) {
  var poll = polls.filter(function(poll) { 
  if (poll) 
  {
    return (poll.id === id);
  } 
  return false;
  });
  return poll[0] || null;
}

function voteListener(db, from, channel, message, messageCallback) {

  var match = /^@vote\s+(\d+)\s+(yea|nay)/.exec(message);
  var msg = '';
  var channelPolls = initPoll(db,channel);
  if (match) {

    var id  = parseInt(match[1]);
    var vote = match[2];
    var poll = findPoll(channelPolls.polls,id);
    
    if (poll)  {
      if (poll.isOpen) {
{'fraction_non_alphanumeric': 0.19166948865560446, 'fraction_numerical': 0.0033863867253640365, 'mean_word_length': 2.96510067114094, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, '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': '2859464', 'n_tokens_mistral': 1114, 'n_tokens_neox': 1082, 'n_words': 202}