You mention both mission-based and pilot-based moods. I humbly suggest starting just with the first one, and dealing with the second one later. The mission ones are both more immediately useful and more straightforward, I think, and will be easier to do.
Honestly, my first thought is to just allow "mood" to be a property of a mission that can be controlled via set-mood and clear-mood SEXPs. You can have more than one mood as appropriate for the current circumstances (so you basically track a list of active moods). And as you already mentioned, mood-keyed messages will only play if the current mission's mood list includes the right string. It may also be useful to have a +Not Mood property, for messages that are generally appropriate EXCEPT for specific times.
So for Diaspora, to prevent stuff like the above, you could do the following:
- Cocky pilot messages of praise for self and others have +not-mood: Somber.
- In the mission, track a variable called "somber-cooldown." This starts at 0.
- When a major friendly ship gets blown up, add some value to somber-cooldown and call set-mood "Somber".
- Have a SEXP that just fires off every second and decrements somber-cooldown until it is 0.
- Have a SEXP that fires when somber-cooldown reaches 0 to call clear-mood "Somber".
Or something like that. This is all pretty much off the top of my head.