Know that, if you seek friendship, look for Three qualities in a person:
The first is: Intellect. There is no benefit in friendship with a foolish person. An intelligent enemy is sometimes better than a foolish friend.
The second is: Good Character. Do not befriend someone who cannot restrain their anger or control their desire. Nor, someone who is a liar or who is greedy for this world.
The third is: Righteousness. Do not befriend someone who persists in major wrongdoings, for witnessing such actions on a regular basis makes wrongdoings seem insignificant.
These qualities rarely exist together. Keep interactions with your friends proportionate to the level of these qualities within them.
– Imam al-Ghazzali rahimahu Llah –