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// ---EXAMPLE OF HOW TO USE Net_SmartIRC---
27// this code shows how a mini php bot could be written
28include_once('Net/SmartIRC.php');
29
30class MyBot
31{
32    private $irc;
33    private $handlerid;
34
35    public function __construct($irc)
36    {
37        $this->irc = $irc;
38        $this->handlerid = $irc->registerActionHandler(SMARTIRC_TYPE_CHANNEL, '^!ops', array($this, 'op_list'));
39    }
40
41    public function __destruct()
42    {
43        $this->irc->unregisterActionId($this->handlerid);
44    }
45
46    public function op_list($irc, $data)
47    {
48        $irc->message(SMARTIRC_TYPE_CHANNEL, '#smartirc-test', 'ops on this channel are:');
49
50        // Here we're going to get the Channel Operators, the voices and users
51        // method is available too, e.g. $irc->getChannel('#test')->users will
52        // return all of the channel's users.
53        $oplist = implode(' ', array_keys($irc->getChannel('##fix_your_mind')->ops));
54
55        // result is sent to the channel
56        $irc->message(SMARTIRC_TYPE_CHANNEL, '#smartirc-test', $oplist);
57    }
58}
59
60// Using Channel Syncing we will track all users on all channels we are joined
61$irc = new Net_SmartIRC(array(
62    'DebugLevel' => SMARTIRC_DEBUG_ALL,
63    'ChannelSyncing' => true,
64));
65$bot = new MyBot($irc);
66$irc->connect('chat.freenode.net', 6667);
67$irc->login('Net_SmartIRC', 'Net_SmartIRC Client '.SMARTIRC_VERSION.' (example3.php)', 8, 'Net_SmartIRC');
68$irc->join(array('#smartirc-test','#test'));
69$irc->listen();
70$irc->disconnect();
71