This is going into an infinite loop because OnEvent_ChatWndReceiveMessage is called when you send a message too! What you will want to do is compare the Origin parameter to your current display name. That will tell you if you are sending the message, or if its coming from your contact. One word of caution is that there are addons that can set a chat-only name (like StuffPlug) so you will also have to compare the chat only name as it is stored in the registry if you plan on using that feature any time in the future.