<commit_before>require 'sinatra'
require 'json'
require './filter'
SLACK_TOKEN = ENV['SLACK_TOKEN']

puts "TOKEN: #{SLACK_TOKEN}"

before '/hooks' do
  unless token_valid?
    puts 'Token invalid'
    halt 403, "Token is invalid\n"
  end
  if comment_by_myself?
    puts 'Comment by myself'
    halt 200
  end
end

def token_valid?
  params['token'] == SLACK_TOKEN
end

def comment_by_myself?
 params['user_name'] == 'slackbot'
end

get '/' do
  'Hello world!'
end

post '/hooks' do
  response = filter.update(params).compact.first
  return 200 unless response
  j = response.to_json
  puts j
  j
end

def filter
  @filter ||= Filter::Pipe.new
end<commit_msg>Add multi-token options and enable expand urls<commit_after>require 'sinatra'
require 'json'
require './filter'
SLACK_TOKENS = ENV['SLACK_TOKENS'].split(/\,/)

puts "TOKEN: #{SLACK_TOKENS}"

before '/hooks' do
  unless token_valid?
    puts 'Token invalid'
    halt 403, "Token is invalid\n"
  end
  if comment_by_myself?
    puts 'Comment by myself'
    halt 200
  end
end

def token_valid?
  SLACK_TOKENS.include?(params['token'])
end

def comment_by_myself?
 params['user_name'] == 'slackbot'
end

get '/' do
  'Hello world!'
end

post '/hooks' do
  response = filter.update(params).compact.first
  return 200 unless response
  response.merge!({link_names: 1, parse: "full"})
  j = response.to_json
  puts j
  j
end

def filter
  @filter ||= Filter::Pipe.new
end
{'fraction_non_alphanumeric': 0.12008426966292135, 'fraction_numerical': 0.013342696629213483, 'mean_word_length': 3.9479166666666665, 'pattern_counts': {'":': 0, '<': 3, '<?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': '6973600', 'n_tokens_mistral': 532, 'n_tokens_neox': 526, 'n_words': 148}