What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Messenger Plus! for Live Messenger » Scripting » Window Close after Signout

Pages: (2): « First « 1 [ 2 ] Last »
Window Close after Signout
Author: Message:
absorbation
Elite Member
*****

Avatar

Posts: 3636
Reputation: 81
– / Male / Flag
Joined: Feb 2005
RE: Window Close after Signout
I suggest adding a timer to the script. Which the user can customise to what they want, e.g. make the window close after 10 seconds of the contact signing out. I personally would want it 10 minutes after a contact signed out. I often have tabs with tons of offline contacts who I stopped speaking to say, an hour ago :).

Adding a timer would make the script a lot better :P.
08-20-2006 10:28 PM
Profile PM Find Quote Report
Eagle_Erwin
Junior Member
**

Avatar
Eagle Erwin

Posts: 17
Reputation: 1
38 / Male / –
Joined: Aug 2006
O.P. RE: RE: Window Close after Signout
quote:
Originally posted by CookieRevised
quote:
Originally posted by Eagle_Erwin
I'm trying to make a script that closes the conversation-window when a contact signs out.

The code I have now:
(...)

But, this doesn't work. What is wrong in this script, or what script can I use to close the conversation window of the person that signs out?
There is too much wrong to list, so here is the fixed script. Things you got wrong are corrected in in red:

code:
function OnEvent_ContactSignout(Email) {
        var contact = Email;
        var chats = Messenger.CurrentChats;
        var e = new Enumerator(chats);
        for(; !e.atEnd(); e.moveNext()) {
                var chat = e.item();
                var f = new Enumerator(chat.Contacts);
                for(; !f.atEnd(); f.moveNext()) {

                        var contact1 = f.item();
                        if (contact == contact1.Email) {
                                Interop.Call("User32", "SendMessageA", chat.Handle, 0x10, 0, 0)
                                break;
                        }
                }
        }
}


But I also advise not to use this script as-is. 2 major drawbacks:
1) It will also close conversation with multiple contacts whenever 1 of those contacts signs out
2) Closing a convo automatically like that will make you often miss messages send by people

Thank you very much, never doubt about it: it works!

And about your advice: The script is used in a WLM-bot, so multiple contacts in one chat doesn't exists in this case. And about your second drawback: Because it is a bot, it doen't matter to ME what the last was the contact said, as long as the bot knows it. And the bot is fast enough, it will 'read' it ;)
08-20-2006 10:31 PM
Profile PM Web Find Quote Report
CookieRevised
Elite Member
*****

Avatar

Posts: 15519
Reputation: 173
– / Male / Flag
Joined: Jul 2003
Status: Away
RE: Window Close after Signout
IF you will never encounter multiple contacts in one chat you can remove the for...loop:

code:
for(; !f.atEnd(); f.moveNext()) {
      var contact1 = f.item();
      if (contact == contact1.Email) {
            Interop.Call("User32", "SendMessageA", chat.Handle, 0x10, 0, 0)
            break;
      }
}
thus, replace all the above with:
code:
var contact1 = f.item();
if (contact == contact1.Email) {
      Interop.Call("User32", "SendMessageA", chat.Handle, 0x10, 0, 0)
}
or thus simple one line:
code:
if (contact == f.item().Email) Interop.Call("User32", "SendMessageA", chat.Handle, 0x10, 0, 0)
.-= A 'frrrrrrrituurrr' for Wacky =-.
08-20-2006 10:49 PM
Profile PM Find Quote Report
Jesus
Scripting Contest Winner
****

Avatar
Koffie, my cat ;)

Posts: 623
Reputation: 15
37 / Male / Flag
Joined: Jul 2005
RE: RE: RE: Window Close after Signout
quote:
Originally posted by Eagle_Erwin
Thank you very much, never doubt about it: it works!

And about your advice: The script is used in a WLM-bot, so multiple contacts in one chat doesn't exists in this case. And about your second drawback: Because it is a bot, it doen't matter to ME what the last was the contact said, as long as the bot knows it. And the bot is fast enough, it will 'read' it ;)

Well for your purpose it is fine this way, but to make it really useful it should detect whether the window is "flashing" or not, so it doesn't close unread messages.
I know it's harder to code, but it would be neat to have that functionality :D
08-20-2006 11:19 PM
Profile PM Find Quote Report
mickael9
Full Member
***


Posts: 117
Reputation: 3
32 / Male / Flag
Joined: Jul 2005
RE: RE: Window Close after Signout
quote:
Originally posted by absorbation
I suggest adding a timer to the script. Which the user can customise to what they want, e.g. make the window close after 10 seconds of the contact signing out. I personally would want it 10 minutes after a contact signed out. I often have tabs with tons of offline contacts who I stopped speaking to say, an hour ago :).

Adding a timer would make the script a lot better :P.

Done :D
code:
var Timers     = {};
var TimerCount = 0;

function OnEvent_ContactSignout(sEmail)
{
    CloseWindows();
}
function OnEvent_ChatWndContactRemoved(ChatWnd, sEmail)
{
    CloseWindows();
}
function OnEvent_Timer(sTimerId)
{
    if (sTimerId.substr(0, 13) == "AutoCloseWin_")
    {       
        try
        {
            Interop.Call("User32","SendMessageW", Timers[sTimerId].Wnd.Handle, 16, 0, 0);
        }
        catch (e){};
        delete(Timers[sTimerId]);
        TimerCount--;
    }
    else if (sTimerId.substr(0, 19) == "AutoCloseWinCancel_")
    {
        var oParams      = Timers[sTimerId];
        var sOldText     = oParams.EditText;
        var nOldSelStart = oParams.SelStart;
        var nOldSelEnd   = oParams.SelEnd;
        var Wnd          = oParams.Wnd;
       
        Wnd.EditText = sOldText;
        Wnd.EditText_SetCurSel(nOldSelStart, nOldSelEnd);
        MsgPlus.DisplayToast("","Canceled !");
       
        delete(Timers[sTimerId]);
        TimerCount--;
    }
}
function OnEvent_ChatWndSendMessage(oChatWnd, sMessage)
{
    if (sMessage.substr(0,8) == "!cancel ")
    {
        var regex = /^!cancel ([0-9]+)/;
        var match = regex.exec(sMessage);
        if (!match)
            return sMessage;

        var sId = match[1];
        var sTimerId = "AutoCloseWin_" + sId;
       
        if (typeof(Timers[sTimerId]) != "undefined")
        {
            MsgPlus.CancelTimer(sTimerId);
            var Params = Timers[sTimerId];
            delete(Timers[sTimerId]);
           
            sTimerId = "AutoCloseWinCancel_" + sId;
            Timers[sTimerId] = Params;
            MsgPlus.AddTimer(sTimerId, 100);
            return '';
        }
    }
}
function CloseWindows()
{
    var chats = Messenger.CurrentChats;
    var e = new Enumerator(chats);

    for(; !e.atEnd(); e.moveNext())
    {
        var chat = e.item();
        var e2 = new Enumerator(chat.Contacts);
        var bCanClose = true;
        for (; !e2.atEnd(); e2.moveNext())
        {
            var contact = e2.item();
            bCanClose &= (contact.Status == 1);
        }
        if (bCanClose)
            CloseWindow(chat);
    }
}
function CloseWindow(oWnd)
{
    var nId      = (++TimerCount);
    var sTimerId = "AutoCloseWin_" + nId;
   
    var sText = "!cancel " + nId + " [This conversation will be closed in 10 seconds; send this text to cancel and restore the text typed here :)]";
   
    var nSelStart = oWnd.EditText_GetCurSelStart();
    var nSelEnd   = oWnd.EditText_GetCurSelEnd();
    var sOldText  = oWnd.EditText;
   
    var Params   = {"Wnd" : oWnd, "SelStart" : nSelStart, "SelEnd" : nSelEnd, "EditText" : oWnd.EditText};

    oWnd.EditText = sText;
    oWnd.EditText_SetCurSel(0, sText.length);
   
    Timers[sTimerId] = Params;
    MsgPlus.AddTimer(sTimerId, 10000);
}

.plsc File Attachment: Auto-close window.plsc (1.83 KB)
This file has been downloaded 105 time(s).

This post was edited on 08-21-2006 at 12:06 AM by mickael9.
08-20-2006 11:33 PM
Profile PM Web 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