<commit_before>require 'rubygems'
require 'sinatra'
require 'json'
require 'uri'
require 'net/http'
require 'dicebag'


post '/' do

  puts request.POST.inspect

  username = request.POST["user_name"]
  text = request.POST["text"]

  puts "requester: #{username}"
  puts "text:      #{text}"

  %r{^(?<number_of_dice>\d+)d(?<die_size>\d+)?\+?(?<plus>\d+)?$} =~ text[5..-1].strip

  if number_of_dice.nil? or die_size.nil?
    return 200
  end

  die_request = text[6..-1]
  result = DiceBag::Roll.new(die_request).result()
  total = result.total
  tally = result.sections[0].tally

  webhook_url = "<KEY>"

  uri = URI(webhook_url)
  https = Net::HTTP.new(uri.host, uri.port)
  https.use_ssl = true

  request = Net::HTTP::Post.new(uri.path, initheader = {'Content-Type' =>'application/json'})
  request.body = { "text" => "#{username} rolled #{number_of_dice}d#{die_size} and got #{total} #{tally}" }.to_json

  response = https.request(request)

  puts response.inspect

  return 200

end
<commit_msg>Fix parsing error.<commit_after>require 'rubygems'
require 'sinatra'
require 'json'
require 'uri'
require 'net/http'
require 'dicebag'


post '/' do

  puts request.POST.inspect

  username = request.POST["user_name"]
  text = request.POST["text"]

  puts "requester: #{username}"
  puts "text:      #{text}"

  die_request = text[5..-1].strip

  %r{^(?<number_of_dice>\d+)d(?<die_size>\d+)?\+?(?<plus>\d+)?$} =~ die_request

  if number_of_dice.nil? or die_size.nil?
    return 200
  end

  result = DiceBag::Roll.new(die_request).result()
  total = result.total
  tally = result.sections[0].tally

  webhook_url = "<KEY>"

  uri = URI(webhook_url)
  https = Net::HTTP.new(uri.host, uri.port)
  https.use_ssl = true

  request = Net::HTTP::Post.new(uri.path, initheader = {'Content-Type' =>'application/json'})
  request.body = { "text" => "#{username} rolled #{number_of_dice}d#{die_size} and got #{total} #{tally}" }.to_json

  response = https.request(request)

  puts response.inspect

  return 200

end

{'fraction_non_alphanumeric': 0.1779324055666004, 'fraction_numerical': 0.009940357852882704, 'mean_word_length': 4.161538461538462, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 15, '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': '4757807', 'n_tokens_mistral': 791, 'n_tokens_neox': 756, 'n_words': 150}