<commit_before>import Promise from 'bluebird'
const debug = require('debug')('wololobot:raffle')

const openUsage = '!raffle open [price] [max tickets] [?winners]'

const sum = (a, b) => a + b
const check = n => n != null && !isNaN(parseInt(n, 10))

export default function (opts) {

  function raffle(bot, price, maxTickets, winnersNeeded) {
    let _entries = {}

    function enter(user, tickets) {
      if (isNaN(tickets) || tickets < 0)
        return Promise.reject(new Error('Invalid number of tickets.'))
      if (tickets > maxTickets)
        return Promise.reject(new Error(`Cannot enter with more than ${maxTickets} tickets.`))

      let luser = user.toLowerCase()
      if (tickets === 0) {
        delete _entries[luser]
        return Promise.resolve({ user, tickets: 0 })
      }

      return bot.florinsOf(user).then(florins => {
        if (florins > tickets * price)
          return Promise.reject(new Error('You don\'t have that many florins.'))

        _entries[luser] = { user, tickets }
        return _entries[luser]
      })
    }
    function entries() {
      return Object.keys(_entries).map(u => _entries[u])
    }
    function tickets(user) {
      return _entries[user.toLowerCase()].tickets
    }
    function entryValue(user) {
      let t = tickets(user)
      return t ? price * t : 0
    }
    function totalTickets() {
      return entries().map(entry => entry.tickets).reduce(sum)
    }
    function end() {
      // find winners
      let availableTickets = totalTickets()
        , availableEntries = entries()
        , winners = []<commit_msg>raffle: fix retrieving tickets for users who did not enter<commit_after>import Promise from 'bluebird'
const debug = require('debug')('wololobot:raffle')

const openUsage = '!raffle open [price] [max tickets] [?winners]'

const sum = (a, b) => a + b
const check = n => n != null && !isNaN(parseInt(n, 10))

export default function (opts) {

  function raffle(bot, price, maxTickets, winnersNeeded) {
    let _entries = {}

    function enter(user, tickets) {
      if (isNaN(tickets) || tickets < 0)
        return Promise.reject(new Error('Invalid number of tickets.'))
      if (tickets > maxTickets)
        return Promise.reject(new Error(`Cannot enter with more than ${maxTickets} tickets.`))

      let luser = user.toLowerCase()
      if (tickets === 0) {
        delete _entries[luser]
        return Promise.resolve({ user, tickets: 0 })
      }

      return bot.florinsOf(user).then(florins => {
        if (florins > tickets * price)
          return Promise.reject(new Error('You don\'t have that many florins.'))

        _entries[luser] = { user, tickets }
        return _entries[luser]
      })
    }
    function entries() {
      return Object.keys(_entries).map(u => _entries[u])
    }
    function tickets(user) {
      return (_entries[user.toLowerCase()] || {}).tickets
    }
    function entryValue(user) {
      let t = tickets(user)
      return t ? price * t : 0
    }
    function totalTickets() {
      return entries().map(entry => entry.tickets).reduce(sum)
    }
    function end() {
      // find winners
      let availableTickets = totalTickets()
        , availableEntries = entries()
        , winners = []
{'fraction_non_alphanumeric': 0.13145685122177544, 'fraction_numerical': 0.0037117228580266005, 'mean_word_length': 2.7430555555555554, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 17, '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': '3671828', 'n_tokens_mistral': 996, 'n_tokens_neox': 979, 'n_words': 270}