Net_SmartIRC
[ class tree: Net_SmartIRC ] [ index: Net_SmartIRC ] [ all elements ]

Source for file example7.php

Documentation is available at example7.php

  1. <?php
  2. /**
  3.  * $Id$
  4.  * $Revision$
  5.  * $Author$
  6.  * $Date$
  7.  *
  8.  * Copyright (C) 2002-2003 Mirco "MEEBEY" Bauer <mail@meebey.net> <http://www.meebey.net>
  9.  *
  10.  * Full LGPL License: <http://www.meebey.net/lgpl.txt>
  11.  *
  12.  * This library is free software; you can redistribute it and/or
  13.  * modify it under the terms of the GNU Lesser General Public
  14.  * License as published by the Free Software Foundation; either
  15.  * version 2.1 of the License, or (at your option) any later version.
  16.  *
  17.  * This library is distributed in the hope that it will be useful,
  18.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  20.  * Lesser General Public License for more details.
  21.  *
  22.  * You should have received a copy of the GNU Lesser General Public
  23.  * License along with this library; if not, write to the Free Software
  24.  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  25.  */
  26.  
  27. // ---EXAMPLE OF HOW TO USE Net_SmartIRC---
  28. // this code shows how a mini php bot could be written
  29. include_once('Net/SmartIRC.php');
  30.  
  31. class MyBot
  32. {
  33.     private $irc;
  34.     private $actionid;
  35.     private $timeids;
  36.  
  37.     public function __construct($irc)
  38.     {
  39.         $this->irc $irc;
  40.         $this->timeids = array(
  41.             // register this to be called every 30 sec. (30,000 milliseconds)
  42.             $irc->registerTimeHandler(30000function($irc)
  43.                 {
  44.                     $irc->message(SMARTIRC_TYPE_CHANNEL'#smartirc-test''the time is: '.date('H:i:s'));
  45.                 }
  46.             ),
  47.  
  48.             // register saytime_once() to be called in 10 sec. (10,000 milliseconds) and save the assigned id
  49.             // which is needed for unregistering the timehandler.
  50.             $irc->registerTimeHandler(10000array($this'saytime_once')),
  51.         );
  52.  
  53.         $this->actionid $irc->registerActionHandler(SMARTIRC_TYPE_CHANNEL'^!quit'function($irc)
  54.             {
  55.                 $irc->quit("time to say goodbye...");
  56.             }
  57.         );
  58.     }
  59.  
  60.     public function __destruct()
  61.     {
  62.         $this->irc->unregisterActionId($this->actionid);
  63.         $this->irc->unregisterTimeId($this->timeids);
  64.     }
  65.  
  66.     public function saytime_once($irc)
  67.     {
  68.         $irc->message(SMARTIRC_TYPE_CHANNEL'#smartirc-test''(once) the time is: '.date('H:i:s'));
  69.         $irc->unregisterTimeId($this->timeids[1]);
  70.         unset($this->timeids[1]);
  71.     }
  72. }
  73.  
  74. $irc = new Net_SmartIRC(array(
  75.     'DebugLevel' => SMARTIRC_DEBUG_ALL,
  76. ));
  77. $bot = new MyBot($irc);
  78. $irc->connect('chat.freenode.net'6667);
  79. $irc->login('Net_SmartIRC''Net_SmartIRC Client '.SMARTIRC_VERSION.' (example7.php)'8'Net_SmartIRC');
  80. $irc->join(array('#smartirc-test','#test'));
  81. $irc->listen();
  82. $irc->disconnect();

Documentation generated on Thu, 25 Jul 2019 12:49:07 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.