forked from super3/IRC-Bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
phpbot404.php
73 lines (55 loc) · 2.2 KB
/
phpbot404.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<?php
/**
* IRC Bot
*
* LICENSE: This source file is subject to Creative Commons Attribution
* 3.0 License that is available through the world-wide-web at the following URI:
* http://creativecommons.org/licenses/by/3.0/. Basically you are free to adapt
* and use this script commercially/non-commercially. My only requirement is that
* you keep this header as an attribution to my work. Enjoy!
*
* @license http://creativecommons.org/licenses/by/3.0/
*
* @package IRCBot
* @author Super3 <[email protected]>
* @author Matej Velikonja <[email protected]>
*/
define('ROOT_DIR', __DIR__);
// Configure PHP
//ini_set( 'display_errors', 'on' );
// Make autoload working
require 'Classes/Autoloader.php';
if (file_exists(ROOT_DIR . '/config.local.php')) {
$config = include_once(ROOT_DIR . '/config.local.php');
} else {
$config = include_once(ROOT_DIR . '/config.php');
}
spl_autoload_register( 'Autoloader::load' );
// Create the bot.
$bot = new Library\IRC\Bot();
// Configure the bot.
$bot->setServer( $config['server'] );
$bot->setPort( $config['port'] );
$bot->setChannel( $config['channels'] );
$bot->setName( $config['name'] );
$bot->setNick( $config['nick']);
$bot->setMaxReconnects( $config['max_reconnects'] );
$bot->setLogFile( $config['log_file'] );
// Add commands to the bot.
foreach ($config['commands'] as $commandName => $args) {
$reflector = new ReflectionClass($commandName);
$command = $reflector->newInstanceArgs($args);
$bot->addCommand($command);
}
foreach ($config['listeners'] as $listenerName => $args) {
$reflector = new ReflectionClass($listenerName);
$listener = $reflector->newInstanceArgs($args);
$bot->addListener($listener);
}
if (function_exists('setproctitle')) {
$title = basename(__FILE__, '.php') . ' - ' . $config['nick'];
setproctitle($title);
}
// Connect to the server.
$bot->connectToServer();
// Nothing more possible, the bot runs until script ends.