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 which could be written
28include_once('Net/SmartIRC.php');
29
30class Net_SmartIRC_module_MyBot
31{
32    public $name        = 'MyBot';
33    public $description = 'My custom bot with two action handlers';
34    public $author      = 'My Name';
35    public $license     = 'LGPL';
36
37    private $irc;
38    private $handlerids;
39
40    public function __construct($irc)
41    {
42        $this->irc = $irc;
43        $this->handlerids = array(
44            $irc->registerActionHandler(SMARTIRC_TYPE_QUERY|SMARTIRC_TYPE_NOTICE, '^test', array($this, 'query_test')),
45            $irc->registerActionHandler(SMARTIRC_TYPE_CHANNEL, '^test', function($irc, $data)
46                {
47                    $irc->message(SMARTIRC_TYPE_CHANNEL, $data->channel, $data->nick.': I dont like tests!');
48                }
49            ),
50        );
51    }
52
53    public function __destruct()
54    {
55        $this->irc->unregisterActionId($this->handlerids);
56    }
57
58    public function query_test($irc, $data)
59    {
60        // result is sent to #smartirc-test
61        $irc->message(SMARTIRC_TYPE_CHANNEL, '#smartirc-test', $data->nick.' said "'.$data->message.'" to me!');
62        $irc->message(SMARTIRC_TYPE_QUERY, $data->nick, 'I told everyone on #smartirc-test what you said!');
63    }
64}
65
66$irc = new Net_SmartIRC(array(
67    'DebugLevel' => SMARTIRC_DEBUG_ALL,
68));
69$irc->loadModule('MyBot')
70    ->connect('ssl://chat.freenode.net', 6697)
71    ->login('Net_SmartIRC', 'example.php', 0, 'Net_SmartIRC')
72    ->join(array('#smartirc-test'))
73    ->listen()
74    ->disconnect();
75