Module_PingReply  latest
Erebot module to respond to PING messages
PingReply.php
1 <?php
2 /*
3  This file is part of Erebot.
4 
5  Erebot is free software: you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation, either version 3 of the License, or
8  (at your option) any later version.
9 
10  Erebot is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with Erebot. If not, see <http://www.gnu.org/licenses/>.
17 */
18 
19 namespace Erebot\Module;
20 
30 class PingReply extends \Erebot\Module\Base implements \Erebot\Interfaces\HelpEnabled
31 {
44  public function reload($flags)
45  {
46  if ($flags & self::RELOAD_HANDLERS) {
47  $handler = new \Erebot\EventHandler(
48  \Erebot\CallableWrapper::wrap(array($this, 'handlePing')),
49  new \Erebot\Event\Match\Type('\\Erebot\\Interfaces\\Event\\Ping')
50  );
51  $this->connection->addEventHandler($handler);
52  }
53  }
54 
55  public function getHelp(
56  \Erebot\Interfaces\Event\Base\TextMessage $event,
57  \Erebot\Interfaces\TextWrapper $words
58  ) {
59  if ($event instanceof \Erebot\Interfaces\Event\Base\PrivateMessage) {
60  $target = $event->getSource();
61  $chan = null;
62  } else {
63  $target = $chan = $event->getChan();
64  }
65 
66  if (count($words) == 1 && $words[0] === get_called_class()) {
67  $msg = $this->getFormatter($chan)->_(
68  "This module does not provide any command but replies ".
69  "to a server's PING message with the appropriate PONG ".
70  "response."
71  );
72  $this->sendMessage($target, $msg);
73  return true;
74  }
75  }
76 
88  public function handlePing(
89  \Erebot\Interfaces\EventHandler $handler,
90  \Erebot\Interfaces\Event\Ping $event
91  ) {
92  $this->sendCommand('PONG :'.$event->getText());
93  }
94 }
handlePing(\Erebot\Interfaces\EventHandler $handler,\Erebot\Interfaces\Event\Ping $event)
Definition: PingReply.php:88
A basic module that sends replies to PING queries it receives.
Definition: PingReply.php:30