Shoutbox

[request] turn a script on/ off for individual chats... - 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: [request] turn a script on/ off for individual chats... (/showthread.php?tid=70612)

[request] turn a script on/ off for individual chats... by What? on 01-12-2007 at 07:31 PM

I'm new here, and new to the whole Scripts thing, so first up hello! But more importantly, I'm trying to write a script that can be turned on and off for individual contacts by typing a / command into the chat box.

I can get it to work individually using an variable turned on/off by sending the message but not for individual contacts.

I've only been using JScript a day (all I've done so far is picked up the very basics to make a script that changes my display name to a random quote of various people from an array every couple of minutes) so sorry if I'm a bit slow to pick this up. Any help would be appreciated.

Thank you. :D


RE: [request] turn a script on/ off for individual chats... by Matti on 01-12-2007 at 08:00 PM

Good, first of all: Welcome to the forums!

As for your question, you should think of how you want this to be done. Imagine which steps a script should take to get your desired result. Because you're new, I'll help you a bit.

  1. You should register the command using a ScriptCommands block in your ScriptInfo.xml file or by using OnGetScriptCommands. I'll assume the command would be "/mycommand " followed by "on" or "off".
  2. You should capture the event when the user sends the command.
  3. In that event, you should get a Contact object by checking if there's only one contact in the conversation and then get that object.
  4. You then should set and save the setting for that contact's email to on or off, depending on the parameter given.
So, in a script it could like like:
code:
//We need to store the settings somewhere, so I choose an array. This is very inefficient when you need to use them the next time you use Messenger.
var settings = new Array();
//Register the command
function OnGetScriptCommands() {
  var s = "<ScriptCommands>";
  s += "<Command>";
  s += "<Name>mycommand</Name>";
  s += "<Parameters>&lt;on|off&gt;</Parameters>";
  s += "<Description>Turn the script on or off for the current contact.</Description>";
  s += "</Command>";
  s += "</ScriptCommands>";
}

//The event!
function OnEvent_ChatWndSendMessage(ChatWnd, Message) {
  //Check if the message is our command
  //This is a regular expression, read more about these on MSDN

  if(/^\/mycommand\s([a-z]+)$/i.test(Message)) {
    //Make sure there are only two people in the chat (you and someone else)
    if(ChatWnd.Contacts.Count == 1) {
      //Get the contact!
      var Contact = new Enumerator(ChatWnd.Contacts).item();
      var Email = Contact.Email;
      //Save the setting
      //RegExp.$1 stores the first captured string in our command check (the thing between brackets)

      if(RegExp.$1 == "on" || RegExp.$1 == "true") settings[Email] = true;
      else settings[Email] = false;
      //End the event by returning nothing (otherwise Plus! gives an error)
      return "";
    } else return "";
  }
}
//Now you can add a function to load and save the settings, make the script function based on the per-contact settings and anytthing you like else...

And yes, the coloring took time... :dodgy:
RE: [request] turn a script on/ off for individual chats... by pedro_cesar on 01-12-2007 at 08:05 PM

u can do it by selecting the emails u want it to work for:


var e = new Enumerator(ChatWnd.Contacts);
    var Cnt = e.item();


now Cnt.Email stands for the Contact's (the one u typed command for) email, so for example u want it to work for somenone like: someone@somewhat.com u can use:

if (Cnt.Email == someone@somewhat.com) { do this }


RE: [request] turn a script on/ off for individual chats... by What? on 01-12-2007 at 08:10 PM

oh wow! thanks you two :D
I want it to add the emails itself from the chat window so i'll try out Mattikes suggestion first. I'll probably mess it up though >.< lol!

edit:
That seems to work just finding various ways to check whether the message i received came from someone on the list- think i've got it though. Can't test for sure until I've found it.

Thanks again for all your help! :)