SamV522
New Member
Posts: 10
Joined: Nov 2009
|
O.P. RE: Need Help with my First Script
AwayI.js
js code: // Name: AwayI.js
// Author: SamV522
// Purpose: A.I. to respond to any messages while you're away.
var AI = {};
AI.Name = "Sophie";
AI.UnkownResponse = "I do not know how to respond to that, sorry.";
AI.Status = true;
AI.Responses = {};
var xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
function verify(){
if (xmlDoc.readyState != 4){
return false;
}
}
function loadXML(xmlFile)
{
xmlDoc.async="false";
xmlDoc.onreadystatechange=verify;
xmlDoc.load(xmlFile);
xmlObj=xmlDoc.documentElement;
}
function OnEvent_SigninReady()
{
if( AI.Status){
loadXML("coms.xml");
var In = "";
var Out = "";
for(i=0;i!=xmlObj.childNodes.length;i++){
if(xmlObj.childNodes(i).childNodes(0).getAttribute("CaseSenseitive")=="false"){
// The response IS case sensitive
In = xmlObj.childNodes(i).childNodes(0).text;
In = In.split(",");
Out = xmlObj.childNodes(i).childNodes(1).text;
Out = Out.split(",");
for(i2=0;i2!=In.length;i2++){
AI.Responses[In[i2]].Resp = Out;
AI.Responses[In[i2]].CaseSens = false;
}
}else{
}
}
}
}
function OnEvent_ChatWndReceiveMessage(ChatWnd,Origin, Message, MessageKind)
{
var inMsg = Message;
var resp = "Error!";
for(i=0;i!=AI.Responses.length;i++){
if(AI.Responses[Message]){
if(AI.Responses[Message].CaseSens){
inMsg = inMsg.toLowerCase();
}else{
inMsg = inMsg;
}
if(inMsg==AI.Responses[inMsg]){
resp = AI.Responses[Message][Math.floor(Math.random()*Responses[Message].length)];
}else{
resp = AI.UnkownResponse;
}
}
ChatWnd.SendMessage(resp);
}
}
function OnEvent_ChatWndSendMessage(ChatWnd, Message){
if (Message.substr(0,6).toLowerCase() == "/AwayI"){
var param = Message.substr(7);
switch(param){
case "enable":
AI.State = true;
return "";
case "disable":
AI.State = false;
return "";
case "commands":
var WindowOptions=MsgPlus.CreateWnd("Commands.xml","CommandsWND");
return "";
/*default:
alert("Invalid Command! Type \"/AwayI Commands\" to see a list of valid commands");
break;
*/
}
}
}
function OnEvent_MenuClicked(sMenuId, nLocation, ChatWnd)
{
switch(sMenuId){
case "enableAI":
AI.Status = true;
break;
case "disableAI":
AI.Status = false;
break;
case "commandList":
var WindowOptions=MsgPlus.CreateWnd("Interfaces.xml","commandsWND");
break;
}
}
ScriptInfo.xml:
xml code: <?xml version="1.0"?>
<ScriptInfo xmlns="urn:msgplus:scripts" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" Version="1.0">
<Information>
<Name>AwayI MSN Bot</Name>
<Description>An MSN Bot by SamV522</Description>
<Version>1.0</Version>
</Information>
<ScriptMenu>
<MenuEntry Id="enableAI">Enable</MenuEntry>
<MenuEntry Id="disableAI">Disable</MenuEntry>
<MenuEntry Id="commandList">Commands</MenuEntry>
</ScriptMenu>
<ScriptCommands>
<Command>
<Name>AwayI</Name>
<Description>Execute an AwayI command</Description>
<Parameters><Command></Parameters>
</Command>
</ScriptCommands>
</ScriptInfo>
|
|