-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
bot.php
56 lines (45 loc) · 1.39 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
<?php
/*
* Copyright (c) 2019 Keira Dueck <[email protected]>
* Use of this source code is governed by the MIT license, which
* can be found in the LICENSE file.
*/
namespace Huntress;
use React\EventLoop\Factory;
use Throwable;
if (PHP_SAPI != "cli") {
die("Only run from the command-line.");
}
require_once __DIR__ . "/vendor/autoload.php";
require_once __DIR__ . "/config.php";
// grab out git ID and thow it in a const
exec("git diff --quiet HEAD", $null, $rv);
define('VERSION', trim(`git rev-parse HEAD`) . ($rv == 1 ? "-modified" : ""));
// error handling
set_exception_handler(function (Throwable $e) {
if (property_exists($e, "xdebug_message")) {
echo $e->xdebug_message;
} else {
echo $e->getMessage() . PHP_EOL . PHP_EOL . $e->getTraceAsString();
}
});
if (!is_writable("temp")) {
if (!mkdir("temp", 0770)) {
die("Huntress must be able to write to the 'temp' directory. Please make this dir, give permissions, and try again");
}
}
foreach (glob(__DIR__ . "/src/Huntress/Plugin/*.php") as $file) {
require_once($file);
}
$huntress_inhibit_auto_restart = false;
register_shutdown_function(function () {
global $huntress_inhibit_auto_restart;
if ($huntress_inhibit_auto_restart) {
die(0);
} else {
die(1);
}
});
$bot = new Huntress($config, Factory::create());
$bot->log->info('Connecting to discord...');
$bot->start();