| 136 | | |
| 137 | | /** |
| 138 | | * Answers for seen when the user is present |
| 139 | | * |
| 140 | | * @var array |
| 141 | | */ |
| 142 | | protected $present = array |
| 143 | | ( |
| 144 | | 'Open your eyes already!', |
| 145 | | 'Are you blind?', |
| 146 | | 'Behind you!', |
| 147 | | 'Over there!', |
| 148 | | ); |
| 149 | | |
| 150 | | /** |
| 151 | | * Answers for when record of a user cannot be found |
| 152 | | * |
| 153 | | * @var array |
| 154 | | */ |
| 155 | | protected $missing = array |
| 156 | | ( |
| 157 | | 'must be mute, or one of your imaginary friends?', |
| 158 | | 'was never heard from... a first time.', |
| 159 | | 'was never heard from... to begin with.', |
| 160 | | 'must have eluded my ubiquity.', |
| 161 | | ); |
| 564 | | // Person is online, send a random prank answer |
| 565 | | if (Phergie_Plugin_Users::isIn($user, $source)) { |
| 566 | | $this->doPrivmsg( |
| 567 | | $source, |
| 568 | | sprintf( |
| 569 | | '%s: %s', |
| 570 | | $target, |
| 571 | | $this->randomPresent() |
| 572 | | ) |
| 573 | | ); |
| 574 | | |
| 575 | | // Person is offline |
| 576 | | } else { |
| 577 | | $params = array( |
| 578 | | ':name' => $user, |
| 579 | | ':chan' => $source |
| 580 | | ); |
| 581 | | |
| 582 | | $this->seen->execute($params); |
| 583 | | $row = $this->seen->fetch(PDO::FETCH_ASSOC); |
| 584 | | |
| 585 | | // Send the last action if available |
| 586 | | if ($row) { |
| 587 | | $this->doPrivmsg( |
| 588 | | $source, |
| 589 | | sprintf( |
| 590 | | '%s: %s was last seen %s: %s (on %s)', |
| 591 | | $target, |
| 592 | | $user, |
| 593 | | $this->actions[$row['type']], |
| 594 | | $row['message'], |
| 595 | | $this->formatTimestamp($row['tstamp']) |
| 596 | | ) |
| 597 | | ); |
| 598 | | |
| 599 | | // Send a prank answer if no last action is found |
| 600 | | } else { |
| 601 | | $this->doPrivmsg( |
| 602 | | $source, |
| 603 | | sprintf( |
| 604 | | '%s: %s %s', |
| 605 | | $target, |
| 606 | | $user, |
| 607 | | $this->randomMissing() |
| 608 | | ) |
| 609 | | ); |
| 610 | | } |
| 611 | | } |
| 612 | | } |
| 613 | | |
| 614 | | /** |
| 615 | | * Responds to requests for the last logged PRIVMSG action or CTCP ACTION |
| 616 | | * command originating from a particular user. |
| 617 | | * |
| 618 | | * @param string $user Nick of the user to search for |
| 619 | | * @return void |
| 620 | | */ |
| 621 | | public function onDoHeard($user) |
| 622 | | { |
| 623 | | if (!$this->db) { |
| 624 | | return; |
| 625 | | } |
| 626 | | |
| 627 | | // Don't match if user has a space (obviously it's not a nick) |
| 628 | | if (strpos($user, ' ') !== false) { |
| 629 | | return; |
| 630 | | } |
| 631 | | |
| 632 | | $source = $this->event->getSource(); |
| 633 | | $target = $this->event->getNick(); |
| 634 | | |
| 635 | | // Handle 'me' alias |
| 636 | | if ($user == 'me') { |
| 637 | | $user = $target; |
| 638 | | } |
| 639 | | |
| 640 | | // Search for the last recorded action |
| 641 | | $params = array( |
| 642 | | ':nick' => $user, |
| 643 | | ':chan' => $source |
| 644 | | ); |
| 645 | | |
| 646 | | $this->heard->execute($params); |
| 647 | | $row = $this->heard->fetch(PDO::FETCH_ASSOC); |
| 648 | | |
| 649 | | // Send the last action if available |
| 650 | | if($row) { |
| 651 | | $this->doPrivmsg( |
| 652 | | $source, |
| 653 | | sprintf( |
| 654 | | '%s: %s\'s last words were: %s (on %s)', |
| 655 | | $target, |
| 656 | | $user, |
| 657 | | $row['message'], |
| 658 | | $this->formatTimestamp($row['tstamp']) |
| 659 | | ) |
| 660 | | ); |
| 661 | | |
| 662 | | // Send a prank answer if no last action is found |
| 663 | | } else { |
| 664 | | $this->doPrivmsg( |
| 665 | | $source, |
| 666 | | sprintf( |
| 667 | | '%s: %s %s', |
| 668 | | $target, |
| 669 | | $user, |
| 670 | | $this->randomMissing() |
| 671 | | ) |
| 672 | | ); |
| 673 | | } |
| | 508 | // Get the last event from the specified user |
| | 509 | $params = array( |
| | 510 | ':name' => $user, |
| | 511 | ':chan' => $source |
| | 512 | ); |
| | 513 | |
| | 514 | $this->seen->execute($params); |
| | 515 | $row = $this->seen->fetch(PDO::FETCH_ASSOC); |
| | 516 | |
| | 517 | // Send the last action if available |
| | 518 | if ($row) { |
| | 519 | $this->doPrivmsg( |
| | 520 | $source, |
| | 521 | sprintf( |
| | 522 | '%s: %s was last seen %s: %s (on %s)', |
| | 523 | $target, |
| | 524 | $user, |
| | 525 | $this->actions[$row['type']], |
| | 526 | $row['message'], |
| | 527 | $this->formatTimestamp($row['tstamp']) |
| | 528 | ) |
| | 529 | ); |
| | 530 | } |