Middle schooler brings gun to extracurricular school function