matty
Scripting Guru
Posts: 8336 Reputation: 109
39 / /
Joined: Dec 2002
Status: Away
|
RE: Caching which windows have a command enabled
Sure does:
jscript code: // Declare an object to hold our ChatWindows
var oChatWnds = {};
// An event is fired because a chat window was created
function OnEvent_ChatWndCreated(oChatWnd) {
// Create an entry in the object for the chat window
oChatWnds[oChatWnd.Handle] = {};
// Store the chat window's object in our oChatWnds object
oChatWnds[oChatWnd.Handle].objChatWnd = oChatWnd;
// Create a read/write property for the on/off
oChatWnds[oChatWnd.Handle].bCommand = true;
}
// An event is fired because a chat window was closed
function OnEvent_ChatWndDestroyed(oChatWnd) {
// Remove the chat window from the object
delete oChatWnds[oChatWnd.Handle];
}
// An event is fired because we sent a message
function OnEvent_ChatWndSendMessage(oChatWnd, sMessage) {
// Perform a regexp function to split the command and params
if (/^\/([^\s\/]+)\s*([\s\S]*)$/.exec(sMessage) !== null) {
// Declare local variables for the command and the parameters
var Command = RegExp.$1.toLowerCase();
var Param = RegExp.$2;
// Check if the command is one of ours
if (Command === 'command') {
// If it is then change the variable based on what the paramter is set to
oChatWnds[oChatWnd.Handle].bCommand = (Param === 'on' ? true : false);
// Return a null string to the function
return '';
}
// Return the message if we are doing nothing with it
return sMessage;
}
// Called when the user presses / in the chat window
function OnGetScriptCommands() {
// Make sure 'command' is a valid command so Plus! doesn't bark
return '<ScriptCommands><Command><Name>command</Name></Command></ScriptCommands>';
}
This post was edited on 11-18-2008 at 09:03 PM by matty.
|
|