| 297 | | protected function run() |
| 298 | | { |
| 299 | | // Current username and size of username |
| 300 | | $bot = $this->config['username']; |
| 301 | | $len = strlen($bot); |
| 302 | | |
| 303 | | // Parts of a publicly spoken message |
| 304 | | $parts = array('nickname', 'username', 'hostname', 'channel', 'message'); |
| 305 | | |
| 306 | | while ( ! feof($this->socket)) |
| 307 | | { |
| 308 | | while ($raw = fgets($this->socket, 1024)) |
| 309 | | { |
| 310 | | // Remove extra whitespace |
| 311 | | $raw = trim($raw); |
| 312 | | |
| 313 | | if (substr($raw, 0, 4) === 'PING') |
| 314 | | { |
| 315 | | // Send a PONG response |
| 316 | | $this->send('PONG'.substr($raw, 4)); |
| 317 | | break; |
| 318 | | } |
| 319 | | else |
| 320 | | { |
| 321 | | if (strpos($raw, 'PRIVMSG') !== FALSE |
| 322 | | AND strpos($raw, $bot) !== FALSE |
| 323 | | AND preg_match('/^:(.+?)!n=(.+?)@(.+?) PRIVMSG (#.+?) :(.+)$/', $raw, $data)) |
| 324 | | { |
| 325 | | // Make an associative array of the data |
| 326 | | $data = array_combine($parts, array_slice($data, 1)); |
| 327 | | |
| 328 | | if (substr($data['message'], 0, $len) === $bot) |
| 329 | | { |
| 330 | | // A command has been sent |
| 331 | | $command = ltrim(substr($data['message'], $len), ' :;,'); |
| 332 | | |
| 333 | | if ($command === 'say hello') |
| 334 | | { |
| 335 | | ; |
| 336 | | } |
| 337 | | elseif (preg_match('/^r(\d+)$/', $command, $match)) |
| 338 | | { |
| 339 | | // The URL for a revision number |
| 340 | | $url = 'http://trac.kohanaphp.com/changeset/'.$match[1]; |
| 341 | | |
| 342 | | if ($this->url_status($url)) |
| 343 | | { |
| 344 | | $this->send('PRIVMSG '.$data['channel'].' :Revision r'.$match[1].', '.$url); |
| 345 | | } |
| 346 | | } |
| 347 | | elseif (preg_match('/^#(\d+)$/', $command, $match)) |
| 348 | | { |
| 349 | | // The URL for a ticket number |
| 350 | | $url = 'http://trac.kohanaphp.com/ticket/'.$match[1]; |
| 351 | | |
| 352 | | if ($this->url_status($url)) |
| 353 | | { |
| 354 | | $this->send('PRIVMSG '.$data['channel'].' :Ticket #'.$match[1].', '.$url); |
| 355 | | } |
| 356 | | } |
| 357 | | } |
| 358 | | } |
| 359 | | else |
| 360 | | { |
| 361 | | echo $raw."\n"; |
| 362 | | } |
| 363 | | |
| 364 | | // |
| 365 | | // if (($offset = strpos($raw, ' PRIVMSG :'.$user)) !== FALSE AND ) |
| 366 | | // { |
| 367 | | // |
| 368 | | // } |
| 369 | | // list ($host, $cmd, $msg) = explode(' ', $raw, 3); |
| 370 | | // |
| 371 | | // $host = trim($host); |
| 372 | | // $cmd = trim($cmd); |
| 373 | | // $msg = trim($msg); |
| 374 | | // |
| 375 | | // list ($chan, $msg) = explode(' ', $msg); |
| 376 | | // $msg = substr($msg, 1); |
| 377 | | // |
| 378 | | // print_r(array('host' => $host, 'cmd' => $cmd, 'chan' => $chan, 'msg' => $msg)); |
| 379 | | |
| 380 | | // if (($offset = strpos($raw, ':', 1)) !== FALSE) |
| 381 | | // { |
| 382 | | // if (($offset = substr($raw, $offset, $size)) === $user) |
| 383 | | // { |
| 384 | | // // Process the command |
| 385 | | // $this->send('PRIVMSG '.$chan.' :saying hello?'); |
| 386 | | // } |
| 387 | | // } |
| 388 | | } |
| 389 | | |
| 390 | | // Flush the console output |
| 391 | | flush(); |
| 392 | | } |
| 393 | | } |
| 394 | | } |
| 395 | | |
| | 449 | public function response_privmsg($data) |
| | 450 | { |
| | 451 | if ($data['message'] === chr(1).'VERSION'.chr(1)) |
| | 452 | { |
| | 453 | // Send a CTCP VERSION response |
| | 454 | $this->response_version($data); |
| | 455 | } |
| | 456 | elseif (substr($data['message'], 0, strlen($this->username)) === $this->username |
| | 457 | AND $trigger = trim(substr($data['message'], strlen($this->username)), ' :')) |
| | 458 | { |
| | 459 | // Process triggers |
| | 460 | foreach ($this->msg_triggers as $pattern => $func) |
| | 461 | { |
| | 462 | if (preg_match('/'.$pattern.'/', $trigger, $matches)) |
| | 463 | { |
| | 464 | // Execute the callback trigger: |
| | 465 | // callback($this, $command_array, $captures); |
| | 466 | call_user_func($func, $this, $data, $matches); |
| | 467 | } |
| | 468 | } |
| | 469 | } |
| | 470 | } |
| | 471 | |
| | 472 | public function response_version($data) |
| | 473 | { |
| | 474 | // Send a CTCP VERSION response |
| | 475 | $this->send('NOTICE '.$data['sender'].' :'.chr(1).'VERSION Kobot v'.KOHANA_VERSION.' Kohana Team'.chr(1)); |
| | 476 | } |
| | 477 | |