20
[irbot.git] / main.php
blob061e8fd4959bf257a484eebaaff75c23dbcc4443
1 #!/usr/bin/php
2 <?php
3 /**
4 * This file is part of IrBot, irc robot.
5 * Copyright (C) 2007 Bellière Ludovic
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
22 // This page need to be rewrited
24 error_reporting(E_ALL);
26 date_default_timezone_set('Europe/Brussels');
28 require_once('./sources/functions.inc.php');
30 debug(true);
31 //set_error_handler('myErrorHandler');
33 // Arguments passés à la ligne de commande
34 if ( isset($argv[1], $argv[2], $argv[3], $argv[4]) ) {
35 $server = $argv[1] ;
36 $port = (int) $argv[2] ;
37 $chan = '#' . $argv[3] ;
38 $name = $argv[4] ;
39 } else {
40 $server = 'irc.tty2.org';
41 $port = 6667;
42 $chan = '#sharesource';
43 $name = 'IrBot';
46 require_once('./sources/main-class.inc.php');
47 require_once('./sources/irc-class.inc.php');
48 require_once('./sources/plugin-class.inc.php');
49 require_once('./sources/tick-class.inc.php');
50 require_once('./sources/TextFormat-class.inc.php');
52 // Nouvelle instance de la classe IRCMain
53 bot::$server = $server;
54 bot::$port = $port;
55 bot::$channel = $chan;
56 bot::$myBotName = $name;
57 bot::$ip = '';
58 bot::$domain = '';
59 bot::$connection_password = false;
61 echo <<<EOF
63 IrBot Copyright (C) 2007 Bellière Ludovic
64 This program comes with ABSOLUTELY NO WARRANTY;
65 This is free software, and you are welcome to redistribute it
66 under certain conditions; for details see <http://www.gnu.org/licenses/>.
69 EOF;
71 $MainProc = bot::GetInstance();
72 while (1) {
74 // On charge les plugins que l'on souhaite
75 $MainProc->plugins->load_plugin('sample');
76 $MainProc->plugins->load_plugin('jet');
78 // On lance le bot
79 try {
80 $MainProc -> launch();
81 } catch (Exception $e) {
82 switch($e->getCode()) {
83 case 0:
84 echo $e->getMessage()."\n";
85 echo "Process terminating...\n";
86 die("EOL from client\n");
87 break 2;
88 case 1: // SIGHUP restart
89 echo $e->getMessage()."\n";
90 echo "Process restarting ...\n\n";
91 continue 2;
92 case 3: // SIGQUIT
93 die("EOL from user...\n");
94 break 2;
95 case 'TIMEOUT':
96 continue 2;