Ibn Jamaa’ah said:
“The student of knowledge should not mix except with either those he can benefit, or can benefit from. And if he is offered the friendship of one who will waste his time with him, will not benefit him, will not benefit from him, and will not assist him in reaching his objective, he should politely end the relationship from the start before it progresses to something deeper, as when something becomes established, it becomes more difficult to change it. There is a phrase that is constantly on the tongues of the Fuqahaa’, “Repelling something is easier than removing it.
So, if he requires someone to befriend, let that person be righteous, religious, pious, wary, intelligent, full of benefit, having little evil, good at complying, rarely conflicting, reminding him if he forgets, cooperating with him when he is reminded, helpful if he is in need, and comforting if he is in distress.”
[Tadhkirat As-Saami’ Wal-Mutakallim, p. 83]