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.
- 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".
- You should capture the event when the user sends the command.
- 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.
- 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><on|off></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...