<commit_before>def replace_mentions(message)
  message.strip!
  message.gsub! '**', ''
  message.gsub! '@everyone', '**everyone**'
  message.gsub! '@here', '**here**'
  words = message.split ' '
  done = []
  words.each_with_index do |w, i|
    w.sub!('(', '')
    w.sub!(')', '')
    w.sub!('"', '')
    if w.start_with? '<@' and w.end_with? '>'
      id = w.sub('<@!', '').sub('<@', '').sub('>', '') # Get ID 
      if !done.include? id and /\A\d+\z/.match(id)
        user = $db.query("SELECT username FROM students WHERE discord_id=#{id}")
        if user.count > 0
          user = user.first
          rep = "**@#{user["username"]}**" # replacement
          message.gsub! "<@#{id}>", rep # Only works when they don't have a nickname
          message.gsub! "<@!#{id}>", rep
        end
        done << id
      end
    end
  end

  return message.sub('@', '') if words.length == 1 and done == 1
  return message
end

def delete_channel(server, channel, count=1)
  return if channel.nil?

  puts "Deleting voice-channel #{channel.name} and associated #voice-channel"
  begin
    channel.delete
  rescue
    puts 'Failed to delete voice-channel'
  end
  begin
    server.text_channels.find{|t| t.id == $hierarchy[channel.id]}.delete
    $hierarchy.delete channel.id
  rescue => e
    puts 'Failed to find/delete associated #voice-channel'
    puts e
    if count < 2
      sleep 1.1
      delete_channel(server, channel, count + 1)
    end
  end
end

$groups = nil
def handle_group_voice_channels(server)
  if $groups.nil?
    $groups = $db.query('SELECT * FROM groups WHERE creator != "server"')
  end

  $groups.each do |row|
    group_role = server.roles.find{|r| r.id==Integer(row['role_id'])}
    next if group_role.nil?

    # Get count of online group members
    total_count = server.members.find_all { |m| m.role? group_role }.length
    count = server.online_members.find_all { |m| m.role? group_role }.length
    channel = server.voice_channels.find { |c| c.name == "Group #{row['name']}" }
    perms = Discordrb::Permissions.new
    perms.can_connect = true

    minimum = (total_count * 0.25).floor > 5 ? (total_count * 0.25).floor > minimum : 5 
    minimum = 10 if minimum > 10

    if count > minimum
      if channel.nil? and server.voice_channels.find { |c| c.name == row['name'] }.nil?
        puts "Opening group voice channel for #{row['name']}"
        channel = server.create_channel("Group #{row['name']}", 'voice')
        study_role = server.roles.find { |r| r.name == "studying" }
        channel.define_overwrite(group_role, perms, 0)
        Discordrb::API.update_role_overrides($token, channel.id, server.id, 0, perms.bits)
        study_perms = perms
        study_perms.can_speak = true
        channel.define_overwrite(study_role, 0, study_perms)
      end
    else
      delete_channel(server, channel) unless channel.nil?  or !channel.users.empty?
      # puts 'Less than 5 online members in #{row['name']}'
    end
  end
end

def handle_game_parties(server)
  server.voice_channels.find_all { |v| !v.name.include? 'Group ' and v.name.downcase.include? 'room ' }.each do |v|
    game_totals = Hash.new(0)
    user_count = v.users.length
    
    v.users.each do |u|
      next if u.game.nil?
      game_totals[u.game] += 1
    end
    
    next if user_count < 4
    
    game_totals.each do |game, t|
      next if t <= 2

      min = 0.75 # If only a few people are in the room, all must be playing the game
      percent = t / user_count.to_f

      next if percent < min

      v.name = "#{game} Party"
      server.text_channels.find { |c| c.id == $hierarchy[v.id] }.topic = "Private chat for all those in the voice channel '#{game} Party'."
      puts "Started #{game} Party room"
      event.bot.find_channel('gaming').first.send_message "@here A #{game} session has started. Join voice-channel **#{game} Party**!"
      break
    end
  end

  server.voice_channels.find_all { |v| !v.name.include? 'Group ' and v.name.end_with? ' Party' and v.users.empty? }.each do |v|
    v.delete
    sleep 0.5
  end
end<commit_msg>Fixed tiny game party bug<commit_after>def replace_mentions(message)
  message.strip!
  message.gsub! '**', ''
  message.gsub! '@everyone', '**everyone**'
  message.gsub! '@here', '**here**'
  words = message.split ' '
  done = []
  words.each_with_index do |w, i|
    w.sub!('(', '')
    w.sub!(')', '')
    w.sub!('"', '')
    if w.start_with? '<@' and w.end_with? '>'
      id = w.sub('<@!', '').sub('<@', '').sub('>', '') # Get ID 
      if !done.include? id and /\A\d+\z/.match(id)
        user = $db.query("SELECT username FROM students WHERE discord_id=#{id}")
        if user.count > 0
          user = user.first
          rep = "**@#{user["username"]}**" # replacement
          message.gsub! "<@#{id}>", rep # Only works when they don't have a nickname
          message.gsub! "<@!#{id}>", rep
        end
        done << id
      end
    end
  end

  return message.sub('@', '') if words.length == 1 and done == 1
  return message
end

def delete_channel(server, channel, count=1)
  return if channel.nil?

  puts "Deleting voice-channel #{channel.name} and associated #voice-channel"
  begin
    channel.delete
  rescue
    puts 'Failed to delete voice-channel'
  end
  begin
    server.text_channels.find{|t| t.id == $hierarchy[channel.id]}.delete
    $hierarchy.delete channel.id
  rescue => e
    puts 'Failed to find/delete associated #voice-channel'
    puts e
    if count < 2
      sleep 1.1
      delete_channel(server, channel, count + 1)
    end
  end
end

$groups = nil
def handle_group_voice_channels(server)
  if $groups.nil?
    $groups = $db.query('SELECT * FROM groups WHERE creator != "server"')
  end

  $groups.each do |row|
    group_role = server.roles.find{|r| r.id==Integer(row['role_id'])}
    next if group_role.nil?

    # Get count of online group members
    total_count = server.members.find_all { |m| m.role? group_role }.length
    count = server.online_members.find_all { |m| m.role? group_role }.length
    channel = server.voice_channels.find { |c| c.name == "Group #{row['name']}" }
    perms = Discordrb::Permissions.new
    perms.can_connect = true

    minimum = (total_count * 0.25).floor > 5 ? (total_count * 0.25).floor > minimum : 5 
    minimum = 10 if minimum > 10

    if count > minimum
      if channel.nil? and server.voice_channels.find { |c| c.name == row['name'] }.nil?
        puts "Opening group voice channel for #{row['name']}"
        channel = server.create_channel("Group #{row['name']}", 'voice')
        study_role = server.roles.find { |r| r.name == "studying" }
        channel.define_overwrite(group_role, perms, 0)
        Discordrb::API.update_role_overrides($token, channel.id, server.id, 0, perms.bits)
        study_perms = perms
        study_perms.can_speak = true
        channel.define_overwrite(study_role, 0, study_perms)
      end
    else
      delete_channel(server, channel) unless channel.nil?  or !channel.users.empty?
      # puts 'Less than 5 online members in #{row['name']}'
    end
  end
end

def handle_game_parties(server)
  server.voice_channels.find_all { |v| !v.name.include? 'Group ' and v.name.downcase.include? 'room ' }.each do |v|
    game_totals = Hash.new(0)
    user_count = v.users.length
    
    v.users.each do |u|
      next if u.game.nil?
      game_totals[u.game] += 1
    end
    
    next if user_count < 4
    
    game_totals.each do |game, t|
      next if t <= 2

      min = 0.75 # If only a few people are in the room, all must be playing the game
      percent = t / user_count.to_f

      next if percent < min

      v.name = "#{game} Party"
      server.text_channels.find { |c| c.id == $hierarchy[v.id] }.topic = "Private chat for all those in the voice channel '#{game} Party'."
      puts "Started #{game} Party room"
      server.text_channels.find { |c| c.name == 'gaming' }.send_message "@here A #{game} session has started. Join voice-channel **#{game} Party**!"
      break
    end
  end

  server.voice_channels.find_all { |v| !v.name.include? 'Group ' and v.name.end_with? ' Party' and v.users.empty? }.each do |v|
    v.delete
    sleep 0.5
  end
end
{'fraction_non_alphanumeric': 0.14884747425208436, 'fraction_numerical': 0.008092202059833251, 'mean_word_length': 2.788666976312123, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 23, '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': '2177424', 'n_tokens_mistral': 2853, 'n_tokens_neox': 2792, 'n_words': 753}