-
Notifications
You must be signed in to change notification settings - Fork 2
/
bot.php
114 lines (87 loc) · 2.44 KB
/
bot.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
<?php
/* Awesome IRC Bot v2
* Created by Jack Harley
*
* Copyright © 2014, Jack P. Harley, jackpharley.com.
* All Rights Reserved
*/
// import
require_once(__DIR__ . "/lib/awesomeircbot/awesomeircbot.inc.php");
require_once(__DIR__ . "/modules/modules.inc.php");
use awesomeircbot\server\Server;
use awesomeircbot\module\ModuleManager;
use awesomeircbot\line\ReceivedLine;
use awesomeircbot\line\ReceivedLineTypes;
use awesomeircbot\command\Command;
use awesomeircbot\event\Event;
use awesomeircbot\trigger\Trigger;
use awesomeircbot\database\Database;
use awesomeircbot\config\Config;
// set up environment
error_reporting(E_ALL & ~E_NOTICE);
passthru('clear');
// welcome the user
echo "Welcome to Awesome IRC Bot v2\n";
echo "http://github.com/JackHarley/AwesomeIRCBot\n";
// import all modules
ModuleManager::initialize();
// get a server instance
$server = Server::getInstance();
// setup database
if (!is_file(__DIR__ . "/config.php"))
die("\nYou need to rename config.php.example to config.php and edit the settings to match your MySQL database\n");
include_once(__DIR__ . "/config.php");
$db = Database::getInstance();
$db->updateScriptArrays();
// configure
Config::initializeRequiredValues();
// update database
$db->updateDatabase();
echo "\n";
$lastUpdate = time();
while (true) {
// Connect
$server->connect();
// Identify
$server->identify();
// If we send anything else too soon after identification it could be
// lost, so sleep for 2 seconds
sleep(2);
// NickServ
if (Config::getValue("nickservPassword"))
$server->identifyWithNickServ();
// Connect commands
ModuleManager::runConnectCommands();
// Loop through the channels in the config and join them
$channels = Config::getValue("channels");
foreach($channels as $channel) {
$server->join($channel);
}
// Loop-edy-loop
while($server->connected()) {
$line = $server->getNextLine();
$line = new ReceivedLine($line);
$line->parse();
if ($line->isMappedCommand()) {
$command = new Command($line);
$command->execute();
}
if ($line->isMappedEvent()) {
$event = new Event($line);
$event->execute();
}
if ($line->isMappedTrigger()) {
$trigger = new Trigger($line);
$trigger->execute();
}
if (time() - 2 >= $lastUpdate) {
$db->updateScriptArrays();
$db->updateDatabase();
$lastUpdate = time();
}
unset($command, $event, $trigger);
}
// Disconnected, Give the server 1 second before we attempt a reconnect
sleep(1);
}
?>