Welcome!

Join our community of MMO enthusiasts and game developers! By registering, you'll gain access to discussions on the latest developments in MMO server files and collaborate with like-minded individuals. Join us today and unlock the potential of MMO server development!

Join Today!

[PHP] How To Make A Talking Bot

Status
Not open for further replies.
Vous Pas Reel
Loyal Member
Joined
Nov 6, 2007
Messages
880
Reaction score
11
Ok well, heres how to make a php bot., and heres an example
PHP:
<form method="post"> 
Message: <input name="message" type="text" /> 
<br />

<input type="submit" value="Send Message" />

<?php 
$name =$_POST['name'];
$message =$_POST['message'];
if ( $message == "hello") {
$return = "how are you?";
}
if ($message == "good you?") {
$return = "i am good";
}
if ($message == "good") {
$return = "thats cool";
}
if ($message == "sad") {
$return = "well why are u sad";
}
if ($message == "sad you?") {
$return = "im good, and why so sad?";
}
if ($message == "fine") {
$return = "fine, usually that measn your bored!";
}
if ($message == "fine you?") {
$return = "im good";
} 
?>
<br />
<? echo("$return"); ?>
That is how you do it, just change it to what u would like to add. It is all done if if statements.
PHP:
The if statement is necessary for most programming, thus it is important in PHP. Imagine that on January 1st you want to print out "Happy New Year!" at the top of your personal web page. With the use of PHP if statements you could have this process automated, months in advance, occuring every year on January 1st. 
This idea of planning for future events is something you would never have had the opportunity of doing if you had just stuck with HTML.
 
Last edited by a moderator:
---
Loyal Member
Joined
Aug 18, 2004
Messages
641
Reaction score
3
re: [PHP][Tutorial] How To Make A Talking Bot

Well, if you're making a talking bot. I believe it's not a best way.
Just my 2 cents comment.
 
Custom Title Activated
Loyal Member
Joined
Jun 28, 2007
Messages
2,986
Reaction score
3
re: [PHP][Tutorial] How To Make A Talking Bot

Quite basic, but nice try. Maybe it would be nice to let it actually interpret the language and figure out what is said... (or try with regex's, where you see if the word hello is in the text, or how are you...).
 
Joined
Jul 26, 2006
Messages
3,634
Reaction score
1,007
re: [PHP][Tutorial] How To Make A Talking Bot

Try using a switch statement.
Try something like this:

PHP:
<form method="post"> 
Message: <input name="message" type="text" />
<label><input type="radio" name="type" value="switch" checked="checked" />Switch case</label> 
<label><input type="radio" name="type" value="preg_replace" />Preg_replace</label> 
<br />

<input type="submit" value="Send Message" />

<?php 
$message = $_POST['message'];
$type    = $_POST['type'];

if ($type == 'switch')
{
	switch(strtolower($message))
	{
		case 'hello':
					 $return = 'How are you?';
					 break;
		case 'good you?':
					 $return = 'I am good.';
					 break;
		case 'good':
					 $return = 'That\'s cool.';
					 break;
		case 'sad':
					 $return = 'Well, why are you sad?';
					 break;
		case 'sad you?':
					 $return = 'I\'m good, and why so sad?';
					 break;
		case 'fine':
					 $return = "Fine, usually that means you're bored!";
					 break;
		case 'fine you?':
					 $return = 'I\'m good.';
					 break;
		default:
					 $return = 'Why hello!';
					 break;
	}
}
else if ($type == 'preg_replace')
{
	$find = array(
				  "/(.*?)hello(.*?)/is",                               
				  "/(.*?)good(.*?)you\?(.*?)/is",                               
				  "/(.*?)good(.*?)/is",                               
				  "/(.*?)sad(.*?)/is",                               
				  "/(.*?)sad(.*?)you\?(.*?)/is",                               
				  "/(.*?)fine(.*?)/is",                               
				  "/(.*?)fine(.*?)you\?(.*?)/is"
				  );
	
	$replace = array(
					"How are you?",                               
					"I'm good.",                               
					"That's cool!",                               
					"Well, why are you sad?",                               
					"I'm good, and why so sad?",                               
					"Fine, usually that means you're bored!",                               
					"I'm good."
					);
	$return  = preg_replace($find, $replace, $message);
}

echo $return;
?>
<br />
 
Joined
Jun 8, 2007
Messages
1,985
Reaction score
490
re: [PHP][Tutorial] How To Make A Talking Bot

It could turn into something cool... Maybe make a form where users/admins can add more conditions. That way the engine can live and grow as it ages and gets more popular. Maybe make a website designed to relive stress or give advice on certain questions. Maybe someday it could develope a personallity.

For example, if it's designed to have multiple responses for some questions, it could say something random for things like "How are you?"

Maybe the user wants to know how the server is doing, and the server will respond with a random response ranging from "Fine, good, bad, sad, happy, glad, extatic, sleepy, disturbed, sick, etc."

Then if the user asks a single word question, such as "Why?", it will respond with an answer relating to it's last answer. So the end result could be a user talking to a computer for 10 minutes... Pretty funny.. lol

Johny: Hello.
server: Hey Johny! What's up?
Johny: Not much, how are you?
server: I'm feeling kind of sick right now..
Johny: Why's that?
server: Someone's been spamming my database with useless posts.. like this one!

lol...
 
Skilled Illusionist
Loyal Member
Joined
Jun 23, 2007
Messages
310
Reaction score
1
Re: [PHP][Tutorial] How To Make A Talking Bot

Nice, but why not use MySQL. When it recieves the 'trigger' search the MySQL table for the 'result' then echo it, will decrease the size of the .php file but it will be moved to the .SQL file.

Good Luck.
 
Joined
Jun 8, 2007
Messages
1,985
Reaction score
490
Re: [PHP][Tutorial] How To Make A Talking Bot

I made this an open source project! Hope you don't mind, HotelUnderSeige

Post More Source and check for updates/info here:
http://forum.ragezone.com/f86/opensourceproject-talk2me-bot-478882/

Check it out now here:


P.S. Try saying: "You suck", "This sucks", "This thing sucks" or "talk2mebot sucks" lol...

You can add more things for it to recognize/respond to!

Enjoy your experience talking to yourself !! ;)
 
Vous Pas Reel
Loyal Member
Joined
Nov 6, 2007
Messages
880
Reaction score
11
Re: [PHP][Tutorial] How To Make A Talking Bot

I made this an open source project! Hope you don't mind, HotelUnderSeige

Post More Source and check for updates/info here:
http://forum.ragezone.com/f86/opensourceproject-talk2me-bot-478882/

Check it out now here:


P.S. Try saying: "You suck", "This sucks", "This thing sucks" or "talk2mebot sucks" lol...

You can add more things for it to recognize/respond to!

Enjoy your experience talking to yourself !! ;)
sweet ;p
 
Master Summoner
Joined
Oct 25, 2006
Messages
524
Reaction score
0
Re: [PHP][Tutorial] How To Make A Talking Bot

first one looks good and easy... the other one with radios... i don't get it ...
 
Custom Title Activated
Loyal Member
Joined
Aug 8, 2004
Messages
3,892
Reaction score
20
Re: [PHP][Tutorial] How To Make A Talking Bot

Aah, good times.. I once wrote a bot called Fai, based on pretty much the same principle. As an added bonus I wrote a webcrawler that read texts on the internet and searched them for definitions and info, she could come up with some witty remarks.. See

In training mode you can also learn her new stuff, that has led to some unexpected results already :icon6:

She's also on IRC sometimes, irc.sorcery.net channel #ragezone, tho' you can invite her to your own channel too :smile:
 
Junior Spellweaver
Joined
Jun 20, 2008
Messages
151
Reaction score
1
Re: [PHP][Tutorial] How To Make A Talking Bot

but if u do ur code we must know the exact words to write so the bot replies thats kinda hard u know.
 
Skilled Illusionist
Joined
Dec 7, 2007
Messages
337
Reaction score
0
Re: [PHP][Tutorial] How To Make A Talking Bot

to easy to error the code. simply not say something that is in the code that you put and voila no response.
 
Experienced Elementalist
Joined
Oct 7, 2007
Messages
234
Reaction score
0
Re: [PHP][Tutorial] How To Make A Talking Bot

PHP is beautiful, do you know how to make a Bot that it can talk?
 
Junior Spellweaver
Joined
Dec 2, 2006
Messages
198
Reaction score
0
Re: [PHP][Tutorial] How To Make A Talking Bot

umm, if it finds a word, then it loads the same sound?
it sounds good. lol.
 
Supreme Arcanarch
Loyal Member
Joined
Mar 23, 2007
Messages
931
Reaction score
10
Re: [PHP][Tutorial] How To Make A Talking Bot

Hehe, can you make it so it will read all the values from *.txt?
 
Joined
Jun 8, 2007
Messages
1,985
Reaction score
490
Re: [PHP][Tutorial] How To Make A Talking Bot

Anyone ever heard of a podcast? Basically, if you goto a website with podcast installed, it will read off the text loaded from an RSS feed, .txt document, and probably many other methods of databased text.

So on the same event that tells the bot to talk, tell the podcast to read the text.

In essence, when the user clicks submit, the bot will talk to them.

I never would've thought of it if Intelext hadn't have brought it up!

Tis genius..... Genius.


Unfortunatly, my free hosting ran out at awardspace.com.. so I'm forced to put a stop to my development in this field.

If anyone wants to find me a free mySQL/PHP host and wants me re-open the Talk2MeBot project, let me know.

There's a large demand in FAQ/Technical Support systems that would love something like this..

I'm sure if we prepared Talk2MeBot for something like that, it would sell 1000 times if we target the right audience.

I'm a Warrior at heart, RaGEZOneRs, what can I say?
 
Status
Not open for further replies.
Back
Top