SRL Archive - Research & Development Lounge

Auto-responder


Frement

2011-07-17 16:29:35

<!– Re-posted from Members –>

Ok, so this is still under developement, but basicly the idea is simple.

Gather conversations from RS and transfer them to a database. Then through an interface sort them out and give them answers (or delete if stupid message).

After that the final database has some messages and answers.

Then a simba script will query a webpage which searches the most accurate answer from the final database, and outputs the answer.

Answer defines (or normal text):
Level Answers


{LVL_ATTACK}
{LVL_STRENGTH}
{LVL_DEFENCE}
{LVL_RANGED}
{LVL_PRAYER}
{LVL_MAGIC}
{LVL_RUNECRAFTING}
{LVL_CONSTRUCTIONS}
{LVL_DUNGEONEERING}
{LVL_CONSTITUTION}
{LVL_AGILITY}
{LVL_HERBLORE}
{LVL_THIEVING}
{LVL_CRAFTING}
{LVL_FLETCHING}
{LVL_SLAYER}
{LVL_HUNTER}
{LVL_MINING}
{LVL_SMITHING}
{LVL_FISHING}
{LVL_COOKING}
{LVL_FIREMAKING}
{LVL_WOODCUTTING}
{LVL_FARMING}
{LVL_SUMMONING}


QuickChat Answers


{QC_S-R-2}


Advanced Answers


Seperator is "+". Outputs all levels.

{LVL_[SKILL1+SKILL2+SKILL3]}

Seperator is "-". Outputs a random level.

{LVL_[R]SKILL1-SKILL2-SKILL3[/R]}

Seperator is "~". Outputs a random text.

{ANSWER_[R]Hi~Hello there!~Well hi:)~Heya~Hey[/R]}

Here is a picture of the interface which is used to sort the messages, you can also add custom messages and answers if you like.


Here is a test script to retrieve messages:
http://www.frement.net/srl/autoresponder/test.php

I have done the script for simba to sort the messages that are retrieved from the database, but it needs some more work, but I'll paste it too.

program New;
{$I SRL/SRL.scar}

var TheMsg: String;

{*******************************************************************************
function AR_GetResponse(Msg: String): String;
By: Frement
Description: Gets a response for given message.
*******************************************************************************}
function AR_GetResponse(Msg: String): String;
var Page: Integer;
begin
Page := InitializeHTTPClient(False, False);
ClearPostData(Page);
AddPostVariable(Page, 'message', Msg);
Result := PostHTTPPageEx(Page, 'http://www.frement.net/srl/autoresponder/response.php');
end;

{*******************************************************************************
function AR_ParseResponse(Text: String; var Mode: Integer): TStringArray;
By: Frement & mixster
Description: Parses the response to be used in respond function.
*******************************************************************************}
function AR_ParseResponse(Text: String; var Mode: Integer): TStringArray;
var RArray: TStringArray;
begin
Mode := 0;
if (Pos('ANSWER_[R', Text) > 0) then begin
RArray := Explode('~', Between('[R]', '[/R]', Between('{ANSWER_', '}', Text)));
Mode := 1;
end else if (Pos('LVL_[', Text) > 0) then begin
RArray := Explode('+', Between('[', ']', Between('{LVL_', '}', Text)));
Mode := 2;
end else if (Pos('LVL_[R', Text) > 0) then begin
RArray := Explode('-', Between('[R]', '[/R]', Between('{LVL_', '}', Text)));
Mode := 3;
end else if (Pos('QC_', Text) > 0) then begin
RArray := Explode('-', Between('{QC_', '}', Text));
Mode := 4;
end else if (Pos('LVL_', Text) > 0) then begin
RArray := Explode('', Between('{LVL_', '}', Text));
Mode := 5;
end else begin
SetArrayLength(RArray, 1);
RArray[0] := Text;
Mode := 6;
end;
Result := RArray;
end;

{*******************************************************************************
function KeyToChar(Key: String): Char;
By: Frement
Description: Converts a key to character.
*******************************************************************************}
function KeyToChar(Key: String): Char;
begin
Result := Key[1];
end;

{*******************************************************************************
procedure AR_TypeQC(Keys: TStringArray);
By: Frement
Description: Sends a QuickChat message.
*******************************************************************************}
procedure AR_TypeQC(Keys: TStringArray);
var I: Integer;
begin
for I := 0 to High(Keys) do begin
TypeByte(GetKeyCode(KeyToChar(LowerCase(Keys[I]))));
Wait(823+Random(59));
end;
end;

{*******************************************************************************
procedure AR_Respond(Text: String);
By: Frement
Description: Responds to a message from RS.
*******************************************************************************}
procedure AR_Respond(Text: String);
var Response: String;
ResponseArray: TStringArray;
ARMode, I: Integer;
begin
Response := AR_GetResponse(Text);
ResponseArray := AR_ParseResponse(Response, ARMode);
case ARMode of
1: begin
TypeSend(ResponseArray[Random(High(ResponseArray))]);
end;
2: begin
for I := 0 to High(ResponseArray) do begin
TypeSend(IntToStr(GetSkillLevel(ResponseArray[I])));
end;
end;
3: begin
TypeSend(IntToStr(GetSkillLevel(ResponseArray[Random(High(ResponseArray))])));
end;
4: begin
AR_TypeQC(ResponseArray);
end;
5: begin
TypeSend(IntToStr(GetSkillLevel(ResponseArray[0])));
end;
6: begin
for I := 0 to High(ResponseArray) do begin
TypeSend(ResponseArray[I]);
end;
end;
end;
end;

begin
SetupSRL;
repeat
TheMsg := GetChatBoxText(8, clChat);
AR_Respond(TheMsg);
Wait(7000);
until(False);
end.

I am still making this so nothing is perfect or nearly as good as it will be when its done, but I was just hoping to hear your thoughts and ideas.

I am currently (when I find the inspiration again) doing an alias system for the words that it matches, like "att/attack/attk" "str/strength" etc.

So yeah, I first started with i luffs yeww, but I mainly had to do everything by myself because he didn't know PHP or anything.

So here it is, post your thoughts!

Gu3st...

2011-07-17 16:48:56

It'll be cool to see if the JR Members find this interesting :)

Frement

2011-07-17 17:26:44

I mainly want to see if anyone is interested, if there is enough people that could contribute by sorting some messages, then I'll finish this project.

Gu3st...

2011-07-17 17:27:41

I could join in on that if you'd like

Frement

2011-07-17 17:29:56

From: Zyt3x
I could join in on that if you'd like


At least 9 others :(

Smarter Child

2011-07-17 18:06:19

Me2.

Silent

2011-07-18 02:54:22

I could help out I guess. I would just need to know what to do?

RawringDragon

2011-07-18 03:51:29

This looks interesting and worthwhile. Woud have to be really on the spot though, and have randomness. Imagine one guy asking "Are you guys bots?" and all of the 20 something bots answering "I'm not."

Sex

2011-07-18 04:32:19

Haha, I inputted "hi" and it outputted a bunch of "thanks " messages.

Gu3st...

2011-07-18 06:58:40

From: Sex
Haha, I inputted "hi" and it outputted a bunch of "thanks " messages.
it wil lsay "{ANSWER_[R]Thx~Thanx~Thank you~thanks~thank you very much[/R]}" no matter what you input :P

Home

2011-07-18 07:09:12

I'm in too ;)


~Home

Sex

2011-07-18 07:21:12

From: Zyt3x
it wil lsay "{ANSWER_[R]Thx~Thanx~Thank you~thanks~thank you very much[/R]}" no matter what you input :P

No, it won't. When you type "bye" it will say "cya later".

Gu3st...

2011-07-18 07:23:23

From: Sex
No, it won't. When you type "bye" it will say "cya later".
Hmm… Weird.. It doesn't follow the usual {ANSWER[R][/R]} output.. Probably something Frement added manually (?)

Frement

2011-07-18 11:01:42

From: Zyt3x
Hmm… Weird.. It doesn't follow the usual {ANSWER[R][/R]} output.. Probably something Frement added manually (?)


There are multiple return values, you can add random answers etc.

Seperator is "+". Outputs all levels.

{LVL_[SKILL1+SKILL2+SKILL3]}

Seperator is "-". Outputs a random level.

{LVL_[R]SKILL1-SKILL2-SKILL3[/R]}

Seperator is "~". Outputs a random text.

{ANSWER_[R]Hi~Hello there!~Well hi:)~Heya~Hey[/R]}

Or just normal text.

pieapple

2011-08-24 22:37:22

This looks interesting and worthwhile