The ability to flag and automatically deal with flags will solve two of your three example problems.
If a user is posting spam, your other users should be able to flag the posts. After a certain threshold is met for number of flags, the user can be ejected from the room. If possible the offending messages could be removed as well.
Flaming / Trolling
Generally this isn't as serious as spam, but can be handled the same way. If a user accumulates enough flags, they are ejected from the room. In this case, I don't think removing the messages is appropriate as it hides the trail of what was done. Unlike spam, it can be useful to go back and see this behavior.
This is going to fall into a few different categories.
- "Upsetting" topics: User is considering suicide; User is considering going to Vegas to marry the stripper he met in Reno; User is 17 and wants a baby now and is going to trick her boy friend to get said baby.
In all of these cases, what is the moderator to do? Ban the user? The user is sitting in your chat room, discussing their life choices. Be a human and talk to them. Obviously they are upset or confused or in need of guidance. Talk to them. If you can, steer the conversation to something constructive (suicide hotline, divorce statistics for elopes in Vegas, life outlook of single teenage mothers).
- "Controversial" topics: The United States should torture kittens and makes them into pudding; Spying on everyone is great; Moderators are power tripping people.
Again, what is the moderator to do? All of these can start as constructive conversations. Assuming they don't head into trolling territory, they could even become heated discussions. That is the point of your chat room. Discussion. A chat room can't be serious all the time. On the flip side, it's not always going to be fun and games either. Topics will be raised that people have opinions about. Let them discuss them.
If your software doesn't have the ability to raise flags, perhaps another automated system can be built. Can a bot be added that could perform moderation duties and accepts flags? Your other option is to trust more of your users and grant them moderation power.