Answering code (kinda, I suck at titles) - 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: Answering code (kinda, I suck at titles) (/showthread.php?tid=87668)
Answering code (kinda, I suck at titles) by Jonte135 on 12-09-2008 at 08:41 PM
I'm pretty new to this kind of coding, but could someone explain to me why this won't work:
jscript code: function OnEvent_ChatWndReceiveMessage(ChatWnd, Origin, Message, MessageKind) {
//local variables
var sDetector = " ", sResponse = " "; /* sDetector is words to detect, sResponse is words to respond with */
var ofr, ofr1, ofr2, ForReading = 1; /* For reading from file */
ofr = new ActiveXObject("Scripting.FileSystemObject");
ofr1 = ofr.OpenTextFile("C:\\Program\\Messenger Plus! Live\\Scripts\\B.O.T._ Being Optimized for Troubleshooting\\text.txt", ForReading); /* Open file "Detecting Words.txt" */
ofr2 = ofr1.ReadAll(); /* Read all file contents */
ofr1.Close(); /* Close the file */
sDetector = ofr2.split("\r\n"); /* Set sDetector to every word, separated by /r/n */
ofr1 = ofr.OpenTextFile("C:\\Program\\Messenger Plus! Live\\Scripts\\B.O.T._ Being Optimized for Troubleshooting\\text.txt", ForReading); /* Open file "Responding Words.txt" */
ofr2 = ofr1.ReadAll(); /* Read all file contents */
ofr1.Close(); /* Close the file */
sResponse = ofr2.split("\r\n"); /* Set sResponse to every word, separated by \r\n */
/* 2 */
var sDetector2 = " ", sResponse2 = " "; /* sDetector is words to detect, sResponse is words to respond with */
var ofr2, ofr12, ofr22, ForReading2 = 1; /* For reading from file */
ofr2 = new ActiveXObject("Scripting.FileSystemObject");
ofr12 = ofr2.OpenTextFile("C:\\Program\\Messenger Plus! Live\\Scripts\\B.O.T._ Being Optimized for Troubleshooting\\moretext.txt", ForReading); /* Open file "Detecting Words.txt" */
ofr22 = ofr12.ReadAll(); /* Read all file contents */
ofr12.Close(); /* Close the file */
sDetector2 = ofr22.split("\r\n"); /* Set sDetector to every word, separated by /r/n */
ofr12 = ofr2.OpenTextFile("C:\\Program\\Messenger Plus! Live\\Scripts\\B.O.T._ Being Optimized for Troubleshooting\\moretext.txt", ForReading); /* Open file "Responding Words.txt" */
ofr22 = ofr12.ReadAll(); /* Read all file contents */
ofr12.Close(); /* Close the file */
sResponse = ofr2.split("\r\n"); /* Set sResponse to every word, separated by \r\n */
/* Respons */
var iCountUp = 0, iCountUpToo = 0;
if (Origin != Messenger.MyName) {
var sParts = Message.split(" ");
while(1) {
if (iCountUp == 10) {
break;
}
while(1) {
if (iCountUpToo == 10) {
break;
}
if (sParts[iCountUp] == sDetector[iCountUpToo] && sParts[iCountUp] == sDetector2[iCountUpToo]) {
ChatWnd.SendMessage(sResponse[Math.round(Math.random()%4)]);
}
iCountUpToo += 1;
}
iCountUp += 1;
}
}
What's I'm/the code is trying to do is that it will first identify a word from a file and see if that's the same as someone sends. If so it will reply. I tried to do so it would reply only if there were two words. Like instead of just "hello" it will reply on "hello mate" etc.
Thank you
RE: Answering code (kinda, I suck at titles) by matty on 12-09-2008 at 09:08 PM
It would probably help you if you kept each of the problems/issues regarding the one script in the same thread. You have a bunch of questions with regards to the exact same problem.
RE: Answering code (kinda, I suck at titles) by Jonte135 on 12-10-2008 at 07:51 PM
Yes I know, I'm sorry about that. But the other topics included another code and no one would look in them if I edited it. I know it's a lame excuse but I won't do it again. From now on I will edit.
RE: Answering code (kinda, I suck at titles) by matty on 12-10-2008 at 08:03 PM
Ok so here is what you want my recommendation would be
Instead of having text files have 1 XML file. The structure can be something like this:
xml code: <AutoResponder>
<Word>
<Trigger>hey</Trigger>
<Response>hi</Response>
<!--
Number between 1 - 10
10 being takes precedence over all others
1 being last one selected
-->
<Priority>9</Priority>
</Word>
<Word>
<Trigger>hey mate</Trigger>
<Response>hey mate how are you?</Response>
<Priority>10</Priority>
</Word>
</AutoResponder>
What that would allow you to do is have hey mate take priority over hey so if someone were to say hey mate you would say hey how are you instead of hi.
That would be how I would develop such a feature.
RE: Answering code (kinda, I suck at titles) by Jonte135 on 12-10-2008 at 08:10 PM
Ok thanks for the response I don't really understand XML yet, is there any good tutorial on how it works?
RE: Answering code (kinda, I suck at titles) by roflmao456 on 12-10-2008 at 09:25 PM
quote: Originally posted by Jonte135
Ok thanks for the response I don't really understand XML yet, is there any good tutorial on how it works?
Try looking at the ActiveX: Microsoft.XMLDOM
RE: Answering code (kinda, I suck at titles) by Jonte135 on 12-11-2008 at 08:48 PM
Where can I find that?
RE: Answering code (kinda, I suck at titles) by matty on 12-12-2008 at 12:41 AM
RE: Answering code (kinda, I suck at titles) by Jonte135 on 12-13-2008 at 09:41 AM
Thanks Would it be possible to do something like this?
xml code: <AutoResponder>
<Word>
<Trigger>hey</Trigger>
<Response>hi</Response>
<!--
Number between 1 - 10
10 being takes precedence over all others
1 being last one selected
-->
<Priority>9</Priority>
</Word>
<Word>
<Trigger>
hey
hello
hi
yo
</Trigger>
<Response>hey mate how are you?</Response>
<Priority>10</Priority>
</Word>
</AutoResponder>
And it will respond to either hey, hello, hi or yo?
RE: Answering code (kinda, I suck at titles) by Jonte135 on 12-19-2008 at 04:13 PM
But how do Msg+ scripting work with XML?
RE: Answering code (kinda, I suck at titles) by vaccination on 12-19-2008 at 04:42 PM
I suggest you look at the official scripting documentation. It'll help you a lot.
RE: Answering code (kinda, I suck at titles) by matty on 12-19-2008 at 05:07 PM
quote: Originally posted by vaccination
I suggest you look at the official scripting documentation. It'll help you a lot.
The OP is more refering to how to use XMLDOM to read localized XML files not creating the XML interfaces.
As posted earlier read over this: http://msdn.microsoft.com/en-us/library/aa468547.aspx
It may be in VBScript but will be quite easy to convert.
|