What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Messenger Plus! for Live Messenger » Scripting » [not really a release/help] my first script

[not really a release/help] my first script
Author: Message:
andrey
elite shoutboxer
****

Avatar

Posts: 795
Reputation: 48
– / Male / Flag
Joined: Aug 2004
O.P. Tongue  [not really a release/help] my first script
Yeah, this has been my first attempt evar at J(ava)script and programming in general..

And the result of five(:rolleyes:) days learning Jscript from scratch is: "auto-send ISI" :tongue:

The (pretty simple) idea was, that when I type a command in the conversation window, the script gets the Internal Sound Identifier for a Custom Sound (e.g. #CC506B2EDBC4) from the clipboard (if it's present) and sends the sound to the contact.
(might be useful when you're extremely lazy, browsing mpsounds.net and you want to send just one sound from a huge soundpack (the ISI is called Sound ID over there, btw))

Maybe that's not such a big thing, (not very useful either), but it's an achievement for me, and I'm pretty happy that I got it working :happy:

I'll post the code below, and ask you to comment on it (style, efficiency and so on)

Commands:
enable script: +isi
disable script: -isi
send sound: isi
code:
var enabled = false;
var ISI;


function OnEvent_ChatWndSendMessage(ChatWnd, Message) {
   if(Message == "+isi") {
      enabled = true;
      return("");
   }
   if(Message == "-isi") {
      enabled = false;
      return("");
   }
   if(Message == "isi") {
         if(enabled == true)
            return(startISI());
   }
}


function startISI() {
   readClipboard();
   if(matchISI() == true) {
         return(Message = "/sound " + ISI);
      } else {
            return("");
      }
}


//http://shoutbox.menthix.net/showthread.php?tid=63067
function readClipboard() {
   var CF_TEXT = 1;
   var CF_OEMTEXT = 7;
   var CF_UNICODETEXT = 13;
   ISI = false;
   try {
      if(Interop.Call("User32", "OpenClipboard", 0)) {
         if(Interop.Call("User32", "IsClipboardFormatAvailable", CF_TEXT | CF_OEMTEXT)) {
            var hClipboardData = Interop.Call("User32", "GetClipboardData", CF_UNICODETEXT);
            var pchData = Interop.Call("Kernel32", "GlobalLock", hClipboardData);
            var size = Interop.Call("Kernel32", "GlobalSize", hClipboardData);
            var str = Interop.Allocate(size+2);
            Interop.Call("Kernel32", "RtlMoveMemory", str, pchData, size);
            ISI = str.ReadString(0);
            var unlocked = Interop.Call("Kernel32", "GlobalUnlock", hClipboardData);
         } else {
            Interop.Call("User32", "CloseClipboard");
            return(false);
         }
         Interop.Call("User32", "CloseClipboard");
      }
   } catch(exeption) {
      Interop.Call("User32", "CloseClipboard");
      return(false);
   }
   return(ISI);
}


function matchISI() {
   var re = /^\#[A-F0-9]{12}$/;
   var foundArray = re.test(ISI);
   if(foundArray == true) {
      return(true);
   } else {
      return(false);
   }
}

This post was edited on 07-17-2006 at 06:31 AM by andrey.
[Image: w2kzw8qp-sq2_dz_b_xmas.png]
07-17-2006 12:50 AM
Profile PM Find Quote Report
Chestah
Veteran Member
*****

Avatar

Posts: 1658
Reputation: 34
36 / Male / –
Joined: Jun 2004
RE: [not really a release/help] my first script
Looks good :), just a few suggestions.

return(""); - all your returns can be in this format: return "";. There is no need for the brackets.

Also it doesn't matter for your script but in programming in general its good to abstract components of your code so you can reuse them. For instance your readclipboard() function reads the data and puts it into the variable ISI. It would be better if instead it just returned the string contents of the clipboard and then in your code you would do something like this:

code:
ISI = readClipboard();


You could do something similiar to the matchISI() function and pass in the ISI variable. It doesn't really have any impact on this script but its just a programming practise that you can use to reuse code :).

Good work! (Y) :)
Segosa is newb.
07-17-2006 01:03 AM
Profile E-Mail PM Web Find Quote Report
RaceProUK
Elite Member
*****

Avatar

Posts: 6073
Reputation: 57
39 / Male / Flag
Joined: Oct 2003
RE: [not really a release/help] my first script
quote:
Originally posted by Chestah
Also it doesn't matter for your script but in programming in general its good to abstract components of your code so you can reuse them. For instance your readclipboard() function reads the data and puts it into the variable ISI. It would be better if instead it just returned the string contents of the clipboard and then in your code you would do something like this:

code:
ISI = readClipboard();


You could do something similiar to the matchISI() function and pass in the ISI variable. It doesn't really have any impact on this script but its just a programming practise that you can use to reuse code :).

Good work! (Y) :)
It matters in scripts too: it's programming after all. Personally, I'd recommend this as a matter of style: having global variables can be quite dangerous.
[Image: spartaafk.png]
07-17-2006 08:54 AM
Profile PM Web Find Quote Report
« 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