Assembla home | Assembla project page
 

root/trunk/Phergie/Plugin/Ctcp.php

Revision 217, 2.0 kB (checked in by Slynderdale, 8 months ago)

Some final clean up.

Line 
1 <?php
2
3 /**
4  * Responds to various CTCP requests sent by the server and the users
5  */
6 class Phergie_Plugin_Ctcp extends Phergie_Plugin_Abstract_Base
7 {
8     public function onTime()
9     {
10         $source = $this->event->getSource();
11
12         // Send out the default time reply if the second argument is empty
13         $this->doTimeReply($source);
14     }
15
16     public function onVersion()
17     {
18         $source = $this->event->getSource();
19
20         // Send out the default version reply if the second argument is empty
21         $this->doVersionReply($source);
22     }
23
24     public function onPing()
25     {
26         $source = $this->event->getSource();
27
28         // Check for a handshake hash, otherwise its a server ping request
29         $handshake = $this->event->getArgument(1);
30         if ($handshake) {
31             $this->doPingReply($source, $handshake);
32         }
33     }
34
35     public function onCtcp()
36     {
37         $source = $this->event->getSource();
38         // The CTCP Request
39         $ctcp = strtoupper($this->event->getArgument(1));
40
41         // Uncaught PING requests
42         if ($ctcp == 'PING') {
43             $this->doCtcpReply($source, 'pong');
44         }
45         // SOURCE Request, reply with the path to Phergie's SVN
46         else if ($ctcp == 'SOURCE') {
47             $this->doCtcpReply($source, 'source', 'svn2.assembla.com:/svn/phergie/trunk/Phergie/:');
48         }
49         //FINGER Request, reply with the not's real name
50         else if ($ctcp == 'FINGER') {
51             $name = $this->getIni('nick');
52             $realname = $this->getIni('realname');
53             $username = $this->getIni('username');
54
55             $finger = (!empty($realname) ? $realname : $name) . ' (' . (!empty($username) ? $username : $name) . ')';
56             $this->doCtcpReply($source, 'finger', $finger);
57         }
58         // UPTIME Request, reply with the bot's uptime
59         else if ($ctcp == 'UPTIME') {
60             $uptime = $this->getCountdown(time() -$this->getStartTime());
61             $this->doCtcpReply($source, 'uptime', $uptime);
62         }
63     }
64 }
65 ?>
66
Note: See TracBrowser for help on using the browser.