Shoutbox

Modifying a script? - 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: Modifying a script? (/showthread.php?tid=84931)

Modifying a script? by CalonMerc on 07-20-2008 at 08:25 AM

I am modifying the "Computer Details" script to have a few less features I don't use, and a feature I do use. The only issue is my friend wants to use the script as well and it doesn't work correctly for him. What I want it to do is display six different functions in one, or two, message(s). Right now it sends 6 messages in less than a second, which is fine for my laggy connection, but not for a blazing connection. (His sent two of six messages) Is there another command I should use or what?

Mostly the "DisplayAll" items are what I am mentioning.

code:
/* "THE BEER-WARE LICENSE" (Revision 42):<darktempler@gmail.com> wrote this file. As long as you retain this notice you can do whatever you want with my code. If we meet some day, and you think this code is worth it, you can buy me a beer in return - Matt Labrum (-dt-) */
/* Script edited by Calon Merc <arcadegamer2003@yahoo.com> [07/19/08] */
function OnEvent_Initialize(bMessengerStart){
    details = new ActiveXObject("WbemScripting.SWbemLocator");
    serv = details.ConnectServer();
}
function wmi(name,wrapAlways){
    var x = serv.ExecQuery('select * from ' + name);   
    var items = []
    for(var enume = new Enumerator(x);!enume.atEnd();enume.moveNext()){
        items[items.length] = enume.item()
    }
    if(items.length == 1){
        if(typeof(wrapAlways) != 'undefined'){
            return items;
        }else{
            return items[0];
        }
    }else
        return items;
}
function OnEvent_MenuClicked(sMenuId, location, wnd){
    switch(sMenuId){
        case 'OS_name' : wnd.SendMessage('OS: ' + OStitle());return;   
        case "HDD_total" : wnd.SendMessage('HDD: ' + HDDspace('total'));return;
        case "HDD_all" : wnd.SendMessage('HDD: ' + HDDspace('summary'));return;       
        case "Proc_name" : wnd.SendMessage('/noicon CPU Name: ' + getProcessor('name'));return;
        case "Proc_clock" : wnd.SendMessage('CPU Speed: ' + getProcessor('clock')+ ' GHZ') ;return;
        case "Proc_load" : wnd.SendMessage('CPU Load: ' + getProcessor('load') + '%');return;
        case "Proc_summary" : wnd.SendMessage('/noicon CPU: ' + getProcessor('summary') );return       
        case "Video_name" : wnd.SendMessage('GFX Name: ' + getGraphicCard('name') );return;
        case "Video_memory" : wnd.SendMessage('GFX memory: ' + getGraphicCard('memory') + 'MB' );return;
        case "Video_resolution" : wnd.SendMessage('Resolution: ' + getGraphicCard('resolution') + ' (' +getGraphicCard('refresh') + 'HZ)' );return;
        case "Video_summary" : wnd.SendMessage('GFX: ' + getGraphicCard('summary') );return;   
        case "Online" : wnd.SendMessage('Contacts Online: ' + getContacts('summary') );return;
        case "Uptime" : wnd.SendMessage('Uptime: ' + getUptime()); return;
        case "DisplayAll" : wnd.SendMessage('OS: ' + OStitle());wnd.SendMessage('HDD: ' + HDDspace('summary'));wnd.SendMessage('/noicon CPU: ' + getProcessor('summary') );wnd.SendMessage('GFX: ' + getGraphicCard('summary') );wnd.SendMessage('Contacts Online: ' + getContacts('summary') );wnd.SendMessage('Uptime: ' + getUptime()); return;   
    }   
    var name;
    if(name = sMenuId.match(/Soundcard_(.*)$/)){
        wnd.SendMessage('SoundCard : ' + name[1]);
        return;   
    }else if(name = sMenuId.match(/net_([^_]*)_(.*)$/)){
        if(name[2] == 'name'){
            wnd.SendMessage('Connection Name: ' + name[1]);
        }else{
            wnd.SendMessage('Connection '+name[2]+': ' + getConnectionInfo(name[1],name[2]));
        }
    }
}
//TAGS
function OnEvent_ChatWndSendMessage(chatWnd,message){
    //seems it will run the function even if it doesnt match... so we test for a match before the replace   
    if(message.match(/\(!OS\)/ig))message = message.replace(/\(!OS\)/ig, OStitle());
    if(message.match(/\(!HDDTOTAL\)/ig))message = message.replace(/\(!HDDTOTAL\)/ig,  HDDspace('total'));
    if(message.match(/\(!HDDSUMMARY\)/ig))message = message.replace(/\(!HDDSUMMARY\)/ig,  HDDspace('summary'));
    if(message.match(/\(!CPUNAME\)/ig))message = message.replace(/\(!CPUNAME\)/ig,getProcessor('name'));
    if(message.match(/\(!CPUCLOCK\)/ig))message = message.replace(/\(!CPUCLOCK\)/ig,getProcessor('clock'));
    if(message.match(/\(!CPULOAD\)/ig))message = message.replace(/\(!CPULOAD\)/ig,getProcessor('load'));
    if(message.match(/\(!CPUSUMMARY\)/ig))message = message.replace(/\(!CPUSUMMARY\)/ig,getProcessor('summary'));
    if(message.match(/\(!GFXNAME\)/ig))message = message.replace(/\(!GFXNAME\)/ig, getGraphicCard('name')+'MB');
    if(message.match(/\(!GFXMEMORY\)/ig))message = message.replace(/\(!GFXMEMORY\)/ig, getGraphicCard('memory'));
    if(message.match(/\(!GFXRES\)/ig))message = message.replace(/\(!GFXRES\)/ig, getGraphicCard('resolution'));
    if(message.match(/\(!GFXREFRESH\)/ig))message = message.replace(/\(!GFXREFRESH\)/ig, getGraphicCard('refresh') + 'HZ');
    if(message.match(/\(!GFXSUMMARY\)/ig))message = message.replace(/\(!GFXSUMMARY\)/ig, getGraphicCard('summary'));
    if(message.match(/\(!CONTACTSONLINE\)/ig))message = message.replace(/\(!CONTACTSONLINE\)/ig,getContacts('summary'));
    if(message.match(/\(!UPTIME\)/ig))message = message.replace(/\(!UPTIME\)/ig,getUptime());
    return message;
}
//getContacts function idea by lou_habs :P
function getContacts(type){
    var contacts = Messenger.MyContacts;   
    var online = 0;
    var offline = 0;
    var total = 0;
    var blocked = 0;
    var c;
    for(var enume = new Enumerator(contacts);!enume.atEnd();enume.moveNext()){
        total++;
        c = enume.item();
        if(c.Status != 1){
            online++;
        }else{
            offline++;
        }
        if(c.Blocked)blocked++;
    }
    var percent = Math.round((online / total) *100);   
    switch(type){
        case 'summary' : return online + '/' + total + ' (' + percent + '%)';   
    }
}
function getUptime(){
    var uptime = wmi('Win32_OperatingSystem').LastBootUpTime;   
    var start = dateTimetoRealTime(uptime).getTime();
    var now = new Date().getTime();
    var secs = Math.round((now - start) / 1000);
    var st = '';
    var days = removeDec(secs / 86400);   
    if(days >= 1){       
        if(days == 1){
            st += days + ' day ';
        }else{
            st += days + ' days ';
        }
        secs = secs - (days * 86400);
    }   
    var hours = removeDec(secs / 3600);
    if(hours >= 1){
        if(hours == 1){
            st += hours + ' hour ';
        }else{
            st += hours-1 + ' hours ';
        }
        secs = secs - (hours * 3600)
    }   
    var mins = removeDec(secs / 60);   
    if(mins >= 1){
        if(mins == 1){
            st += mins + ' minute ';
        }else{
            st += mins + ' minutes ';
        }
        secs = secs - (mins * 60);
    }
    st += 'and ' + secs + ' seconds'
    return st;
}
function removeDec(num){
    return String(num).split('.')[0];
}
function dateTimetoRealTime(date){
    //2006 06 04 14 15 53.500000+570
    dates = String(date);
    var year = parseInt(dates.substr(0,4));
    var month = parseInt(dates.substr(4,2))-1;
    var day = parseInt(dates.substr(6,2));   
    var hour = parseInt(dates.substr(8,2))-1;
    var min = parseInt(dates.substr(10,2))-1;
    var sec = parseInt(dates.substr(12,2))-1;   
    return new Date(year,month,day,hour,min,sec);
}
function getConnectionInfo(name ,type){
    //find the right card.
    var connections = wmi('Win32_PerfRawData_Tcpip_NetworkInterface');   
    for(var i=0;i<connections.length;i++){
        if(connections[i].Name == name){
            switch(type){
                case 'MB Received' : return Math.round((connections[i].BytesReceivedPersec /1024 /1024)*100)/100 + 'MB';
                case 'MB Sent' : return Math.round((connections[i].BytesSentPersec /1024 /1024)*100)/100 + 'MB';
                case 'summary' : return connections[i].Name + ' , Sent: ' + Math.round((connections[i].BytesSentPersec /1024 /1024)*100)/100 + 'MB Received: ' + Math.round((connections[i].BytesReceivedPersec /1024 /1024)*100)/100 + 'MB'
            }       
        }
    }
return 'unknown';
}
function getGraphicCard(type){
    var gfx = wmi('Win32_VideoController');
    switch(type){
        case "name" : return gfx.Name;
        case "memory" : return gfx.AdapterRAM / 1024 / 1024;
        case "resolution" : return gfx.CurrentHorizontalResolution + 'x' + gfx.CurrentVerticalResolution;
        case "refresh" :  return gfx.CurrentRefreshRate;
        case "summary" : return gfx.Name +' ' + gfx.AdapterRAM / 1024 / 1024 + 'MB @ ' + gfx.CurrentHorizontalResolution + 'x' + gfx.CurrentVerticalResolution + " (" + gfx.CurrentRefreshRate +"HZ)";
    }
}
function getProcessor(type){
    var proc = wmi('Win32_Processor');
    if(typeof(proc)=='array')proc=proc[0];
    switch(type){
        case "name" : return stripWhiteSpace(proc.Name);
        case "clock" : return Math.round((proc.CurrentClockSpeed /1000)*100)/100;
        case "load" : return proc.LoadPercentage;
        case "summary" : return stripWhiteSpace(proc.Name) + ', ' + Math.round((proc.CurrentClockSpeed /1000)*100)/100 + 'GHZ (' +proc.LoadPercentage +'% Load)';
    }
}
function stripWhiteSpace(str){
    str = str.replace(/^([ ]*)/,'');
    str = str.replace(/([ ]*)$/,'');
    return str;
}
function roundToTwoPoints(num){
    var st = String(num);   
    if(st.match('.')){
        var parts = st.split('.');
        parts[1] = parts[1].substr(0,1);
        return parts.join('.') + 0;
    }else{
        return num + 0;
    }
}
function HDDspace(type){
    var devices = wmi('Win32_LogicalDisk');   
    var freeSpace = 0;
    var totalSpace = 0;   
    var fs;
    var ts;
    var used;
    var string = '';   
    for(var i=0;i<devices.length;i++){
        if(devices[i].DriveType == 3){           
            ts = devices[i].Size / 1024 / 1024 /1024;
            fs = ts - (devices[i].FreeSpace /1024 /1024 /1024);           
            string += '[' + devices[i].Caption + ']: ' + Math.round(fs * 100)/100 + 'GB/' + Math.round(ts *100)/100 + 'GB ';           
            freeSpace += fs
            totalSpace += ts
        }
    }   
    switch(type){
        case 'total' : return Math.round(freeSpace)  + 'GB/' + Math.round(totalSpace) + 'GB';
        case 'summary' : return string;
    }
}
function OStitle(){
    var os = wmi('Win32_OperatingSystem');
    return os.Caption + ' - ' + os.CSDVersion + ' - ' + os.Version;
}
function OnGetScriptMenu(nLocation){   
    var sMenuInfo = "<ScriptMenu>"
    if(nLocation == 2){   
    sMenuInfo += '<SubMenu Label="OS">';
    sMenuInfo += '<MenuEntry Id="OS_name">Name</MenuEntry>';
    sMenuInfo += '</SubMenu>';   
    sMenuInfo += '<SubMenu Label="Hard Drive">';
    sMenuInfo += '<MenuEntry Id="HDD_total">Total</MenuEntry>';
    sMenuInfo += '<MenuEntry Id="HDD_all">Summary</MenuEntry>';
    sMenuInfo += '</SubMenu>';   
    sMenuInfo += '<SubMenu Label="Processor">';   
    sMenuInfo += '<MenuEntry Id="Proc_name">Name</MenuEntry>';
    sMenuInfo += '<MenuEntry Id="Proc_clock">Clock</MenuEntry>';
    sMenuInfo += '<MenuEntry Id="Proc_load">Load</MenuEntry>';
    sMenuInfo += '<Separator/>';
    sMenuInfo += '<MenuEntry Id="Proc_summary">Summary</MenuEntry>';
    sMenuInfo += '</SubMenu>';       
    sMenuInfo += '<SubMenu Label="Video Card">';
    sMenuInfo += '<MenuEntry Id="Video_name">Name</MenuEntry>';
    sMenuInfo += '<MenuEntry Id="Video_memory">Memory</MenuEntry>';
    sMenuInfo += '<Separator/>';
    sMenuInfo += '<MenuEntry Id="Video_resolution">Resolution</MenuEntry>';
    sMenuInfo += '<Separator/>';
    sMenuInfo += '<MenuEntry Id="Video_summary">Summary</MenuEntry>';
    sMenuInfo += '</SubMenu>';   
    sMenuInfo += '<SubMenu Label="Connections">';
    var connections = wmi('Win32_PerfRawData_Tcpip_NetworkInterface');   
    for(var i=0;i<connections.length;i++){
        sMenuInfo += '<SubMenu Label="'+ connections[i].Name +'" >';
        sMenuInfo += '<MenuEntry Id="net_' +connections[i].Name +'_name">Name</MenuEntry>';
        sMenuInfo += '<MenuEntry Id="net_' +connections[i].Name +'_MB Sent">MB sent</MenuEntry>';
        sMenuInfo += '<MenuEntry Id="net_' +connections[i].Name +'_MB Received">MB Received</MenuEntry>';
        sMenuInfo += '<Separator/>';
        sMenuInfo += '<MenuEntry Id="net_' +connections[i].Name +'_summary">Summary</MenuEntry>';
        sMenuInfo += '</SubMenu>';
    }   
    sMenuInfo += '</SubMenu>';   
    sMenuInfo += '<SubMenu Label="Sound Card">';
    var soundcards = wmi('Win32_SoundDevice',true);
    for(var i=0;i<soundcards.length;i++){
        sMenuInfo += '<MenuEntry Id="Soundcard_' +soundcards[i].Name +'">' + soundcards[i].Name +'</MenuEntry>';
    }   
    sMenuInfo += '</SubMenu>';   
    sMenuInfo += '<SubMenu Label="Contacts">';
    sMenuInfo += '<MenuEntry Id="Online">Online</MenuEntry>';
    sMenuInfo += '</SubMenu>';   
    sMenuInfo += '<MenuEntry Id="Uptime">Uptime</MenuEntry>';
    sMenuInfo += '<MenuEntry Id="DisplayAll">Show All</MenuEntry>';   
    }
    sMenuInfo +=    "</ScriptMenu>";
    return sMenuInfo;
}

RE: Modifying a script? by tribbium on 07-20-2008 at 02:01 PM

All you really need to do is replace all the wnd.SendMessages in your DisplayAll case with '\r\n'. The following code should replace the current case 'DisplayAll' and it should send one message with all the stats rather than 6:

quote:
Replace
case "DisplayAll" : wnd.SendMessage('OS: ' + OStitle());wnd.SendMessage('HDD: ' + HDDspace('summary'));wnd.SendMessage('/noicon CPU: ' + getProcessor('summary') );wnd.SendMessage('GFX: ' + getGraphicCard('summary') );wnd.SendMessage('Contacts Online: ' + getContacts('summary') );wnd.SendMessage('Uptime: ' + getUptime()); return;
With this
case "DisplayAll" : wnd.SendMessage('/noicon OS: ' + OStitle() + '\r\nHDD: ' + HDDspace('summary') + '\r\nCPU: ' + getProcessor('summary') + '\r\nGFX: ' + getGraphicCard('summary') + '\r\nContacts Online: ' + getContacts('summary') + '\r\nUptime: ' + getUptime()); return;


RE: Modifying a script? by CalonMerc on 07-20-2008 at 09:36 PM

Would they be on separate lines, or one single line? (In the single message, I mean)

Thank you, btw.


RE: Modifying a script? by tribbium on 07-21-2008 at 01:17 AM

You can go try it, they're on separate lines. '\r\n' = newline