What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Messenger Plus! for Live Messenger » Scripting » help me debugging this script

help me debugging this script
Author: Message:
Wakaki
Junior Member
**

Avatar

Posts: 30
31 / Male / –
Joined: Jan 2007
O.P. RE: RE: help me debugging this script
quote:
Originally posted by Mattike
It would be a terrible idea to do that every 5 seconds. You could better listen for a file modification every 30 seconds and if it changed, change your variables.

Take a look at the code snippet here, and you can make something like:
code:
var ListenInterval = 30000; //30 seconds

//This has been token from the code snippet, all credits go to OcuS
var FileModificationDates = [];
function ListenForFileModification(FilePath, Callback) {
   var DateLastModified = GetFileModificationDate(FilePath);
   if (DateLastModified === false) return false;

   Callback = Callback || function(FilePath) {};
   FileModificationDates[FilePath] = {
      file : FilePath,
      date : DateLastModified,
      callback : Callback
   }
   MsgPlus.AddTimer('LSTN_FileModification_' + FilePath, ListenInterval);
   return true;
}

function GetFileModificationDate(FilePath) {
   var FileSystem = new ActiveXObject('Scripting.FileSystemObject');
   if (!FileSystem.FileExists(FilePath)) return false;
   var File = FileSystem.GetFile(FilePath);
   return '' + File.DateLastModified + '';
}

function OnEvent_Timer(TimerId) {
   var TimerMatchLSTN = TimerId.match(/^LSTN_FileModification_(.+)$/);
   if (TimerMatchLSTN.length && FileModificationDates[TimerMatchLSTN[1]]) {
      var FilePath = TimerMatchLSTN[1];
      var DateLastModified = GetFileModificationDate(FilePath);
      if (DateLastModified === false) return false;

      if (DateLastModified != FileModificationDates[FilePath].date){
         FileModificationDates[FilePath].callback(FilePath);
         FileModificationDates[FilePath] = undefined;
         return true;
      }
      MsgPlus.AddTimer('LSTN_FileModification_' + FilePath, ListenInterval);
      return true;
   }
}

function OnEvent_Initialize(MessengerStart) {
//Here comes your original stuff...
//And here are our listening function calls!
ListenForFileModification(MsgPlus.ScriptFilesPath + '\\defwelcomemsg.txt', SetDef);
ListenForFileModification(MsgPlus.ScriptFilesPath + '\\defgoodbyemsg.txt', SetDef);

}

function SetDef(FilePath) {
   //I'll use a regular expression for this one, it checks if the file's right and captures the welcome or

goodbye
   if(FilePath.test(/\\def(welcome|goodbye)msg\.txt$/i) {
      //We'll open our file
      var File = new ActiveXObject("Scripting.FileSystemObject").OpenTextFile(FilePath, 1);
      //Here we'll see what it has captured and save it in the right variable
      switch(RegExp.$1) {
         case "welcome":
            DefWelcomeMsg = File.ReadAll();
            break;
         case "goodbye":
            DefGoodbyeMsg = File.ReadAll();
            break;
      }
      //At the end, we'll close the file
      File.Close();
      //That's all folks!
   }
}



I'm too nice for these guys... :sad:


thank you thank you thank you

i will test it in the morning tommorow

p.s. youre right youre too nice:D:wicked:
[Image: wakakipt2.png]
02-01-2007 09:23 PM
Profile PM Find Quote Report
« Next Oldest Return to Top Next Newest »

Messages In This Thread
help me debugging this script - by Wakaki on 01-30-2007 at 11:49 AM
RE: help me debugging this script - by markee on 01-30-2007 at 12:18 PM
RE: help me debugging this script - by Wakaki on 01-30-2007 at 12:26 PM
RE: RE: help me debugging this script - by tryxter on 02-01-2007 at 01:28 PM
RE: help me debugging this script - by roflmao456 on 01-30-2007 at 10:15 PM
RE: help me debugging this script - by Wakaki on 01-31-2007 at 02:03 PM
RE: help me debugging this script - by Wakaki on 02-01-2007 at 11:55 AM
RE: help me debugging this script - by Wakaki on 02-01-2007 at 02:53 PM
RE: help me debugging this script - by Wakaki on 02-01-2007 at 03:10 PM
RE: help me debugging this script - by tryxter on 02-01-2007 at 06:02 PM
RE: help me debugging this script - by Matti on 02-01-2007 at 06:24 PM
RE: RE: help me debugging this script - by Wakaki on 02-01-2007 at 09:23 PM


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