Paraphrased from The Yoga Sutras of Patanjali, Sutra 33:
If someone is happy, offer them friendship (share their happiness)
If someone is unhappy, offer them compassion (lighten their suffering)
If someone is virtuous, offer them delight (celebrate their goodness)
If someone is wicked, offer them disregard (give them no reward)In this way, you can yourself be calm and untroubled.
Or something like that …