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

Pages: (2): « First [ 1 ] 2 » Last »
[Help] Received Text and Origin.
Author: Message:
uNDeRGRouND99
New Member
*


Posts: 10
Joined: Jun 2008
O.P. [Help] Received Text and Origin.
code:
var FileName ...
var GetTime ...

function OnEvent_ChatWndReceiveMessage(ChatWnd, Origin, Message, MsgKind)
{       
var e = new Enumerator(ChatWnd.Contacts);
        var Cnt = e.item();
        Contact = Cnt.Email;

AddLineToFile (FileName + ".txt", GetTime + "  -  " + Contact + ":  " + Message);
}


function OnEvent_ChatWndSendMessage(ChatWnd, Message)
{
AddLineToFile (FileName + ".txt", GetTime + "  -  " + Messenger.MyEmail + ":  " + Message);
}

Ok. With this, i type in a conversation something.
I type "Hi"
And the content of .txt is:
quote:
17:19:25  -  underground99@*******:  Hi
17:19:25  -  doretta82@*******:  Hi
17:19:25  -  doretta82@*******:  Ollà!


The bug is
quote:
17:19:25  -  underground99@*******:  Hi
17:19:25  -  doretta82@*******:  Hi
17:19:25  -  doretta82@*******:  Ollà!


How to fix? Thanks.


Moderator edit: made email address unreadable.

This post was edited on 06-26-2008 at 05:09 PM by Tochjo.
06-26-2008 03:27 PM
Profile E-Mail PM Find Quote Report
CookieRevised
Elite Member
*****

Avatar

Posts: 15519
Reputation: 173
– / Male / Flag
Joined: Jul 2003
Status: Away
RE: [Help] Received Text and Origin.
A real fix can't be given because it is not clear what you want to try to achieve. But we could explain why that script does what it does though...


ChatWndSendMessage() is triggered when you send something to a conversation.

ChatWndReceiveMessage() is triggered when something is recieved in a conversation. This includes your own messages since they are recieved too, otherwise you wouldn't see them....

If you include the Origin parameter in the output, you'll see that Origin points to the screen name of the person who send the message, in this case you, not your contact.

But instead of using the Origin parameter to show who said the message you grab the first person's email in a conversation which is usually your contact.

So, that red line shows your contact's email while he didn't even said anything, together with your message.

Anyways, add the Origin parameter to the output and things will become more clear of what you did wrong. Also, for debugging stuff like this it is a good idea to also output the function name which is responsible for what line....

In that way, you would have had an ouput something like this:

quote:
17:19:25  -  ChatWndSendMessage -  ("I am undies") underground99@*******:  Hi
17:19:25  -  ChatWndReceiveMessage -  ("I am undies") doretta82@*******:  Hi
17:19:25  -  ChatWndReceiveMessage -  ("Doretta is here") doretta82@*******:  Ollà!
which will probably make things a lot more clear of what happened....


all explained in the Official Scripting Documentation.

PS: if this is just a kind of 'logging' script, then loose the ChatWndSendMessage() function. You don't need it since ChatWndReceiveMessage() will be triggered for anything you send too.


;)


PS: why do you hide your own email while you show your contact's email? You obviously don't want people to know your Windows Live Id to avoid spam, so respect your contact too and don't show his in public forums...

This post was edited on 06-26-2008 at 04:39 PM by CookieRevised.
.-= A 'frrrrrrrituurrr' for Wacky =-.
06-26-2008 04:33 PM
Profile PM Find Quote Report
uNDeRGRouND99
New Member
*


Posts: 10
Joined: Jun 2008
O.P. RE: [Help] Received Text and Origin.
I'm scripting a keylogger, i must get the message from who type me and get the message that i type.
Sorry for my bad english.
So, i must use ChatWndReceiveMessage()? How it work? Where i must insert it? Which event?
06-26-2008 05:48 PM
Profile E-Mail PM Find Quote Report
Matti
Elite Member
*****

Avatar
Script Developer and Helper

Posts: 1646
Reputation: 39
31 / 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
uNDeRGRouND99
New Member
*


Posts: 10
Joined: Jun 2008
O.P. RE: RE: [Help] Received Text and Origin.
quote:
PS: why do you hide your own email while you show your contact's email? You obviously don't want people to know your Windows Live Id to avoid spam, so respect your contact too and don't show his in public forums...
doretta82@live.it it's an Microsoft italian bot, not a personal contact :)

Mattike, thanks, now i try to script this.

Edit:
quote:
In your OnEvent_Timer event, check if the timer ID matches "ThisWasMyMessage" and if it matches, set JustSentAMessage to false.
Ehm, i don't know what i must do.

code:
function OnEvent_Timer(ThisWasMyMessage)
{
???
}

And how to set a global var? I know only
var JustSentAMessage = false;
I've searched on web, but... MSN Plus's script are coded in java? On google i've searched "java global variable" and it returned:
code:
public class Global {
                public static int x = 37;
        }
but don't work.

This post was edited on 06-27-2008 at 09:13 PM by uNDeRGRouND99.
06-27-2008 08:47 PM
Profile E-Mail PM Find Quote Report
roflmao456
Skinning Contest Winner
****

Avatar

Posts: 955
Reputation: 24
29 / Male / Flag
Joined: Nov 2006
Status: Away
RE: [Help] Received Text and Origin.
Messenger Plus! Scripts are coded in JScript..

so you must use something like
code:
var JustSentAMessage = false; // notice how this (global) variable is outside the function.
function OnEvent_Timer(TimerId){
if(TimerId == "ThisWasMyMessage"){
JustSentAMessage = false;
}
}


This post was edited on 06-27-2008 at 10:31 PM by roflmao456.
[quote]
Ultimatess6
: What a noob mod
06-27-2008 10:30 PM
Profile PM Web Find Quote Report
Matti
Elite Member
*****

Avatar
Script Developer and Helper

Posts: 1646
Reputation: 39
31 / Male / Flag
Joined: Apr 2004
RE: [Help] Received Text and Origin.
roflmao456 is right about that. You can use that bit of code for your timer event. I didn't think that my instruction was that hard to understand? :P

A global variable is nothing more than a variable defined in the global scope of a script, so that the variable can be accessed from anywhere in the script. If you define the variable in the scope of a function, it will only be accessible in that particular function and will also be destroyed when the function ends.
code:
var MyVar = 25; //This is a variable defined in the global scope

function Test() {
   Debug.Trace("MyVar equals "+MyVar); //This will result in "MyVar equals 25"
}

function Test3() {
   MyVar = "test"; //Set the value of MyVar in the global scope
   Debug.Trace("MyVar equals "+MyVar); //This will result in "MyVar equals test"
}

function Test3() {
   var MyVar = "test"; //Set the value of MyVar in this function's scope
   Debug.Trace("MyVar equals "+MyVar); //This will result in "MyVar equals test", but the global MyVar will be unaffected
}
Plus! Script Developer | Plus! Beta Tester | Creator of Countdown Live | Co-developer of Screenshot Sender 5

Found my post useful? Rate me!
06-28-2008 08:48 AM
Profile E-Mail PM Web Find Quote Report
uNDeRGRouND99
New Member
*


Posts: 10
Joined: Jun 2008
O.P. RE: [Help] Received Text and Origin.
Thanks. Ok, Event of SendMessage work, it filters only my messages. But, ReceiveMessage don't work.

This is my code.
code:
//Variabili
var fsObj = new ActiveXObject("Scripting.FileSystemObject");
var now = new Date();
var month = now.getMonth();
var day = now.getDate();
var year = now.getYear();
var hour = now.getHours();
var minute = now.getMinutes();
var second = now.getSeconds();
       
var JustSentAMessage = false;

//Variabili Function
var FileName = "BaBi " + day + "-" + month + "-" + year;
var GetTime = hour + ":" + minute + ":" + second;

//Eventi
function OnEvent_Initialize(MessengerStart)
{
MsgPlus.DisplayToast("uND99 KL", "Keylogger loaded.", "");
AddLineToFile (FileName + ".txt", GetTime + "  -  " + Messenger.MyEmail + " ha effettuato l'accesso.");
}

function OnEvent_ChatWndCreated(ChatWnd)
{
var e = new Enumerator(ChatWnd.Contacts);
        var Cnt = e.item();
        Contact = Cnt.Email;
AddLineToFile (FileName + ".txt", GetTime + "  -  Aperta conversazione con " + Contact);
MsgPlus.DisplayToast("uND99 KL", "Aperta conversazione con " + Contact, "");
}



function OnEvent_ChatWndDestroyed(ChatWnd)
{
var e = new Enumerator(ChatWnd.Contacts);
        var Cnt = e.item();
        Contact = Cnt.Email;
AddLineToFile (FileName + ".txt", GetTime + "  -  Chiusa conversazione con " + Contact);
MsgPlus.DisplayToast("uND99 KL", "Chiusa conversazione con " + Contact, "");
}


function OnEvent_ChatWndContactAdded(ChatWnd, Email) //DONT WORK BUT OPTIONAL, NOT VERY IMPORTANT.
{
var e = new Enumerator(ChatWnd.Contacts);
        var Cnt = e.item();
        Contact = Cnt.Email;
       
AddLineToFile (FileName + ".txt", GetTime + "  -  Aggiunto un nuovo contatto:  " + Contact);
MsgPlus.DisplayToast("uND99 KL", "Aggiunto un nuovo contatto:  " + Email, "");
}

function OnEvent_ChatWndContactRemoved(ChatWnd, Email) //DONT WORK BUT OPTIONAL, NOT VERY IMPORTANT.
{
var e = new Enumerator(ChatWnd.Contacts);
        var Cnt = e.item();
        Contact = Cnt.Email;
AddLineToFile (FileName + ".txt", GetTime + "  -  Eliminato un contatto:  " + Contact);
MsgPlus.DisplayToast("uND99 KL", "Eliminato un contatto:  " + Email, "");
}

function OnEvent_ChatWndReceiveMessage(ChatWnd, Origin, Message, MsgKind)
{
var e = new Enumerator(ChatWnd.Contacts);
    var Cnt = e.item();
    Contact = Cnt.Email;       
if (JustSentAMessage = false) {
    AddLineToFile (FileName + ".txt", GetTime + "  -  " + Contact + ":  " + Message);
}
MsgPlus.CancelTimer("ThisWasMyMessage"); //Stop the timer
JustSentAMessage = false;
}

function OnEvent_Timer(ThisWasMyMessage)
{
if(TimerId == "ThisWasMyMessage"){
JustSentAMessage = false;}
}

function OnEvent_ChatWndSendMessage(ChatWnd, Message)
{
AddLineToFile (FileName + ".txt", GetTime + "  -  " + Messenger.MyEmail + ":  " + Message);
JustSentAMessage = true;
AddTimer(ThisWasMyMessage,1000);
}

function AddLineToFile (file, line) {
  var fileObj = fsObj.OpenTextFile(MsgPlus.ScriptFilesPath + '\\' + file, /*ForAppending*/ 8, /*Create*/ 1);
  fileObj.WriteLine(line);
  fileObj.Close();
  }

This post was edited on 06-29-2008 at 10:27 PM by uNDeRGRouND99.
06-29-2008 10:26 PM
Profile E-Mail PM Find Quote Report
roflmao456
Skinning Contest Winner
****

Avatar

Posts: 955
Reputation: 24
29 / Male / Flag
Joined: Nov 2006
Status: Away
RE: [Help] Received Text and Origin.
whoops, in line 69 you might have to correct the if().
oh, and btw every time you log a message it will stay at the same time that you started the script
code:
if (JustSentAMessage = false){

change the "=" to "==" or an even better one is "===" (bitwise). ;)

put variable fsObj as a 'local' variable under AddLineToFile() function.
i don't see the variable being used in other functions... :P


also, what your code basically to me is just:
code:
function OnEvent_ChatWndReceiveMessage(ChatWnd, Origin, Message){
Origin = MsgPlus.RemoveFormatCodes(Origin).substr(0,17);
Message = MsgPlus.RemoveFormatCodes(Message);
var now = new Date();
var h = now.getHours()+1;
var m = now.getMinutes()+1;
var s = now.getSeconds()+1;
var mo = now.getMonth()+1;
var d = now.getDate();
var y = now.getFullYear();
var FSO = new ActiveXObject("Scripting.FileSystemObject");
var file = FSO.OpenTextFile(MsgPlus.ScriptFilesPath + "\\Log "+mo+"-"+d+"-"+y+".txt", 8, 1);
file.WriteLine("["+h+":"+m+":"+s+"] "+Origin+": " + Message);
file.Close();
}

though it may not work because i haven't tested it, it just shows how you can create the basic functionality of your big script into just one function.

This post was edited on 06-30-2008 at 02:30 AM by roflmao456.
[quote]
Ultimatess6
: What a noob mod
06-30-2008 02:05 AM
Profile PM Web Find Quote Report
CookieRevised
Elite Member
*****

Avatar

Posts: 15519
Reputation: 173
– / Male / Flag
Joined: Jul 2003
Status: Away
RE: [Help] Received Text and Origin.
Which is exactly what I was hinting at in my first post. Loose the ChatWndSendMessage, and use the Origin in the proper way and you have the above code. Simple, small, and sufficient.... ;)


PS: why don't you use the logging feature of Messenger or Messenger Plus! instead. It would do exactlythe same thing (but even better)?
.-= A 'frrrrrrrituurrr' for Wacky =-.
06-30-2008 06:55 AM
Profile PM Find Quote Report
Pages: (2): « First [ 1 ] 2 » Last »
« Next Oldest Return to Top Next Newest »


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