Begin of quizz plugin.
[irbot.git] / main.php
blob33dd7cd9124595018395e317164362f1b6c06745
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/>.
20 * $Id: main.php 28 2008-01-19 17:17:01Z xrogaan $
23 require_once('./config.php');
24 require_once('./sources/functions.inc.php');
26 debug(true);
27 //set_error_handler('myErrorHandler');
29 require_once('./sources/main-class.inc.php');
30 require_once('./sources/irc-class.inc.php');
31 require_once('./sources/plugins/Controller.php');
32 require_once('./sources/tick-class.inc.php');
33 require_once('./sources/TextFormat-class.inc.php');
35 echo <<<EOF
37 IrBot Copyright (C) 2007 Bellière Ludovic
38 This program comes with ABSOLUTELY NO WARRANTY;
39 This is free software, and you are welcome to redistribute it
40 under certain conditions; for details see <http://www.gnu.org/licenses/>.
43 EOF;
45 // searching for command line option
46 if (isset($argv[1])) {
47 $i=1;
48 while (isset($argv[$i])) {
49 $val = false;
50 $option = $argv[$i];
51 if (substr_count($option,'=') === 1) {
52 list($option,$val) = explode('=',$option);
55 if (!$val && ($option != '-h' && $option != '--help')) {
56 $i++;
57 $val = $argv[$i];
60 switch ($option) {
61 case '-h':case '--help':
62 echo "
63 ./main.php [options]
65 Options :
66 -s Equivalent to --server=name
67 -p Equivalent to --port=number
68 -c Equivalent to --channel=#name
69 -n Equivalent to --nick=name
70 -i Equivalent to --ip=number
71 -d Equivalent to --domain=HOST
72 -a Equivalent to --password=pwd
73 --server=name
74 IRC server to connect (default: ".IRC_SERVER.")
75 --port=number
76 Port to use (default: ".IRC_PORT.")
77 --channel=#value
78 Channel to join (default: ".IRC_CHANNEL.")
79 --nick=nickname
80 Nick of the bot (default: ".IRC_PSEUDO.")
81 --ip=xxx.xxx.xxx.xxx
82 Local ip (default: ".IRC_IP.")
83 --domain=HOST
84 Local domain (default: ".IRC_DOMAIN.")
85 --password=pwd
86 Server password (default: ".IRC_PASSWORD.")
88 $stop = true;
89 break;
90 case '-s':case '--server':
91 bot::$server = $val;
92 break;
93 case '-p':case '--port':
94 bot::$port = (int) $val;
95 break;
96 case '-c':case '--channel':
97 bot::$channel = $val;
98 break;
99 case '-n':case '--nick':
100 bot::$myBotName = $val;
101 break;
102 case '-i':case '--ip':
103 if (ereg("[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}",$val)) {
104 bot::$ip = $val;
105 } else {
106 echo "The ip adress entered is wrong.\nUsing default ip instead : ".IRC_IP."\n";
108 break;
109 case '-d':case '--domain':
110 bot::$domain = $val;
111 break;
112 case '-a':case '--password':
113 bot::$connection_password = $val;
114 break;
115 default:
116 break;
118 $i++;
120 if (isset($stop)) {
121 die();
125 if (!isset(bot::$server)) bot::$server = IRC_SERVER;
126 if (!isset(bot::$port)) bot::$port = (int) IRC_PORT;
127 if (!isset(bot::$channel)) bot::$channel = IRC_CHANNEL;
128 if (!isset(bot::$myBotName)) bot::$myBotName = IRC_PSEUDO;
129 if (!isset(bot::$ip)) bot::$ip = IRC_IP;
130 if (!isset(bot::$domain)) bot::$domain = IRC_DOMAIN;
131 if (!isset(bot::$connection_password)) bot::$connection_password = IRC_PASSWORD;
133 $MainProc = bot::GetInstance();
134 while (1) {
136 // On charge les plugins que l'on souhaite
137 $MainProc->plugins->load_plugin('sample');
138 $MainProc->plugins->load_plugin('jet');
140 // On lance le bot
141 try {
142 $MainProc -> launch();
143 } catch (Exception $e) {
144 switch($e->getCode()) {
145 case 0:
146 echo $e->getMessage()."\n";
147 echo "Process terminating...\n";
148 die("EOL from client\n");
149 break 2;
150 case 1: // SIGHUP restart
151 echo $e->getMessage()."\n";
152 echo "Process restarting ...\n\n";
153 continue 2;
154 case 3: // SIGQUIT
155 die("EOL from user...\n");
156 break 2;