Having something happen when a particular phrase is written

There’s already a “swearing obscenely” action built in to Inform, which captures many of the most popular curse words, so you can just write new rules for it:

Instead of swearing obscenely, say "Naughty naughty."

(There’s some annoyance about the “swearing obscenely” action, since the Index doesn’t actually list its synonyms, but if you want one catchall response to swear words then it should work for you.)