forked from esromneb/phpwebsocket
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchatbot.demo.php
24 lines (22 loc) · 1.11 KB
/
chatbot.demo.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#!/php -q
<?php
// Run from command prompt > php -q chatbot.demo.php
include "websocket.class.php";
// Extended basic WebSocket as ChatBot
class ChatBot extends WebSocket{
function process($user,$msg){
$this->say("< ".$msg);
switch($msg){
case "hello" : $this->send($user->socket,"hello human"); break;
case "hi" : $this->send($user->socket,"zup human"); break;
case "name" : $this->send($user->socket,"my name is Multivac, silly I know"); break;
case "age" : $this->send($user->socket,"I am older than time itself"); break;
case "date" : $this->send($user->socket,"today is ".date("Y.m.d")); break;
case "time" : $this->send($user->socket,"server time is ".date("H:i:s")); break;
case "thanks": $this->send($user->socket,"you're welcome"); break;
case "bye" : $this->send($user->socket,"bye"); break;
default : $this->send($user->socket,$msg." not understood"); break;
}
}
}
$master = new ChatBot("localhost",12345);