MDL-40048 mod_chat: Replacing add_to_log with new events

For this to be done properly, a new function to send the message
and trigger the event has been created. Following that a
data generator for chat, and some unit tests.