PDA

View Full Version : Auto Responders



Rich
12-09-2008, 04:58 PM
How To Make An Auto Responder
By R1ch

In this tutorial, like the title says, you're going to be learning how to make an auto responder. Now you might think that making one is hard, but after you've read this tutorial, you'll think otherwise. Let's start...

The function that we'll be using is InChat which is used like if InChat('This tutorial is great!') then WriteLn('I know :p'); However, if we are making an auto responder, we want it to respond to more than one phrase. This is why we make the phases into a TStringArray. This also may sound complicated, but is very simple.

What this basically means is an array of strings. You should know that a normal string looks like what I put in the InChat function, and all a TStringArray is is many strings in one. Here's an example, then I will explain it bit by bit
procedure Chat;
var
HiChats : TStringArray;
I : Integer;

begin
if not (LoggedIn) then Exit;
HiChats:= ['hi', 'yo', 'sup', 'ello', 'wassup', 'll right', 'hey'];
for I:= 0 to High(HiChats) do
begin
if InChat(HiChats[i]) then
TypeSend('hi to you too');
end;
end;
For some of you, this will go straight over your head, but here's a breakdown...procedure Chat;
var
HiChats : TStringArray;
I : Integer; This is the name of the procedure which will respond, and the variables. Some of you may have figured out that HiChats : TStringArray; is the key to this working. I is just another variable. begin
if not (LoggedIn) then Exit;
HiChats:= ['hi', 'yo', 'sup', 'ello', 'wassup', 'll right', 'hey'];This is the start of the procedure. if not (LoggedIn) then Exit; is a failsafe, which is pretty self explanatory. The next line states what HiChats equals. As it has been declared as a array of a string then it can contain multiple strings. for I:= 0 to 4 do
begin
if InChat(HiChats[i]) then
TypeSend('hi to you too');
end;
end;for I:= 0 to High(HiChats) do makes I equal 0 and looks for each text and every text in HiChats . We should know what that begin is...if InChat(HiChats) then This does like I showed you above. If it finds the text, then it does TypeSend('hi to you too');. In this case, the text that it is meant to find could be any of the ones in HiChats, hence the part HiChats begin in the InChat function.

This is all very nice, but the script at the moment will only reply with one message. So what do we do? Add another TStringArray of course! I'll call it HiChatsR. Here's what the script looks like nowprocedure Chat;
var
HiChats, HiChatsR : TStringArray;
I : Integer;

begin
if not (LoggedIn) then Exit;
HiChats:= ['hi', 'yo', 'sup', 'ello', 'wassup', 'll right', 'hey'];
for I:= 0 to Hi(HighChats) do
begin
if InChat(HiChats[i]) then
TypeSend('hi to you too');
end;
end;I need to do something to that new variable to make it do something, so I'm going to do the same as what I did with HiChats. If you don't know what that is, I'm going to assign multiple strings to HiChatsR. I've made this up for HiChatsRHiChatsR:= ['hi', 'hello there', 'sup', 'yo', 'hello', 'hey', 'howdy'];Now the script looks like thisprocedure Chat;
var
HiChats, HiChatsR : TStringArray;
I : Integer;

begin
if not (LoggedIn) then Exit;
HiChats:= ['hi', 'yo', 'sup', 'ello', 'wassup', 'll right', 'hey'];
HiChatR:= ['hi', 'hello there', 'sup', 'yo', 'hello', 'hey', 'howdy'];
for I:= 0 to High(HiChats) do
begin
if InChat(HiChats[i]) then
TypeSend('hi to you too');
end;
end; However, the script is still not doing anything with that TStringArray other than assigning text to it. So now we need to change it a bit. For the part of finding the text we haveInChat(HiChats[i])And for replying, we're going to do the same.TypeSend(HiChatsR[i]);
Some things that you'll need to remember are:
~ When assigning text to the TStringArray, we use [], instead of ()
~ Always use TypeSend
~ The more texts to find the better
~ The more replies the better

Well that's the end of my tutorial, and I hope it helped you.
All comments, good and bad, are accepted.
R1ch

Kyle Undefined
12-09-2008, 05:51 PM
Nice tut but one thing. if InChat('This tutorial is great!) then WriteLn('I know :p'); needs to be if InChat('This tutorial is great!') then WriteLn('I know :p'); I know it was just an example but tuts need to have everyting right ;) Again, nice tut.

~Camo

Rich
12-09-2008, 08:15 PM
Thanks Camo. I've changed that as well as a few other little typos.

Thanks again,
Richard

Blumblebee
12-09-2008, 09:41 PM
procedure Chat;
var
HiChats : TStringArray;
I : Integer;

begin
if not (LoggedIn) then Exit;
HiChats:= ['hi', 'yo', 'sup', 'ello', 'wassup', 'll right', 'hey'];
for I:= 0 to 4 do
begin
if InChat(HiChats[i]) then
TypeSend('hi to you too');
end;
end;


ummm why 0 to 4? first of all theres 7 strings in that array. May i suggest doing something like...
for I := 0 to High(HiChats) do
that way the person may put as many talks into the string as they want. Also, maybe add something along the lines of using a number of responses to questions (array or array of string) like question[0] := ['whatever', 'like this'];
response[0] := ['whatever', 'ect'];
question[1] := ['whatever', 'and so on'];
response[1] := ['whatever', 'and so forth'];

looks good though, im sure it will help a ton of people when writing autoresponders, good work

Rich
12-10-2008, 08:04 AM
Thanks Blumblebee, I put it as for i:= 0 to 4 because it only had 5 texts to look for, but I added another two. I changed it to HiChats(High as you suggested.

I'll add something about multiple topics to respond on later.

Thanks,
Richard

anonymity
12-17-2008, 05:12 AM
If I had seen this tut earlier I would have agreed with the others; nonetheless... it is a great tut... so.. thanks for posting... I will pass the word on.