What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Messenger Plus! for Live Messenger » Scripting » [Help] Received Text and Origin.

[Help] Received Text and Origin.
Author: Message:
Matti
Elite Member
*****

Avatar
Script Developer and Helper

Posts: 1646
Reputation: 39
32 / Male / Flag
Joined: Apr 2004
RE: [Help] Received Text and Origin.
Let me first explain what I've learnt by studying that piece of code.
quote:
You are trying to make a logger for sent and received messages. You try to do this by logging the messages you sent and those which you received. To get the name of the contact of the ones you received, you get the name of the first Contact object in ChatWnd.Contacts.
The problem lies in the fact that OnEvent_ChatWndReceiveMessage will also be triggered when you send a message yourself! Basically, that event is triggered when something is added to the chat history, and because you can see your own messages too when you sent them, it'll also be triggered for your own messages.

The solution isn't quite easy, due to many factors causing some trouble. You want to check if the Origin of the received message equals your nickname to prevent logging your messages twice. However, what if you were using StuffPlug's Chat-Only name? Or what if you have enabled StuffPlug's timestamps in front of nicknames? Maybe you've set a custom nickname for the contact you're chatting with which (coincidentally) matches your nickname?

The Scripting Documentation gives a simple workaround which will work in as good as all cases:
quote:
Events > OnEvent_ChatWndReceiveMessage > Remarks
Because Messenger Plus! analyses received messages only when they reach the chat window, it is not possible to determine exactly from which contact the message came from. However, several methods can be used to guess if the message was actually sent by the current user. For example, to determine whether or not the personalized status messages should be sent when a message is received, Messenger Plus! compares the time of the last ChatWndSendMessage event with the current time. If it is less than 1 second, the message is considered to come from the current user and the previously recorded time is reset. Even if this method of analysis can seem too simplistic, it works in almost every scenario as it is extremely rare to receive a message sent by a contact between the time the "Send" button was pressed and the time the message of the current user was added to the window (as Messenger does not wait to receive a reply from the server before adding the message to the history control).
I have tried this method myself and, if you implement it correctly, it will work just fine.
  1. Add a new global variable and name it "JustSentAMessage" or something. Set its value to false.
  2. In your OnEvent_ChatWndSendMessage, after you did all the stuff you wanted to do, set "JustSentAMessage" to true and add a timer (name it something like "ThisWasMyMessage") with an interval of 1 second (1000 milliseconds).
  3. In your OnEvent_Timer event, check if the timer ID matches "ThisWasMyMessage" and if it matches, set JustSentAMessage to false.
  4. In your OnEvent_ChatWndReceiveMessage, check if JustSentAMessage is true. If it is, don't log it. If it is false, log it. After the check, cancel the timer and set the JustSentAMessage to false, so the script can continue logging messages again.
    code:
    if(JustSentAMessage) {
       //This message was sent by yourself -- DO NOT LOG THIS!
    } else {
       //This message must have been sent by a contact -- LOG THIS!
    }
    MsgPlus.CancelTimer("ThisWasMyMessage"); //Stop the timer
    JustSentAMessage = false; //Set the global to false
(Oh dear, I'm starting to make posts which are nearing the size of Cookie's posts! :O I'm infected! :|)

This post was edited on 06-27-2008 at 08:07 AM by Matti.
Plus! Script Developer | Plus! Beta Tester | Creator of Countdown Live | Co-developer of Screenshot Sender 5

Found my post useful? Rate me!
06-27-2008 08:03 AM
Profile E-Mail PM Web Find Quote Report
« Next Oldest Return to Top Next Newest »

Messages In This Thread
[Help] Received Text and Origin. - by uNDeRGRouND99 on 06-26-2008 at 03:27 PM
RE: [Help] Received Text and Origin. - by CookieRevised on 06-26-2008 at 04:33 PM
RE: [Help] Received Text and Origin. - by uNDeRGRouND99 on 06-26-2008 at 05:48 PM
RE: [Help] Received Text and Origin. - by Matti on 06-27-2008 at 08:03 AM
RE: RE: [Help] Received Text and Origin. - by uNDeRGRouND99 on 06-27-2008 at 08:47 PM
RE: [Help] Received Text and Origin. - by roflmao456 on 06-27-2008 at 10:30 PM
RE: [Help] Received Text and Origin. - by Matti on 06-28-2008 at 08:48 AM
RE: [Help] Received Text and Origin. - by uNDeRGRouND99 on 06-29-2008 at 10:26 PM
RE: [Help] Received Text and Origin. - by roflmao456 on 06-30-2008 at 02:05 AM
RE: [Help] Received Text and Origin. - by CookieRevised on 06-30-2008 at 06:55 AM
RE: [Help] Received Text and Origin. - by markee on 06-30-2008 at 08:43 AM
RE: [Help] Received Text and Origin. - by uNDeRGRouND99 on 06-30-2008 at 09:01 PM
RE: [Help] Received Text and Origin. - by CookieRevised on 06-30-2008 at 11:09 PM


Threaded Mode | Linear Mode
View a Printable Version
Send this Thread to a Friend
Subscribe | Add to Favorites
Rate This Thread:

Forum Jump:

Forum Rules:
You cannot post new threads
You cannot post replies
You cannot post attachments
You can edit your posts
HTML is Off
myCode is On
Smilies are On
[img] Code is On