Shoutbox

Update number of contacts - 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: Update number of contacts (/showthread.php?tid=67572)

Update number of contacts by SnuZZer on 10-22-2006 at 03:04 PM

Hi.
I'm from Denmark and my english isn't good, but i'll try.
I have made a script (..or tried to make a script) which shows how many contacts there's online/offline, how many contacts there's on the list and how many windows there's open.
I have tried to make a timer which update the number in the personal message every second, but it doesn't works.

My script:

var Status = "fra";    // SÆTTER STATUS TIL/FRA
var oprindeligPB = Messenger.MyPersonalMessage;

function OpdaterPB()
{
    var online = 0;
    var offline = 0;
    var kontakter = Messenger.MyContacts;
    var e = new Enumerator(kontakter);
    for(; !e.atEnd(); e.moveNext()) {
        var kontakt = e.item();
        if(kontakt.Status == "1") {
            offline++;
        } else {
            online++;
        }
    }
    var alle = (online + offline);
    var igang = Messenger.CurrentChats.Count;
    Messenger.MyPersonalMessage = "Online: " + online + " | Offline: " + offline + " | I alt: " + alle + " | Åbne vinduer: " + igang;
    AddTimer("1",100);
}

// NÅR DU LOGGER PÅ : START
function OnEvent_Initialize(MessengerStart)
{   
    if (Status == "til")
    {
        opdaterPB();
    }
}
// NÅR DU LOGGER PÅ : SLUT

// NÅR DU LOGGER AF : START
function OnEvent_Uninitialize(MessengerExit)
{
    Messenger.MyPersonalMessage = oprindeligPB;
}
// NÅR DU LOGGER AF : SLUT

// NÅR EN KONTAKTER LOGGER PÅ : START
function OnEvent_ContactSignin()
{
    if (Status == "til")
    {
        opdaterPB();
    }
}
// NÅR EN KONTAKTER LOGGER PÅ : SLUT

// NÅR EN KONTAKTER LOGGER AF : START
function OnEvent_ContactSignout()
{
    if (Status == "til")
    {
        opdaterPB();
    }
}
// NÅR EN KONTAKTER LOGGER AF : SLUT

// NÅR ET VINDUE ÅBNES : START
function OnEvent_ChatWndCreated()
{
    OpdaterPB();
}
// NÅR ET VINDUE ÅBNES : SLUT

// NÅR ET VINDUE LUKKES : START
function OnEvent_ChatWndDestroyed()
{
    OpdaterPB();
}
// NÅR ET VINDUE LUKKES : SLUT

// TJEKKER TIMER : START
function OnEvent_Timer(id)
{
    if (id == "1")
    {
        opdaterPB();
    }
}
// TJEKKER TIMER : SLUT

// LAVER MENU : START
function OnGetScriptMenu(Location)
{
    ScriptMenu = "<ScriptMenu>";
    ScriptMenu += "<MenuEntry Id=\"tilfra\">";
    if (Status == "fra")
    {
        ScriptMenu += "Slå til";
    } else {
        ScriptMenu += "Slå fra";
    }
    ScriptMenu += "</MenuEntry>";
    ScriptMenu += "</ScriptMenu>";
    return ScriptMenu;
}
// LAVER MENU : SLUT

// VALGT MENU : START
function OnEvent_MenuClicked(MenuItemId,Location,OriginWnd)
{
    switch(MenuItemId)
    {
        case "tilfra":
            if (Status == "fra")
            {
                Status = "til";
                MsgPlus.DisplayToast("Kontakt information", "Kontakt information er slået til.");
                opdaterPB();
            } else {
                Status = "fra";
                MsgPlus.DisplayToast("Kontakt information", "Kontakt information er slået fra.");
                Messenger.MyPersonalMessage = oprindeligPB;
                CancelTimer(1);
            }
            break;
    }
}
// VALGT MENU : SLUT


Thanks in advance.
- Simon


RE: Update number of contacts by Spunky on 10-22-2006 at 03:25 PM

CancelTimer(1); should be MsgPlus.CancelTimer("1");

Your timer interval is set for 100 which is 10 times a second. (I'm pretty sure that below minimum. Use 1000 instead.)

Thats all i noticed by having a quick look


RE: Update number of contacts by SnuZZer on 10-22-2006 at 03:46 PM

Hi.
It doesn't work.
The timer is only necessary beacuse the numbers of open chat windows is falling if you close the window with the button, and it doesn't fall if you close the window with "ESC".


RE: Update number of contacts by Spunky on 10-22-2006 at 03:50 PM

As far as I can tell it should work. There is no point updating the PSM every second though as there is a limit to how often it updates (6 or times a minute I think :s) so any faster and nobody notices anyway.

My PSM+ script just uses the Messenger.CurrentChats.Count everytime a window is created or destroyed and it works fine


RE: Update number of contacts by SnuZZer on 10-22-2006 at 03:56 PM

Hi.
Ohh.. I'm confused. I'm also use Messenger.CurrentChats.Count, and actually it works when i press "ESC" (:-S) But when there aren't any windows open it still says that there is one open.


RE: Update number of contacts by Spunky on 10-22-2006 at 05:33 PM

That's a problem I came across... it's wierd. Just use:

code:
--Messenger.CurrentChats.Count


Thats should take 1 away from the value. It makes it correct then all the time.
RE: Update number of contacts by SnuZZer on 10-22-2006 at 05:48 PM

Hi.
I'm sorry. I don't understand.

Like this?

code:
var igang = --Messenger.CurrentChats.Count;

Or like this?
code:
var igang = Messenger.CurrentChats.Count--;

RE: Update number of contacts by Spunky on 10-22-2006 at 06:03 PM

should be the first one. If that method doesn't work, use:

code:
var igang = Messenger.CurrentChats.Count-1;


EDIT: [/code]
RE: Update number of contacts by matty on 10-22-2006 at 06:34 PM

code:
var _enabled = new Boolean(false);
var oprindeligPB;

function _update_mypersonalmessage(_conversations) {
    var _online = 0;
    var _offline = 0;
    var _total = 0;
   
    for(var e = new Enumerator(Messenger.MyContacts); !e.atEnd(); e.moveNext()) {
       
        if(e.item().Status == 1) { _offline++; }
        else { _online++; }
    }
    var _total = (_online + _offline);
    Messenger.MyPersonalMessage = "Online: " + _online + " | Offline: " + _offline + " | I alt: " + _total + " | Åbne vinduer: " + _conversations;
}

function OnEvent_Initialize(bMessengerStart){
    try{
        oprindeligPB = Messenger.MyPersonalMessage;
    }catch (e){}
}

function OnEvent_SignInReady(sEmail) {
    if (oprindeligPB != Messenger.MyPersonalMessage){ oprindeligPB = Messenger.MyPersonalMessage; }
    if (_enabled == true) { _update_mypersonalmessage(Messenger.Chats.Count); }
}

function OnEvent_Uninitialize(bMessengerExit) {
    Messenger.MyPersonalMessage = oprindeligPB;
}

function OnEvent_ContactSignin(){
    if (_enabled == true) { _update_mypersonalmessage(Messenger.Chats.Count); }
}
function OnEvent_ContactSignout() {
    if (_enabled == true) { _update_mypersonalmessage(Messenger.Chats.Count); }
}

function OnEvent_ChatWndCreated(){
    if (_enabled == true) { _update_mypersonalmessage(Messenger.Chats.Count); }
}

function OnEvent_ChatWndDestroyed() {
    if (_enabled == true) { _update_mypersonalmessage(Messenger.Chats.Count-1); }
}

function OnGetScriptMenu(Location) {
    ScriptMenu = "<ScriptMenu>";
    ScriptMenu += "<MenuEntry Id=\"tilfra\">";
    if (Status == "fra") { ScriptMenu += "Slå til"; }
    else { ScriptMenu += "Slå fra"; }
    ScriptMenu += "</MenuEntry>";
    ScriptMenu += "</ScriptMenu>";
    return ScriptMenu;
}
function OnEvent_MenuClicked(MenuItemId,Location,OriginWnd) {
    switch(MenuItemId) {
        case "tilfra":
            if (_enabled == false) {
                _enabled = true;
                MsgPlus.DisplayToast("Kontakt information", "Kontakt information er slået til.");
                _update_mypersonalmessage(Messenger.Chats.Count);
            } else {
                _enabled = false;
                MsgPlus.DisplayToast("Kontakt information", "Kontakt information er slået fra.");
                Messenger.MyPersonalMessage = oprindeligPB;
            }
        break;
    }
}

Would look something like this.
RE: Update number of contacts by SnuZZer on 10-22-2006 at 07:04 PM

Hi.
If i minus one (var igang = Messenger.CurrentChats.Count-1;) i must open to windows before the numbers of open chat windows change.


Hi again.
Maybe it is because i turn the counter on in a chatwindow and then it counts that window and don't want to minus it... In a way. :-P .. Does that sounds possible?
RE: Update number of contacts by matty on 10-22-2006 at 10:20 PM

The .Count property when a window is created is properly incremented. When a window is closed the function is called before the .Count property is properly decremented so we need to -1.


RE: Update number of contacts by SnuZZer on 10-23-2006 at 01:11 PM

Hi.
I really can't get i work! If I minus one I must open to window before it counts the windows, and if I don't minus one it allways says that there are one window open.


RE: Update number of contacts by Spunky on 10-23-2006 at 01:14 PM

You need to put the Messenger.CurrentChats.Count-1 in the OnEvent_ChatWndDestroyed event. If it only counts when you open a window, you're using the OnEvent_ChatWndDestroyed event which needs to remain as Messenger.CurrentChats.Count


RE: Update number of contacts by SnuZZer on 10-23-2006 at 01:27 PM

Hej.
I update the number of open windows with af function, wich means that it allways minus one.
This is my code (with danish comments):

code:
var Status = "fra";    // SÆTTER STATUS TIL/FRA
var oprindeligPB = Messenger.MyPersonalMessage; // GEMMER OPRINDELIGE PERSONLIGE BESKED

function OpdaterPB()
{
    if (Status == "til")
    {
        var online = 0;
        var offline = 0;
        var kontakter = Messenger.MyContacts;
        var e = new Enumerator(kontakter);
        for(; !e.atEnd(); e.moveNext()) {
            var kontakt = e.item();
            if(kontakt.Status == "1") {
            offline++;
            } else {
                online++;
            }
        }
        var alle = (online + offline);
        var igang = Messenger.CurrentChats.Count - 1;
        Messenger.MyPersonalMessage = "Online: " + online + " | Offline: " + offline + " | I alt: " + alle + " | Åbne vinduer: " + igang;
    }
}

// NÅR DU LOGGER PÅ : START
function OnEvent_Initialize(MessengerStart)
{   
    opdaterPB();
}
// NÅR DU LOGGER PÅ : SLUT

// NÅR DU LOGGER AF : START
function OnEvent_Uninitialize(MessengerExit)
{
    Messenger.MyPersonalMessage = oprindeligPB;
}
// NÅR DU LOGGER AF : SLUT

// NÅR EN KONTAKTER LOGGER PÅ : START
function OnEvent_ContactSignin()
{
    opdaterPB();
}
// NÅR EN KONTAKTER LOGGER PÅ : SLUT

// NÅR EN KONTAKTER LOGGER AF : START
function OnEvent_ContactSignout()
{
    opdaterPB();
}
// NÅR EN KONTAKTER LOGGER AF : SLUT

// NÅR ET VINDUE ÅBNES : START
function OnEvent_ChatWndCreated()
{
    OpdaterPB();
}
// NÅR ET VINDUE ÅBNES : SLUT

// NÅR ET VINDUE LUKKES : START
function OnEvent_ChatWndDestroyed()
{
    OpdaterPB();
}
// NÅR ET VINDUE LUKKES : SLUT

// LAVER MENU : START
function OnGetScriptMenu(Location)
{
    ScriptMenu = "<ScriptMenu>";
    ScriptMenu += "<MenuEntry Id=\"tilfra\">";
    if (Status == "fra")
    {
        ScriptMenu += "Slå til";
    } else {
        ScriptMenu += "Slå fra";
    }
    ScriptMenu += "</MenuEntry>";
    ScriptMenu += "</ScriptMenu>";
    return ScriptMenu;
}
// LAVER MENU : SLUT

// VALGT MENU : START
function OnEvent_MenuClicked(MenuItemId,Location,OriginWnd)
{
    switch(MenuItemId)
    {
        case "tilfra":
            if (Status == "fra")
            {
                Status = "til";
                MsgPlus.DisplayToast("Kontakt tæller", "Kontakt tæller er slået til.");
                opdaterPB();
            } else {
                Status = "fra";
                MsgPlus.DisplayToast("Kontakt tæller", "Kontakt tæller er slået fra.");
            }
            break;
    }
}
// VALGT MENU : SLUT