Shoutbox

SP3 - MsgPlus Script Problem - 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: SP3 - MsgPlus Script Problem (/showthread.php?tid=72464)

SP3 - MsgPlus Script Problem by bigbob85 on 03-08-2007 at 09:57 PM

I found out about this problem when I couldn't figure out why my script wasn't working.

NOTE : Only happens with the new SP3 Timestamps

If you are using a OnEvent_ChatWndReceiveMessage (and possibly other functions aswel) and you compare the Origin to Messenger.MyName to find out if the message was from you. It will get Messenger.MyName alright, but when  it gets the origin, it includes the time stamp.

So, Origin != Messenger.MyName

Anyone know any possible fixes?


RE: SP3 - MsgPlus Script Problem by matty on 03-08-2007 at 10:07 PM

CookieRevised's reply to [Fix] Problem with OnEvent_ChatWndRecieveMessage's Origin


RE: SP3 - MsgPlus Script Problem by Felu on 03-09-2007 at 04:07 AM

quote:
Originally posted by Matty
CookieRevised's reply to [Fix] Problem with OnEvent_ChatWndRecieveMessage's Origin
quote:
Originally posted by Matty
it gets the origin, it includes the time stamp.
So you'll need to put the TimeStamp before the Message aswell. It is stored here -> HKEY_LOCAL_MACHINE\SOFTWARE\iAvatars.com\StuffPlug\Messenger.MyUserID\szTimestamp. Place that before the ChatOnly Name and then use Regular Expressions to match the HH mm ss, etc :).
RE: SP3 - MsgPlus Script Problem by markee on 03-09-2007 at 01:18 PM

Looks like there is going to be conflicts every time TB adds more features that change the messages received..... Let us hope that TB fore-warns us of possible upcoming problems so we ca release updates for scripts to minimise conflicts (it would be nice, but I doubt it will happen).  But this still doesn't fix the problem with old scripts that don't get updated and when people do not update their scripts as well.

Maybe we should just hope and pray that TB doesn't make any updates that might cause problems instead....


RE: SP3 - MsgPlus Script Problem by J-Thread on 03-09-2007 at 03:35 PM

I don't think TB is aware of this problem, but I doubt he will change anything because it will be hard to implement timestamps in a different way...


RE: SP3 - MsgPlus Script Problem by TheGuruSupremacy on 03-09-2007 at 04:43 PM

Try to use this code

code:
function OnEvent_ChatWndReceiveMessage(ChatWnd,Origin,Message,MessageKind )
{var Contacts = ChatWnd.Contacts
var Contact = new Array()
var e = new Enumerator(Contacts)
var i =0
for(;!e.atEnd();e.moveNext()){
Contact[i] = e.item().Name
Debug.Trace(Contact[i])
i++}
for(var y=0;y<Contact.length;y++){
if (Origin==Contact[y]){
ChatWnd.SendMessage("OOOOOOOOOOOOOOOK")}}
};



RE: SP3 - MsgPlus Script Problem by Matti on 03-09-2007 at 05:37 PM

quote:
Originally posted by TheGuruSupremacy
Try to use this code
Note that this will only work to look for received messages sent by someone else. You can't use it to modify the way your own messages are displayed on your side, because ChatWnd.Contacts only include the contacts in a chat window except the active Messenger user. Therefore, you can't use that to compare it to your name.
RE: SP3 - MsgPlus Script Problem by TheGuruSupremacy on 03-09-2007 at 05:41 PM

quote:
Originally posted by Mattike
quote:
Originally posted by TheGuruSupremacy
Try to use this code
Note that this will only work to look for received messages sent by someone else. You can't use it to modify the way your own messages are displayed on your side, because ChatWnd.Contacts only include the contacts in a chat window except the active Messenger user. Therefore, you can't use that to compare it to your name.

I don't think it....It's true that ChatWnd.Contacts only include the contacts in a chat window except the active Messenger user but you can compare with your name using syntax if....else...

Function Example:

code:
function OnEvent_ChatWndReceiveMessage(ChatWnd,Origin,Message,MessageKind )
{var Contacts = ChatWnd.Contacts
var Contact = new Array()
var e = new Enumerator(Contacts)
var AmI = new Boolean()
var i =0
Debug.Trace("Chatting with ")
for(;!e.atEnd();e.moveNext()){
Contact[i] = e.item().Name
Debug.Trace(Contact[i])
i++}
for(var y=0;y<Contact.length;y++){
if (Origin==Contact[y]){
AmI=false}else{
AmI=true
break}
}
Debug.Trace("Message: " + Message)
Debug.Trace("Have i written this message???" + AmI)
}


However i have checked that it can not work with timestamp because not only your name is modificated but also contact's name...you can use this code

code:
function OnEvent_ChatWndReceiveMessage(ChatWnd,Origin,Message,MessageKind )
{var time = new Date()
var hours = time.getHours()
var minutes = time.getMinutes()
var seconds = time.getSeconds()
var Myformattednick = "[" + hours + "." + minutes + "." + seconds + "]" + " " + Messenger.MyName
Debug.Trace(Myformattednick)
Debug.Trace(Origin)
if (Myformattednick!=Origin){
//do anything
}else{//do else
}
}

RE: RE: SP3 - MsgPlus Script Problem by markee on 03-10-2007 at 04:48 AM

quote:
Originally posted by TheGuruSupremacy
code:
function OnEvent_ChatWndReceiveMessage(ChatWnd,Origin,Message,MessageKind )
{var time = new Date()
var hours = time.getHours()
var minutes = time.getMinutes()
var seconds = time.getSeconds()
var Myformattednick = "[" + hours + "." + minutes + "." + seconds + "]" + " " + Messenger.MyName
Debug.Trace(Myformattednick)
Debug.Trace(Origin)
if (Myformattednick!=Origin){
//do anything
}else{//do else
}
}


You can't use that, just use a regular expression to omit the time stamp when the registry setting for StuffPlug has the feature enabled.  It is also probable wise to add this to CookieRevised's code that was linked to earlier.

EDIT: The reason for the regular expression to omit the time stamp (probably a replace method is best) is because the seconds/minutes/hours could change between when stuffplug adds the time stamp and the script removes it (eg. stuff plug adds the time at 23:59:59 (and 999 milliseconds) at the 31st of december then when your script gets to it, it will already be a new year and ever value has changed and will not be the same).  I hope this gives you explanation rather than just saying it is wrong.

I do stress to add this to CookieRevised's code and to also check to see if the registry setting has the feature enabled before going through your method.
RE: SP3 - MsgPlus Script Problem by bigbob85 on 03-10-2007 at 05:20 AM

I'd assume its the same (or similar) time tags to MsgPlus Live.

quote:
Originally posted by http://www.msgpluslive.net/help/registry/
Time Tags

Enclose text in single quotes. Example: "HH':'mm" will produce "11:40" for 11:40am.

    * h - Hours with no leading zero for single-digit hours; 12-hour clock.
    * hh - Hours with leading zero for single-digit hours; 12-hour clock.
    * H - Hours with no leading zero for single-digit hours; 24-hour clock.
    * HH - Hours with leading zero for single-digit hours; 24-hour clock.
    * m - Minutes with no leading zero for single-digit minutes.
    * mm - Minutes with leading zero for single-digit minutes.
    * s - Seconds with no leading zero for single-digit seconds.
    * ss - Seconds with leading zero for single-digit seconds.
    * t - One character time-marker string, such as A or P.
    * tt - Multicharacter time-marker string, such as AM or PM.

Date Tags

Enclose text in single quotes. Example: "dd'/'MM" will produce "18/10" for October 18th.

    * d - Day of month as digits with no leading zero for single-digit days.
    * dd - Day of month as digits with leading zero for single-digit days.
    * ddd - Day of week as a three-letter abbreviation.
    * dddd - Day of week as its full name.
    * M - Month as digits with no leading zero for single-digit months.
    * MM - Month as digits with leading zero for single-digit months.
    * MMM - Month as a three-letter abbreviation.
    * MMMM - Month as its full name.
    * yy - Year as last two digits, but with leading zero for years less than 10.
    * yyyy - Year represented by full four digits.

Is there any time("h") sort of function?
RE: SP3 - MsgPlus Script Problem by markee on 03-10-2007 at 05:29 AM

Actually if you want the format I would recommend you look at this page.


RE: SP3 - MsgPlus Script Problem by bigbob85 on 03-10-2007 at 05:42 AM

Thats the page I was looknig for. Kept getting search errors.

I'll see if I can make a regexp for it, but I think I'll get problems. So in the mean time, could you post the first one, if you can do regexp?


RE: SP3 - MsgPlus Script Problem by matty on 03-10-2007 at 07:01 AM

quote:
Originally posted by Felu
quote:
Originally posted by Matty
CookieRevised's reply to [Fix] Problem with OnEvent_ChatWndRecieveMessage's Origin
quote:
Originally posted by Matty
it gets the origin, it includes the time stamp.
So you'll need to put the TimeStamp before the Message aswell. It is stored here -> HKEY_LOCAL_MACHINE\SOFTWARE\iAvatars.com\StuffPlug\Messenger.MyUserID\szTimestamp. Place that before the ChatOnly Name and then use Regular Expressions to match the HH mm ss, etc :).
Obviously I am aware that the link is for Chat Only Name and he needs Time Stamp... well he should be smart enough to figure it out.
RE: SP3 - MsgPlus Script Problem by bigbob85 on 03-10-2007 at 07:08 AM

I found a way to do it.
Replace tt, before t in the time stamp string.


RE: SP3 - MsgPlus Script Problem by bigbob85 on 03-12-2007 at 09:57 AM

code:
if (!Origin.match(Messenger.MyName))
{
    // The msg wasn't from you, do stuff here.
}

Seems to work alright, is it flawed in a major way?
RE: SP3 - MsgPlus Script Problem by Felu on 03-12-2007 at 10:04 AM

quote:
Originally posted by bigbob85
code:
if (!Origin.match(Messenger.MyName))
{
    // The msg wasn't from you, do stuff here.
}

Seems to work alright, is it flawed in a major way?
What if the chat only name is entirely different from my name or if the contact has a nickname similar to mine?
RE: RE: SP3 - MsgPlus Script Problem by TheGuruSupremacy on 03-12-2007 at 10:49 AM

quote:
Originally posted by Felu
What if the chat only name is entirely different from my name or if the contact has a nickname similar to mine?


See Cookie Code
RE: SP3 - MsgPlus Script Problem by Felu on 03-12-2007 at 10:57 AM

quote:
Originally posted by TheGuruSupremacy
See Cookie Code
I pointed that towards Bob's code.
quote:
Originally posted by bigbob85
if (!Origin.match(Messenger.MyName))
{
    // The msg wasn't from you, do stuff here.
}

RE: SP3 - MsgPlus Script Problem by TheGuruSupremacy on 03-12-2007 at 11:01 AM

quote:
Originally posted by Felu
I pointed that towards Bob's code.

Eheh okie...However as you know bob's code if contact have chat name nick only or nick similar to yours doesn't work fine
RE: SP3 - MsgPlus Script Problem by Jesus on 03-12-2007 at 12:13 PM

Can't you just use the second code Cookie posted?

code:
var aSent = new Array();

function OnEvent_ChatWndSendMessage(ChatWnd, Message) {
    aSent[ChatWnd.Handle] = Message;
}

function OnEvent_ChatWndReceiveMessage(ChatWnd, Origin, Message, MessageKind) {
    if (aSent[ChatWnd.Handle] === Message) {
        delete aSent[ChatWnd.Handle];
    } else {
        // a contact sent the message, so do whatever
    }
}
doesn't check for any nicknames at all...
RE: SP3 - MsgPlus Script Problem by bigbob85 on 03-12-2007 at 09:21 PM

I tried to use that, but it didnt seem to work :S....

Cookies first code though, returns the Messenger.MyName if no chat only name was found. And then with some regexp from dt.

code:
if (!Origin.match(new RegExp("^" + sMyChatName.replace(/([\[\]\|\)\(\*\?\+\.\$\/])/g, '\\$1')))){
    // Yeah yeah yeah, do stuff
}

It is retruning my name :
The "YTN3rd" Bradley
as
/^The "YTN3rd" Bradley/

And the .match( thing is no longer matching them. Any ideas?
RE: SP3 - MsgPlus Script Problem by kOMPlEXX on 03-20-2007 at 12:52 AM

code:
function GetUserName ( Origin )
{
var regPath = "HKEY_LOCAL_MACHINE\\SOFTWARE\\iAvatars.com\\StuffPlug\\" +Messenger.MyUserId +"\\szTimestamp";
var Shell = new ActiveXObject("WScript.Shell");
var szTimestamp;

  if ( szTimestamp = Shell.RegRead ( regPath ) )
    { var nOrigin;
      nOrigin = Origin.substr(szTimestamp.length+1);
      return ( nOrigin );
    }
  return ( Origin );
}

This returns a cleaned Username :D
RE: SP3 - MsgPlus Script Problem by bigbob85 on 03-20-2007 at 05:50 AM

You've been a member since 04 and this was your first post? :P

Nice work, looks reasonable. I'll test it later.


RE: RE: SP3 - MsgPlus Script Problem by Jesus on 03-20-2007 at 11:59 AM

quote:
Originally posted by kOMPlEXX
code:
function GetUserName ( Origin )
{
var regPath = "HKEY_LOCAL_MACHINE\\SOFTWARE\\iAvatars.com\\StuffPlug\\" +Messenger.MyUserId +"\\szTimestamp";
var Shell = new ActiveXObject("WScript.Shell");
var szTimestamp;

  if ( szTimestamp = Shell.RegRead ( regPath ) )
    { var nOrigin;
      nOrigin = Origin.substr(szTimestamp.length+1);
      return ( nOrigin );
    }
  return ( Origin );
}

This returns a cleaned Username :D

In some cases, it does indeed. In other cases, it won't.
Take a look at the link markee posted earlier in this thread (this page). It shows the format used for the timestamp. If you look at that page you can see that 1 character isn't always replaced with 1 new character. So the length property of the registry string is not a reliable way to remove the timestamp. I thought of another way, but it needs some more testing before I post it.


edit: here it is, there must be a better/easier way to do it with regular expressions, but I suck at them so I did it this way...
code:
function UnStamp(StampedNick)
{
    if (StampedNick != "")
    {
        try
        {
            if (Messenger.MyUserId != undefined)
            {
                var WshShell = new ActiveXObject("WScript.Shell");
                var SPRegPath = "HKLM\\SOFTWARE\\iAvatars.com\\StuffPlug\\"
                try
                {
                    var Splug = true;
                    Splug = WshShell.RegRead(SPRegPath + "DisabledFor" + Messenger.MyUserId) == 0;
                } catch (e) {}
                if (Splug)
                {
                    if (WshShell.RegRead(SPRegPath + Messenger.MyUserId + "\\TimeStamps"))
                    {
                        var StampFormat = WshShell.RegRead(SPRegPath + Messenger.MyUserId + "\\szTimestamp");
                        if (StampFormat != "")
                        {
                            var Nick = StampedNick.split(" ").slice(StampFormat.split(" ").length).join(" ");
                            return Nick;
                        }
                    }
                }
            }
        } catch (e) {}
    }
    return StampedNick;
}

RE: SP3 - MsgPlus Script Problem by bigbob85 on 03-20-2007 at 10:25 PM

Jesus, what is a case when kOMPlEXXs script wont work?

Works for me. Dosnt work for a chat only name... yet...


RE: SP3 - MsgPlus Script Problem by Jesus on 03-20-2007 at 11:24 PM

quote:
Originally posted by bigbob85
Jesus, what is a case when kOMPlEXXs script wont work?

Works for me. Dosnt work for a chat only name... yet...
quote:
Originally posted on the StuffPlug 3 forums
TimeStamp format as follows:
H = 24 Hour
HH = 24 Hour with leading zero
h = 12 Hour
hh = 12 Hour with leading zero
m = Minutes
mm = Minutes with leading zero
s = Seconds
ss = Seconds with leading zero
t = A/P
tt = AM/PM
Now, say szTimeStamp = "[H:mm]", which has a length of 6.
In this timestamp, H can be any number from 0 to 23 and mm can be any number from 00 to 59.
As long as it's before 10am, H will be replaced with 1 character, eg [9:55], with a length of 6. However, 10 minutes later, it will be [10:05], with a length of 7.
As a result, using this method could get you an extra space before the nickname, or even the last few characters of the timestamp.

The method I used first checks whether timestamps are enabled, and if they are, it counts the amount of spaces in the szTimeStamp registry value and removes the amount of spaces plus one space-separated character blocks from the beginning of the string. Spaces don't get replaced by stuffplug and there's always a space between the timestamp and the nickname. If timestamps are disabled or empty, it returns the string you put in.
RE: SP3 - MsgPlus Script Problem by bigbob85 on 03-21-2007 at 02:02 AM

Ah, to true.

code:
var Nick = StampedNick.split(" ").slice(StampFormat.split(" ").length).join(" ");

What if your timestamp was "H:MM |"
RE: SP3 - MsgPlus Script Problem by Jesus on 03-21-2007 at 10:46 AM

I think you mean "H:mm |", anyway that wouldn't matter.
then Nick would be made like this:
StampFormat = "H:mm |";
aStampFormat = StampFormat.split(" ");           //array: H:mm,|
StampLength = StampFormat.split(" ").length;  //value: 2

StampedNick = "11:59 | <insert nick here>";
aStampedNick = StampedNick.split(" ");            //array: 11:59,|,<insert,nick,here>

aNick = aStampedNick.slice(StampLength);     //remove the timestamp (in this case 2 space-separated character blocks, since StampLength = 2)
Nick = aNick.join(" ");                                       //put the nickname back together in a string.

put all these steps together and you get
var Nick = StampedNick.split(" ").slice(StampFormat.split(" ").length).join(" ");

I hope that makes it clear :)


RE: SP3 - MsgPlus Script Problem by bigbob85 on 04-05-2007 at 12:28 PM

Forgot to come back here >_<

Yeah that makes sense.
Ill try write it into a class file, that removes timestamp and returns original name original WLM name.