cvs: pear /Net_SmartIRC/examples example.php example2.php example3.php example4.php example5.php example6.php example7.php
| From: | Mirco " MEEBEY " Bauer | Date: | Tue, 14 Jan 2003 22:32:32 +0000 |
| Subject: | cvs: pear /Net_SmartIRC/examples example.php example2.php example3.php example4.php example5.php example6.php example7.php | ||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-8260@lists.php.net to get a copy of this message | ||
meebey Tue Jan 14 17:32:32 2003 EDT
Added files:
/pear/Net_SmartIRC/examples example.php example2.php example3.php
example4.php example5.php example6.php
example7.php
Log:
moved from Net_SmartIRC/SmartIRC to Net_SmartIRC/examples
Index: pear/Net_SmartIRC/examples/example.php +++ pear/Net_SmartIRC/examples/example.php <?php /** * $Id: example.php,v 1.1 2003/01/14 22:32:32 meebey Exp $ * $Revision: 1.1 $ * $Author: meebey $ * $Date: 2003/01/14 22:32:32 $ */ /** * Copyright (c) 2002-2003 Mirco "MEEBEY" Bauer <mail@meebey.net> <http://www.meebey.net> * * Full LGPL License: <http://www.meebey.net/lgpl.txt> * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ // ---EXAMPLE OF HOW TO USE Net_SmartIRC--- // this code shows how a mini php bot which could be written include_once('../SmartIRC.php'); class mybot { function channel_test(&$irc, &$data) { $irc->message(SMARTIRC_TYPE_CHANNEL, $data->channel, $data->nick.': I dont like tests!'); } function query_test(&$irc, &$data) { // result is send to #smartirc-test (we don't want to spam #test) $irc->message(SMARTIRC_TYPE_CHANNEL, '#smartirc-test', $data->nick.' said "'.$data->message.'" to me!'); $irc->message(SMARTIRC_TYPE_QUERY, $data->nick, 'I told everyone on #smartirc-test what you said!'); } } $bot = &new mybot(); $irc = &new Net_SmartIRC(); $irc->setDebug(SMARTIRC_DEBUG_ALL); $irc->setUseSockets(TRUE); $irc->registerActionhandler(SMARTIRC_TYPE_QUERY|SMARTIRC_TYPE_NOTICE, '^test', $bot, 'query_test'); $irc->registerActionhandler(SMARTIRC_TYPE_CHANNEL, '^test', $bot, 'channel_test'); $irc->connect('irc.freenet.de', 6667); $irc->login('Net_SmartIRC', 'Net_SmartIRC Client '.SMARTIRC_VERSION, 0, 'Net_SmartIRC'); $irc->join(array('#smartirc-test','#test')); $irc->listen(); $irc->disconnect(); ?> Index: pear/Net_SmartIRC/examples/example2.php +++ pear/Net_SmartIRC/examples/example2.php <?php /** * $Id: example2.php,v 1.1 2003/01/14 22:32:32 meebey Exp $ * $Revision: 1.1 $ * $Author: meebey $ * $Date: 2003/01/14 22:32:32 $ */ /** * Copyright (c) 2002-2003 Mirco "MEEBEY" Bauer <mail@meebey.net> <http://www.meebey.net> * * Full LGPL License: <http://www.meebey.net/lgpl.txt> * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ // ---EXAMPLE OF HOW TO USE Net_SmartIRC--- // this code shows how you could show on your homepage how many users are in a specific channel include_once('../SmartIRC.php'); $irc = &new Net_SmartIRC(); $irc->startBenchmark(); $irc->setDebug(SMARTIRC_DEBUG_ALL); $irc->setUseSockets(TRUE); $irc->setBenchmark(TRUE); $irc->connect('irc.freenet.de', 6667); $irc->login('Net_SmartIRC', 'Net_SmartIRC Client '.SMARTIRC_VERSION, 0, 'Net_SmartIRC'); $irc->getList('#debian.de'); $resultar = $irc->listenFor(SMARTIRC_TYPE_LIST); $irc->disconnect(); $irc->stopBenchmark(); if (is_array($resultar)) { $resultex = explode(' ', $resultar[0]); $count = $resultex[1]; ?> <B>On our IRC Channel #debian.de are <? echo $count; ?> Users</B> <? } else { ?> <B>An error occured, please check the specified server and settings<B> <? } ?> Index: pear/Net_SmartIRC/examples/example3.php +++ pear/Net_SmartIRC/examples/example3.php <?php /** * $Id: example3.php,v 1.1 2003/01/14 22:32:32 meebey Exp $ * $Revision: 1.1 $ * $Author: meebey $ * $Date: 2003/01/14 22:32:32 $ */ /** * Copyright (C) 2002-2003 Mirco "MEEBEY" Bauer <mail@meebey.net> <http://www.meebey.net> * * Full LGPL License: <http://www.meebey.net/lgpl.txt> * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ // ---EXAMPLE OF HOW TO USE Net_SmartIRC--- // this code shows how a mini php bot could be written include_once('../SmartIRC.php'); class mybot { function op_list(&$irc, &$data) { $irc->message(SMARTIRC_TYPE_CHANNEL, '#smartirc-test', 'ops on this channel are:'); $oplist = ''; foreach ($irc->channel['#test']->ops as $key => $value) { $oplist .= ' '.$key; } // result is send to #smartirc-test (we don't want to spam #test) $irc->message(SMARTIRC_TYPE_CHANNEL, '#smartirc-test', $oplist); } } $bot = &new mybot(); $irc = &new Net_SmartIRC(); $irc->setDebug(SMARTIRC_DEBUG_ALL); $irc->setUseSockets(TRUE); $irc->setChannelSynching(TRUE); $irc->registerActionhandler(SMARTIRC_TYPE_CHANNEL, '^!ops', $bot, 'op_list'); $irc->connect('irc.freenet.de', 6667); $irc->login('Net_SmartIRC', 'Net_SmartIRC Client '.SMARTIRC_VERSION, 8, 'Net_SmartIRC'); $irc->join(array('#smartirc-test','#test')); $irc->listen(); $irc->disconnect(); ?> Index: pear/Net_SmartIRC/examples/example4.php +++ pear/Net_SmartIRC/examples/example4.php <?php /** * $Id: example4.php,v 1.1 2003/01/14 22:32:32 meebey Exp $ * $Revision: 1.1 $ * $Author: meebey $ * $Date: 2003/01/14 22:32:32 $ */ /** * Copyright (C) 2002-2003 Mirco "MEEBEY" Bauer <mail@meebey.net> <http://www.meebey.net> * * Full LGPL License: <http://www.meebey.net/lgpl.txt> * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ // ---EXAMPLE OF HOW TO USE Net_SmartIRC--- // this code shows how a mini php bot could be written include_once('../SmartIRC.php'); class mybot { function realname_check(&$irc, &$data) { // lets loop through all user that are on the #test channel // result is send to #smartirc-test (we don't want to spam #test) foreach ($irc->channel['#test']->users as $value) { $nickname = $value->nick; $realname = $value->realname; // lets match against this realname regex, which wants (capital-letter) *(small-letter) (space) (capital-letter) *(small-letter) if(preg_match('/^[A-Z][a-z]+ ([A-Z][a-z]+(\-[A-Z][a-z]+)?)+/', $realname) == 0) $irc->message(SMARTIRC_TYPE_CHANNEL, '#smartirc-test', $nickname.' has not valid realname! ('.$realname.')'); else $irc->message(SMARTIRC_TYPE_CHANNEL, '#smartirc-test', $nickname.' approved ('.$realname.')'); } $irc->message(SMARTIRC_TYPE_CHANNEL, '#smartirc-test', '<end of realnamecheck>'); } } $bot = &new mybot(); $irc = &new Net_SmartIRC(); $irc->setDebug(SMARTIRC_DEBUG_ALL); $irc->setUseSockets(TRUE); // activating the channel synching is important, or we won't have $irc->channel[] available $irc->setChannelSynching(TRUE); $irc->registerActionhandler(SMARTIRC_TYPE_CHANNEL, '^!realnamecheck', $bot, 'realname_check'); $irc->connect('irc.freenet.de', 6667); $irc->login('Net_SmartIRC', 'Net_SmartIRC Client '.SMARTIRC_VERSION, 8, 'Net_SmartIRC'); $irc->join(array('#smartirc-test','#test')); $irc->listen(); $irc->disconnect(); ?> Index: pear/Net_SmartIRC/examples/example5.php +++ pear/Net_SmartIRC/examples/example5.php <?php /** * $Id: example5.php,v 1.1 2003/01/14 22:32:32 meebey Exp $ * $Revision: 1.1 $ * $Author: meebey $ * $Date: 2003/01/14 22:32:32 $ */ /** * Copyright (C) 2002-2003 Mirco "MEEBEY" Bauer <mail@meebey.net> <http://www.meebey.net> * * Full LGPL License: <http://www.meebey.net/lgpl.txt> * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ // ---EXAMPLE OF HOW TO USE Net_SmartIRC--- // this code shows how a mini php bot could be written include_once('../SmartIRC.php'); class mybot { function kick(&$irc, &$data) { // we need the nickname parameter if(isset($irc->messageex[1])) { $nickname = $irc->messageex[1]; $channel = $irc->channel; $irc->kick($channel, $nickname); } else { $irc->message( $data->type, $data->nick, 'wrong parameter count' ); $irc->message( $data->type, $data->nick, 'usage: !kick $nickname' ); } } } $bot = &new mybot(); $irc = &new Net_SmartIRC(); $irc->setDebug(SMARTIRC_DEBUG_ALL); $irc->setUseSockets(TRUE); $irc->registerActionhandler(SMARTIRC_TYPE_CHANNEL, '^!kick', $bot, 'kick'); $irc->connect('irc.freenet.de', 6667); $irc->login('Net_SmartIRC', 'Net_SmartIRC Client '.SMARTIRC_VERSION, 8, 'Net_SmartIRC'); $irc->join('#test'); $irc->listen(); $irc->disconnect(); ?> Index: pear/Net_SmartIRC/examples/example6.php +++ pear/Net_SmartIRC/examples/example6.php <?php /** * $Id: example6.php,v 1.1 2003/01/14 22:32:32 meebey Exp $ * $Revision: 1.1 $ * $Author: meebey $ * $Date: 2003/01/14 22:32:32 $ */ /** * Copyright (C) 2002-2003 Mirco "MEEBEY" Bauer <mail@meebey.net> <http://www.meebey.net> * * Full LGPL License: <http://www.meebey.net/lgpl.txt> * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ // ---EXAMPLE OF HOW TO USE Net_SmartIRC--- // this code shows how a mini php bot could be written include_once('../SmartIRC.php'); class mybot { function onjoin_greeting(&$irc, &$data) { // if _we_ join, don't greet ourself, just jump out via return if ($data->nick == $irc->_nick) return; // now check if this is the right channel if ($data->channel == '#test') // it is, lets greet the joint user $irc->message(SMARTIRC_TYPE_CHANNEL, '#test', 'hi '.$data->nick); } } $bot = &new mybot(); $irc = &new Net_SmartIRC(); $irc->setDebug(SMARTIRC_DEBUG_ALL); $irc->setUseSockets(TRUE); $irc->registerActionhandler(SMARTIRC_TYPE_JOIN, '.*', $bot, 'onjoin_greeting'); $irc->connect('irc.freenet.de', 6667); $irc->login('Net_SmartIRC', 'Net_SmartIRC Client '.SMARTIRC_VERSION, 8, 'Net_SmartIRC'); $irc->join(array('#smartirc-test','#test')); $irc->listen(); $irc->disconnect(); ?> Index: pear/Net_SmartIRC/examples/example7.php +++ pear/Net_SmartIRC/examples/example7.php <?php /** * $Id: example7.php,v 1.1 2003/01/14 22:32:32 meebey Exp $ * $Revision: 1.1 $ * $Author: meebey $ * $Date: 2003/01/14 22:32:32 $ */ /** * Copyright (C) 2002-2003 Mirco "MEEBEY" Bauer <mail@meebey.net> <http://www.meebey.net> * * Full LGPL License: <http://www.meebey.net/lgpl.txt> * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ // ---EXAMPLE OF HOW TO USE Net_SmartIRC--- // this code shows how a mini php bot could be written include_once('../SmartIRC.php'); class mybot { function saytime_once(&$irc) { global $saytime_once_id; $irc->message(SMARTIRC_TYPE_CHANNEL, '#smartirc-test', '(once) the time is: '.date('H:i:s')); $irc->unregisterTimeid($saytime_once_id); } function saytime(&$irc) { $irc->message(SMARTIRC_TYPE_CHANNEL, '#smartirc-test', 'the time is: '.date('H:i:s')); } function quit(&$irc, &$ircdata) { $irc->quit("time to say goodbye..."); } } $bot = &new mybot(); $irc = &new Net_SmartIRC(); $irc->setDebug(SMARTIRC_DEBUG_ALL); $irc->setUseSockets(TRUE); $irc->registerTimehandler(300, $bot, 'saytime'); $saytime_once_id = $irc->registerTimehandler(10, $bot, 'saytime_once'); $irc->registerActionhandler(SMARTIRC_TYPE_CHANNEL, '^!quit', $bot, 'quit'); $irc->connect('irc.freenet.de', 6667); $irc->login('Net_SmartIRC', 'Net_SmartIRC Client '.SMARTIRC_VERSION, 8, 'Net_SmartIRC'); $irc->join(array('#smartirc-test','#test')); $irc->listen(); $irc->disconnect(); ?>
Index: pear/Net_SmartIRC/examples/example.php +++ pear/Net_SmartIRC/examples/example.php <?php /** * $Id: example.php,v 1.1 2003/01/14 22:32:32 meebey Exp $ * $Revision: 1.1 $ * $Author: meebey $ * $Date: 2003/01/14 22:32:32 $ */ /** * Copyright (c) 2002-2003 Mirco "MEEBEY" Bauer <mail@meebey.net> <http://www.meebey.net> * * Full LGPL License: <http://www.meebey.net/lgpl.txt> * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ // ---EXAMPLE OF HOW TO USE Net_SmartIRC--- // this code shows how a mini php bot which could be written include_once('../SmartIRC.php'); class mybot { function channel_test(&$irc, &$data) { $irc->message(SMARTIRC_TYPE_CHANNEL, $data->channel, $data->nick.': I dont like tests!'); } function query_test(&$irc, &$data) { // result is send to #smartirc-test (we don't want to spam #test) $irc->message(SMARTIRC_TYPE_CHANNEL, '#smartirc-test', $data->nick.' said "'.$data->message.'" to me!'); $irc->message(SMARTIRC_TYPE_QUERY, $data->nick, 'I told everyone on #smartirc-test what you said!'); } } $bot = &new mybot(); $irc = &new Net_SmartIRC(); $irc->setDebug(SMARTIRC_DEBUG_ALL); $irc->setUseSockets(TRUE); $irc->registerActionhandler(SMARTIRC_TYPE_QUERY|SMARTIRC_TYPE_NOTICE, '^test', $bot, 'query_test'); $irc->registerActionhandler(SMARTIRC_TYPE_CHANNEL, '^test', $bot, 'channel_test'); $irc->connect('irc.freenet.de', 6667); $irc->login('Net_SmartIRC', 'Net_SmartIRC Client '.SMARTIRC_VERSION, 0, 'Net_SmartIRC'); $irc->join(array('#smartirc-test','#test')); $irc->listen(); $irc->disconnect(); ?> Index: pear/Net_SmartIRC/examples/example2.php +++ pear/Net_SmartIRC/examples/example2.php <?php /** * $Id: example2.php,v 1.1 2003/01/14 22:32:32 meebey Exp $ * $Revision: 1.1 $ * $Author: meebey $ * $Date: 2003/01/14 22:32:32 $ */ /** * Copyright (c) 2002-2003 Mirco "MEEBEY" Bauer <mail@meebey.net> <http://www.meebey.net> * * Full LGPL License: <http://www.meebey.net/lgpl.txt> * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ // ---EXAMPLE OF HOW TO USE Net_SmartIRC--- // this code shows how you could show on your homepage how many users are in a specific channel include_once('../SmartIRC.php'); $irc = &new Net_SmartIRC(); $irc->startBenchmark(); $irc->setDebug(SMARTIRC_DEBUG_ALL); $irc->setUseSockets(TRUE); $irc->setBenchmark(TRUE); $irc->connect('irc.freenet.de', 6667); $irc->login('Net_SmartIRC', 'Net_SmartIRC Client '.SMARTIRC_VERSION, 0, 'Net_SmartIRC'); $irc->getList('#debian.de'); $resultar = $irc->listenFor(SMARTIRC_TYPE_LIST); $irc->disconnect(); $irc->stopBenchmark(); if (is_array($resultar)) { $resultex = explode(' ', $resultar[0]); $count = $resultex[1]; ?> <B>On our IRC Channel #debian.de are <? echo $count; ?> Users</B> <? } else { ?> <B>An error occured, please check the specified server and settings<B> <? } ?> Index: pear/Net_SmartIRC/examples/example3.php +++ pear/Net_SmartIRC/examples/example3.php <?php /** * $Id: example3.php,v 1.1 2003/01/14 22:32:32 meebey Exp $ * $Revision: 1.1 $ * $Author: meebey $ * $Date: 2003/01/14 22:32:32 $ */ /** * Copyright (C) 2002-2003 Mirco "MEEBEY" Bauer <mail@meebey.net> <http://www.meebey.net> * * Full LGPL License: <http://www.meebey.net/lgpl.txt> * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ // ---EXAMPLE OF HOW TO USE Net_SmartIRC--- // this code shows how a mini php bot could be written include_once('../SmartIRC.php'); class mybot { function op_list(&$irc, &$data) { $irc->message(SMARTIRC_TYPE_CHANNEL, '#smartirc-test', 'ops on this channel are:'); $oplist = ''; foreach ($irc->channel['#test']->ops as $key => $value) { $oplist .= ' '.$key; } // result is send to #smartirc-test (we don't want to spam #test) $irc->message(SMARTIRC_TYPE_CHANNEL, '#smartirc-test', $oplist); } } $bot = &new mybot(); $irc = &new Net_SmartIRC(); $irc->setDebug(SMARTIRC_DEBUG_ALL); $irc->setUseSockets(TRUE); $irc->setChannelSynching(TRUE); $irc->registerActionhandler(SMARTIRC_TYPE_CHANNEL, '^!ops', $bot, 'op_list'); $irc->connect('irc.freenet.de', 6667); $irc->login('Net_SmartIRC', 'Net_SmartIRC Client '.SMARTIRC_VERSION, 8, 'Net_SmartIRC'); $irc->join(array('#smartirc-test','#test')); $irc->listen(); $irc->disconnect(); ?> Index: pear/Net_SmartIRC/examples/example4.php +++ pear/Net_SmartIRC/examples/example4.php <?php /** * $Id: example4.php,v 1.1 2003/01/14 22:32:32 meebey Exp $ * $Revision: 1.1 $ * $Author: meebey $ * $Date: 2003/01/14 22:32:32 $ */ /** * Copyright (C) 2002-2003 Mirco "MEEBEY" Bauer <mail@meebey.net> <http://www.meebey.net> * * Full LGPL License: <http://www.meebey.net/lgpl.txt> * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ // ---EXAMPLE OF HOW TO USE Net_SmartIRC--- // this code shows how a mini php bot could be written include_once('../SmartIRC.php'); class mybot { function realname_check(&$irc, &$data) { // lets loop through all user that are on the #test channel // result is send to #smartirc-test (we don't want to spam #test) foreach ($irc->channel['#test']->users as $value) { $nickname = $value->nick; $realname = $value->realname; // lets match against this realname regex, which wants (capital-letter) *(small-letter) (space) (capital-letter) *(small-letter) if(preg_match('/^[A-Z][a-z]+ ([A-Z][a-z]+(\-[A-Z][a-z]+)?)+/', $realname) == 0) $irc->message(SMARTIRC_TYPE_CHANNEL, '#smartirc-test', $nickname.' has not valid realname! ('.$realname.')'); else $irc->message(SMARTIRC_TYPE_CHANNEL, '#smartirc-test', $nickname.' approved ('.$realname.')'); } $irc->message(SMARTIRC_TYPE_CHANNEL, '#smartirc-test', '<end of realnamecheck>'); } } $bot = &new mybot(); $irc = &new Net_SmartIRC(); $irc->setDebug(SMARTIRC_DEBUG_ALL); $irc->setUseSockets(TRUE); // activating the channel synching is important, or we won't have $irc->channel[] available $irc->setChannelSynching(TRUE); $irc->registerActionhandler(SMARTIRC_TYPE_CHANNEL, '^!realnamecheck', $bot, 'realname_check'); $irc->connect('irc.freenet.de', 6667); $irc->login('Net_SmartIRC', 'Net_SmartIRC Client '.SMARTIRC_VERSION, 8, 'Net_SmartIRC'); $irc->join(array('#smartirc-test','#test')); $irc->listen(); $irc->disconnect(); ?> Index: pear/Net_SmartIRC/examples/example5.php +++ pear/Net_SmartIRC/examples/example5.php <?php /** * $Id: example5.php,v 1.1 2003/01/14 22:32:32 meebey Exp $ * $Revision: 1.1 $ * $Author: meebey $ * $Date: 2003/01/14 22:32:32 $ */ /** * Copyright (C) 2002-2003 Mirco "MEEBEY" Bauer <mail@meebey.net> <http://www.meebey.net> * * Full LGPL License: <http://www.meebey.net/lgpl.txt> * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ // ---EXAMPLE OF HOW TO USE Net_SmartIRC--- // this code shows how a mini php bot could be written include_once('../SmartIRC.php'); class mybot { function kick(&$irc, &$data) { // we need the nickname parameter if(isset($irc->messageex[1])) { $nickname = $irc->messageex[1]; $channel = $irc->channel; $irc->kick($channel, $nickname); } else { $irc->message( $data->type, $data->nick, 'wrong parameter count' ); $irc->message( $data->type, $data->nick, 'usage: !kick $nickname' ); } } } $bot = &new mybot(); $irc = &new Net_SmartIRC(); $irc->setDebug(SMARTIRC_DEBUG_ALL); $irc->setUseSockets(TRUE); $irc->registerActionhandler(SMARTIRC_TYPE_CHANNEL, '^!kick', $bot, 'kick'); $irc->connect('irc.freenet.de', 6667); $irc->login('Net_SmartIRC', 'Net_SmartIRC Client '.SMARTIRC_VERSION, 8, 'Net_SmartIRC'); $irc->join('#test'); $irc->listen(); $irc->disconnect(); ?> Index: pear/Net_SmartIRC/examples/example6.php +++ pear/Net_SmartIRC/examples/example6.php <?php /** * $Id: example6.php,v 1.1 2003/01/14 22:32:32 meebey Exp $ * $Revision: 1.1 $ * $Author: meebey $ * $Date: 2003/01/14 22:32:32 $ */ /** * Copyright (C) 2002-2003 Mirco "MEEBEY" Bauer <mail@meebey.net> <http://www.meebey.net> * * Full LGPL License: <http://www.meebey.net/lgpl.txt> * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ // ---EXAMPLE OF HOW TO USE Net_SmartIRC--- // this code shows how a mini php bot could be written include_once('../SmartIRC.php'); class mybot { function onjoin_greeting(&$irc, &$data) { // if _we_ join, don't greet ourself, just jump out via return if ($data->nick == $irc->_nick) return; // now check if this is the right channel if ($data->channel == '#test') // it is, lets greet the joint user $irc->message(SMARTIRC_TYPE_CHANNEL, '#test', 'hi '.$data->nick); } } $bot = &new mybot(); $irc = &new Net_SmartIRC(); $irc->setDebug(SMARTIRC_DEBUG_ALL); $irc->setUseSockets(TRUE); $irc->registerActionhandler(SMARTIRC_TYPE_JOIN, '.*', $bot, 'onjoin_greeting'); $irc->connect('irc.freenet.de', 6667); $irc->login('Net_SmartIRC', 'Net_SmartIRC Client '.SMARTIRC_VERSION, 8, 'Net_SmartIRC'); $irc->join(array('#smartirc-test','#test')); $irc->listen(); $irc->disconnect(); ?> Index: pear/Net_SmartIRC/examples/example7.php +++ pear/Net_SmartIRC/examples/example7.php <?php /** * $Id: example7.php,v 1.1 2003/01/14 22:32:32 meebey Exp $ * $Revision: 1.1 $ * $Author: meebey $ * $Date: 2003/01/14 22:32:32 $ */ /** * Copyright (C) 2002-2003 Mirco "MEEBEY" Bauer <mail@meebey.net> <http://www.meebey.net> * * Full LGPL License: <http://www.meebey.net/lgpl.txt> * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ // ---EXAMPLE OF HOW TO USE Net_SmartIRC--- // this code shows how a mini php bot could be written include_once('../SmartIRC.php'); class mybot { function saytime_once(&$irc) { global $saytime_once_id; $irc->message(SMARTIRC_TYPE_CHANNEL, '#smartirc-test', '(once) the time is: '.date('H:i:s')); $irc->unregisterTimeid($saytime_once_id); } function saytime(&$irc) { $irc->message(SMARTIRC_TYPE_CHANNEL, '#smartirc-test', 'the time is: '.date('H:i:s')); } function quit(&$irc, &$ircdata) { $irc->quit("time to say goodbye..."); } } $bot = &new mybot(); $irc = &new Net_SmartIRC(); $irc->setDebug(SMARTIRC_DEBUG_ALL); $irc->setUseSockets(TRUE); $irc->registerTimehandler(300, $bot, 'saytime'); $saytime_once_id = $irc->registerTimehandler(10, $bot, 'saytime_once'); $irc->registerActionhandler(SMARTIRC_TYPE_CHANNEL, '^!quit', $bot, 'quit'); $irc->connect('irc.freenet.de', 6667); $irc->login('Net_SmartIRC', 'Net_SmartIRC Client '.SMARTIRC_VERSION, 8, 'Net_SmartIRC'); $irc->join(array('#smartirc-test','#test')); $irc->listen(); $irc->disconnect(); ?>