<commit_before>require! <[./games ./util]>

choose = util.from-random
command = /\s*(\S+)\s*(.+)?/

function ask question
  if question then
    if games.questions.has-own-property question then
      util.from-random games.questions[question]
    else
      'Your options are ' + Object.keys(games.questions).join(', ')
  else
    util.from-random games.questions

function vote command
  "#{it}"

controller =
  say: (-> "#{it}")
  flip: (-> choose <[heads tails]>)
  roll: (-> '' + if it then util.up-to parse-int it else util.up-to! )
  ask: ask
  tell: (-> util.from-random games.answers)
  vote: vote

execute = (command, content) ->
  if controller.has-own-property command then
    controller[command] content

using = (message) ->
  execute(that.1.to-lower-case!, that.2) if message.match command

safely = (content) ->
  content or 'I have nothing to say.'

txt = ->
  it.reply safely using it.body

export txt
export safely<commit_msg>Experimental vote command<commit_after>require! <[./games ./util]>

choose = util.from-random
command = /\s*(\S+)\s*(.+)?/

function ask question
  if question then
    if games.questions.has-own-property question then
      util.from-random games.questions[question]
    else
      'Your options are ' + Object.keys(games.questions).join(', ')
  else
    util.from-random games.questions

function vote command
  if command.index-of('on') !== -1 then
    global.vote-tally = {yes: 0, no: 0}
  else if command.index-of('off') !== -1 and global.vote-tally? then
    for own let key, value of global.vote-tally when value > 0
      key + ' = ' + value
  else if global.vote-tally? then
    lower = command.to-lower-case!
    global.vote-tally[lower] = (global.vote-tally[lower] or 1)

controller =
  say: (-> "#{it}")
  flip: (-> choose <[heads tails]>)
  roll: (-> '' + if it then util.up-to parse-int it else util.up-to! )
  ask: ask
  tell: (-> util.from-random games.answers)
  vote: vote

execute = (command, content) ->
  if controller.has-own-property command then
    controller[command] content

using = (message) ->
  execute(that.1.to-lower-case!, that.2) if message.match command

safely = (content) ->
  content or 'I have nothing to say.'

txt = ->
  it.reply safely using it.body

export txt
export safely
{'fraction_non_alphanumeric': 0.15106007067137808, 'fraction_numerical': 0.00441696113074205, 'mean_word_length': 3.1483516483516483, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 24, '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': '7398288', 'n_tokens_mistral': 780, 'n_tokens_neox': 751, 'n_words': 214}