The easiest way to do this would be through Webcore, which allows you to set up very complex rules. It’s very popular, and there are many people who will be glad to help you create the rules you want. They even have their own forum.
See the community FAQ (The topic title is a clickable link):
You might also be able to eventually do this with the official “rules API“ but it’s still in development and for now, Webcore will probably be easier to use.