16
[irbot.git] / main.php
bloba215449f34fe867aae9e4c96509930757afd999f
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/TextFormat-class.inc.php');
51 // Nouvelle instance de la classe IRCMain
52 bot::$server = $server;
53 bot::$port = $port;
54 bot::$channel = $chan;
55 bot::$myBotName = $name;
56 bot::$ip = '127.0.0.1';
57 bot::$domain = 'localhost';
58 bot::$connection_password = false;
60 echo <<<EOF
62 IrBot Copyright (C) 2007 Bellière Ludovic
63 This program comes with ABSOLUTELY NO WARRANTY;
64 This is free software, and you are welcome to redistribute it
65 under certain conditions; for details see <http://www.gnu.org/licenses/>.
67 EOF;
69 $MainProc = bot::GetInstance();
70 while (1) {
72 // On charge les plugins que l'on souhaite
73 $MainProc->plugins->load_plugin('sample');
74 $MainProc->plugins->load_plugin('jet');
76 // On lance le bot
77 try {
78 $MainProc -> launch();
79 } catch (Exception $e) {
80 switch($e->getCode()) {
81 case 0:
82 echo $e->getMessage()."\n";
83 echo "Process terminating...\n";
84 die("EOL from client\n");
85 break 2;
86 case 1: // SIGHUP restart
87 echo $e->getMessage()."\n";
88 echo "Process restarting ...\n\n";
89 continue 2;
90 case 3: // SIGQUIT
91 die("EOL from user...\n");
92 break 2;
93 case 'TIMEOUT':
94 continue 2;