-
Notifications
You must be signed in to change notification settings - Fork 47
/
Copy pathphpbot404.php
89 lines (67 loc) · 2.65 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
<?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');
}
$timezone = ini_get('date.timezone');
if (empty($timezone)) {
if (empty($config['timezone']))
$config['timezone'] = 'UTC';
date_default_timezone_set($config['timezone']);
}
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']);
if ( isset( $config['password'] ) ) {
$bot->setPassword ( $config['password'] );
}
$bot->setMaxReconnects( $config['max_reconnects'] );
// Initialise the LogManager.
$log = new Library\IRC\Log($config['log']);
// Attach the LogManager instance to the Bot.
$bot->setupLogging($log);
// 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.