|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Sovereign\Plugins\onMessage; |
|
4
|
|
|
|
|
5
|
|
|
use Discord\Discord; |
|
6
|
|
|
use Discord\Parts\Channel\Message; |
|
7
|
|
|
use Monolog\Logger; |
|
8
|
|
|
use Sovereign\Lib\Config; |
|
|
|
|
|
|
9
|
|
|
use Sovereign\Lib\cURL; |
|
10
|
|
|
use Sovereign\Lib\Db; |
|
11
|
|
|
use Sovereign\Lib\Permissions; |
|
12
|
|
|
use Sovereign\Lib\ServerConfig; |
|
13
|
|
|
use Sovereign\Lib\Settings; |
|
14
|
|
|
use Sovereign\Lib\Users; |
|
15
|
|
|
|
|
16
|
|
|
class corp extends \Threaded implements \Collectable |
|
17
|
|
|
{ |
|
18
|
|
|
/** |
|
19
|
|
|
* @var Message |
|
20
|
|
|
*/ |
|
21
|
|
|
private $message; |
|
22
|
|
|
/** |
|
23
|
|
|
* @var Discord |
|
24
|
|
|
*/ |
|
25
|
|
|
private $discord; |
|
26
|
|
|
/** |
|
27
|
|
|
* @var Logger |
|
28
|
|
|
*/ |
|
29
|
|
|
private $log; |
|
30
|
|
|
/** |
|
31
|
|
|
* @var array |
|
32
|
|
|
*/ |
|
33
|
|
|
private $channelConfig; |
|
34
|
|
|
/** |
|
35
|
|
|
* @var Config |
|
36
|
|
|
*/ |
|
37
|
|
|
private $config; |
|
38
|
|
|
/** |
|
39
|
|
|
* @var Db |
|
40
|
|
|
*/ |
|
41
|
|
|
private $db; |
|
42
|
|
|
/** |
|
43
|
|
|
* @var cURL |
|
44
|
|
|
*/ |
|
45
|
|
|
private $curl; |
|
46
|
|
|
/** |
|
47
|
|
|
* @var Settings |
|
48
|
|
|
*/ |
|
49
|
|
|
private $settings; |
|
50
|
|
|
/** |
|
51
|
|
|
* @var Permissions |
|
52
|
|
|
*/ |
|
53
|
|
|
private $permissions; |
|
54
|
|
|
/** |
|
55
|
|
|
* @var ServerConfig |
|
56
|
|
|
*/ |
|
57
|
|
|
private $serverConfig; |
|
58
|
|
|
/** |
|
59
|
|
|
* @var Users |
|
60
|
|
|
*/ |
|
61
|
|
|
private $users; |
|
62
|
|
|
/** |
|
63
|
|
|
* @var array |
|
64
|
|
|
*/ |
|
65
|
|
|
private $extras; |
|
66
|
|
|
|
|
67
|
|
View Code Duplication |
public function __construct($message, $discord, $channelConfig, $log, $config, $db, $curl, $settings, $permissions, $serverConfig, $users, $extras) |
|
|
|
|
|
|
68
|
|
|
{ |
|
69
|
|
|
$this->message = $message; |
|
70
|
|
|
$this->discord = $discord; |
|
71
|
|
|
$this->channelConfig = $channelConfig; |
|
72
|
|
|
$this->log = $log; |
|
73
|
|
|
$this->config = $config; |
|
74
|
|
|
$this->db = $db; |
|
75
|
|
|
$this->curl = $curl; |
|
76
|
|
|
$this->settings = $settings; |
|
77
|
|
|
$this->permissions = $permissions; |
|
78
|
|
|
$this->serverConfig = $serverConfig; |
|
79
|
|
|
$this->users = $users; |
|
80
|
|
|
$this->extras = $extras; |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
public function run() |
|
84
|
|
|
{ |
|
85
|
|
|
$explode = explode(" ", $this->message->content); |
|
86
|
|
|
unset($explode[0]); |
|
87
|
|
|
$name = implode(" ", $explode); |
|
88
|
|
|
|
|
89
|
|
|
$url = "https://evedata.xyz/api/search/corporation/" . urlencode($name) . "/"; |
|
90
|
|
|
$data = @json_decode($this->curl->get($url), true)["corporation"]; |
|
91
|
|
|
if (empty($data)) { |
|
92
|
|
|
return $this->message->reply("**Error:** no results was returned."); |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
if (count($data) > 1) { |
|
96
|
|
|
$results = array(); |
|
97
|
|
|
foreach ($data as $corp) { |
|
98
|
|
|
$results[] = $corp["corporationName"]; |
|
99
|
|
|
} |
|
100
|
|
|
return $this->message->reply("**Error:** more than one result was returned: " . implode(", ", $results)); |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
// Get stats |
|
104
|
|
|
$corporationID = $data[0]["corporationID"]; |
|
105
|
|
|
$statsURL = "https://beta.eve-kill.net/api/corpInfo/corporationID/" . urlencode($corporationID) . "/"; |
|
106
|
|
|
$stats = json_decode($this->curl->get($statsURL), true); |
|
107
|
|
|
if (empty($stats)) { |
|
108
|
|
|
return $this->message->reply("**Error:** no data available"); |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
$corporationName = @$stats["corporationName"]; |
|
112
|
|
|
$allianceName = isset($stats["allianceName"]) ? $stats["allianceName"] : "None"; |
|
113
|
|
|
$factionName = isset($stats["factionName"]) ? $stats["factionName"] : "None"; |
|
114
|
|
|
$ceoName = @$stats["ceoName"]; |
|
115
|
|
|
$homeStation = @$stats["stationName"]; |
|
116
|
|
|
$taxRate = @$stats["taxRate"]; |
|
117
|
|
|
$corporationActiveArea = @$stats["corporationActiveArea"]; |
|
118
|
|
|
$allianceActiveArea = @$stats["allianceActiveArea"]; |
|
119
|
|
|
$lifeTimeKills = @$stats["lifeTimeKills"]; |
|
120
|
|
|
$lifeTimeLosses = @$stats["lifeTimeLosses"]; |
|
121
|
|
|
$memberCount = @$stats["memberArrayCount"]; |
|
122
|
|
|
$superCaps = @count($stats["superCaps"]); |
|
123
|
|
|
$ePeenSize = @$stats["ePeenSize"]; |
|
124
|
|
|
$url = "https://beta.eve-kill.net/corporation/" . @$stats["corporationID"] . "/"; |
|
125
|
|
|
$msg = "```corporationName: {$corporationName} |
|
126
|
|
|
allianceName: {$allianceName} |
|
127
|
|
|
factionName: {$factionName} |
|
128
|
|
|
ceoName: {$ceoName} |
|
129
|
|
|
homeStation: {$homeStation} |
|
130
|
|
|
taxRate: {$taxRate} |
|
131
|
|
|
corporationActiveArea: {$corporationActiveArea} |
|
132
|
|
|
allianceActiveArea: {$allianceActiveArea} |
|
133
|
|
|
lifeTimeKills: {$lifeTimeKills} |
|
134
|
|
|
lifeTimeLosses: {$lifeTimeLosses} |
|
135
|
|
|
memberCount: {$memberCount} |
|
136
|
|
|
superCaps: {$superCaps} |
|
137
|
|
|
ePeenSize: {$ePeenSize} |
|
138
|
|
|
``` |
|
139
|
|
|
For more info, visit: $url"; |
|
140
|
|
|
|
|
141
|
|
|
$this->message->reply($msg); |
|
142
|
|
|
|
|
143
|
|
|
// Mark this as garbage |
|
144
|
|
|
$this->isGarbage(); |
|
145
|
|
|
} |
|
146
|
|
|
} |
Let’s assume that you have a directory layout like this:
. |-- OtherDir | |-- Bar.php | `-- Foo.php `-- SomeDir `-- Foo.phpand let’s assume the following content of
Bar.php:If both files
OtherDir/Foo.phpandSomeDir/Foo.phpare loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.phpHowever, as
OtherDir/Foo.phpdoes not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: