[Help] Received Text and Origin. - Printable Version
-Shoutbox (https://shoutbox.menthix.net)
+-- Forum: MsgHelp Archive (/forumdisplay.php?fid=58)
+--- Forum: Messenger Plus! for Live Messenger (/forumdisplay.php?fid=4)
+---- Forum: Scripting (/forumdisplay.php?fid=39)
+----- Thread: [Help] Received Text and Origin. (/showthread.php?tid=84529)
[Help] Received Text and Origin. by uNDeRGRouND99 on 06-26-2008 at 03:27 PM
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.
RE: [Help] Received Text and Origin. by CookieRevised on 06-26-2008 at 04:33 PM
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...
RE: [Help] Received Text and Origin. by uNDeRGRouND99 on 06-26-2008 at 05:48 PM
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?
RE: [Help] Received Text and Origin. by Matti on 06-27-2008 at 08:03 AM
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.
- Add a new global variable and name it "JustSentAMessage" or something. Set its value to false.
- 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).
- In your OnEvent_Timer event, check if the timer ID matches "ThisWasMyMessage" and if it matches, set JustSentAMessage to false.
- 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! I'm infected! )
RE: RE: [Help] Received Text and Origin. by uNDeRGRouND99 on 06-27-2008 at 08:47 PM
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.
RE: [Help] Received Text and Origin. by roflmao456 on 06-27-2008 at 10:30 PM
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;
}
}
RE: [Help] Received Text and Origin. by Matti on 06-28-2008 at 08:48 AM
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?
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
}
RE: [Help] Received Text and Origin. by uNDeRGRouND99 on 06-29-2008 at 10:26 PM
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();
}
RE: [Help] Received Text and Origin. by roflmao456 on 06-30-2008 at 02:05 AM
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...
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.
RE: [Help] Received Text and Origin. by CookieRevised on 06-30-2008 at 06:55 AM
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)?
RE: [Help] Received Text and Origin. by markee on 06-30-2008 at 08:43 AM
quote: Originally posted by CookieRevised
It would do exactlythe same thing (but even better)?
It would be better if we had the option of putting in events from scripts like we do with the event logger though. I'm not sure what benefit it would give, but it is just that bit more flexibility....
RE: [Help] Received Text and Origin. by uNDeRGRouND99 on 06-30-2008 at 09:01 PM
Sorry, i've fixed. Now work.
code: function OnEvent_ChatWndReceiveMessage(ChatWnd, Origin, Message, MsgKind)
{
var e = new Enumerator(ChatWnd.Contacts);
var Cnt = e.item();
Contact = Cnt.Email;
if(Origin != Messenger.MyName)
AddLineToFile (FileName + ".txt", GetTime + " - " + Contact + ": " + Message);
}
Thanks for all
RE: [Help] Received Text and Origin. by CookieRevised on 06-30-2008 at 11:09 PM
Use that code in a group conversation and you'll see it will not work properly.
You need to use the Origin parameter to get to the correct email.
Also, as someone already pointed out, the GetTime variable will always return the same time. You should make a function out of it which always gets the current time (not just when the script is started when you start Messenger).
|