<commit_before>$hierarchy = {}
$user_teachers = {}
$OPEN_ROOM_NAME = '[New Room]'.freeze

$voice_states = {}

# UTILITY METHODS
def get_rand_teacher(user)
  teachers = $user_teachers[user.id].nil? ? $db.query("SELECT staffs.last_name FROM staffs JOIN courses ON courses.teacher_id=staffs.id JOIN students_courses ON students_courses.course_id=courses.id JOIN students ON students.id=students_courses.student_id WHERE students.discord_id=#{user.id}").map { |t| t['last_name'] }.uniq : $user_teachers[user.id]
  $user_teachers[user.id] = teachers
  randteacher = teachers.sample

  randteacher
end

def room_exists?(server, name)
  !server.voice_channels.find { |r| r.name == name }.nil?
end

def set_voice_channel_name(server, user, room)
  # Get a random teacher name
  randteacher = get_rand_teacher(user)
  randteacher = 'Zero' if user.id == server.owner.id

  count = 0
  while room_exists?(server, "Room #{randteacher}")
    randteacher = get_rand_teacher(user)
    count += 1
    if count == teachers.length
      randteacher += ' II'
      break
    end
  end
  # Finally rename the voice channel
  room.name = "Room #{randteacher}"
end

def handle_room(event, r)
  server = event.server

  if r.users.empty? and r.name != $OPEN_ROOM_NAME<commit_msg>Temporary fix<commit_after>$hierarchy = {}
$user_teachers = {}
$OPEN_ROOM_NAME = '[New Room]'.freeze

$voice_states = {}

# UTILITY METHODS
def get_rand_teacher(user)
  teachers = $user_teachers[user.id].nil? ? $db.query("SELECT staffs.last_name FROM staffs JOIN courses ON courses.teacher_id=staffs.id JOIN students_courses ON students_courses.course_id=courses.id JOIN students ON students.id=students_courses.student_id WHERE students.discord_id=#{user.id}").map { |t| t['last_name'] }.uniq : $user_teachers[user.id]
  $user_teachers[user.id] = teachers
  randteacher = teachers.sample

  randteacher
end

def room_exists?(server, name)
  !server.voice_channels.find { |r| r.name == name }.nil?
end

def set_voice_channel_name(server, user, room)
  # Get a random teacher name
  randteacher = get_rand_teacher(user)
  randteacher = 'Zero' if user.id == server.owner.id

  count = 0
  while room_exists?(server, "Room #{randteacher}")
    randteacher = get_rand_teacher(user)
    count += 1
    if count == 7
      randteacher += ' II'
      break
    end
  end
  # Finally rename the voice channel
  room.name = "Room #{randteacher}"
end

def handle_room(event, r)
  server = event.server

  if r.users.empty? and r.name != $OPEN_ROOM_NAME
{'fraction_non_alphanumeric': 0.12049639711769415, 'fraction_numerical': 0.0020016012810248197, 'mean_word_length': 4.468271334792123, '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': '5292624', 'n_tokens_mistral': 904, 'n_tokens_neox': 882, 'n_words': 204}