add / modify copyright notice
[irbot.git] / sources / IRCMain / Ctcp.php
blob8a48ff207e6e7dadf687abf55fe9c6df9e0c97bc
1 <?php
2 /**
3 * This file is part of IrBot, irc robot.
4 * Copyright (C) 2007-2008 Bellière Ludovic
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 class IRCMain_Ctcp {
23 const CTCP_CLIENTINFO = 'CLIENTINFO';
24 const CTCP_VERSION = 'VERSION';
25 const CTCP_USERINFO = 'USERINFO';
26 const CTCP_TIME = 'TIME';
27 const CTCP_PING = 'PING';
29 /**
30 * Event object
32 * @var Event
34 protected $_event;
36 /**
37 * IRCMain object for config data
39 * @var IRCMain
41 protected $_ircmain;
43 public $ctcpNotice;
44 public $ctcpRequest;
45 public $ctcpQuery;
47 public function __construct(Event $event, IRCMain $ircmain) {
48 $this->_event = $event;
49 $this->_ircmain = $ircmain;
52 function _stripMessage() {
53 $this->ctcpNotice = str_replace(chr(001), "", $this->_event->getDataMessage());
56 function _setRequest() {
58 self::_stripMessage();
60 if (strstr($this->ctcpNotice,' ') === true) {
61 list($this->ctcpRequest,$this->ctcpQuery) = explode(" ",$this->ctcpNotice);
62 $this->ctcpRequest = trim($this->ctcpRequest);
63 } else {
64 $this->ctcpRequest = trim($this->ctcpNotice);
69 /**
70 * Return the ctcp responce
72 * @return string
74 function getResponce() {
75 switch ($this->ctcpRequest) {
76 case self::CTCP_CLIENTINFO:
77 return 'PING VERSION TIME USERINFO CLIENTINFO';
78 break;
80 case self::CTCP_VERSION:
81 return 'IrBot version '.$this->_ircmain->getConfig('version').' - PHP '.phpversion().' -- on http://irbot.irstat.org';
82 break;
84 case self::CTCP_USERINFO:
85 return 'IrBot';
86 break;
88 case self::CTCP_TIME:
89 return date('Y-m-d H:i:s');
90 break;
92 case self::CTCP_PING:
93 return "PING " . $query;
94 break;
95 default:
96 return "UNKNOWN CTCP REQUEST : '$this->ctcpRequest'";
97 break;