|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* The MIT License (MIT) |
|
4
|
|
|
* |
|
5
|
|
|
* Copyright (c) 2016 Robert Sardinia |
|
6
|
|
|
* |
|
7
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy |
|
8
|
|
|
* of this software and associated documentation files (the "Software"), to deal |
|
9
|
|
|
* in the Software without restriction, including without limitation the rights |
|
10
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
|
11
|
|
|
* copies of the Software, and to permit persons to whom the Software is |
|
12
|
|
|
* furnished to do so, subject to the following conditions: |
|
13
|
|
|
* |
|
14
|
|
|
* The above copyright notice and this permission notice shall be included in all |
|
15
|
|
|
* copies or substantial portions of the Software. |
|
16
|
|
|
* |
|
17
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
|
18
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
|
19
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
|
20
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
|
21
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
|
22
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
|
23
|
|
|
* SOFTWARE. |
|
24
|
|
|
*/ |
|
25
|
|
|
|
|
26
|
|
|
use Discord\Discord; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* @property message |
|
30
|
|
|
*/ |
|
31
|
|
|
class charInfo |
|
|
|
|
|
|
32
|
|
|
{ |
|
33
|
|
|
/** |
|
34
|
|
|
* @var |
|
35
|
|
|
*/ |
|
36
|
|
|
var $config; |
|
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* @var |
|
39
|
|
|
*/ |
|
40
|
|
|
var $discord; |
|
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* @var |
|
43
|
|
|
*/ |
|
44
|
|
|
var $logger; |
|
|
|
|
|
|
45
|
|
|
var $excludeChannel; |
|
|
|
|
|
|
46
|
|
|
public $message; |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* @param $config |
|
50
|
|
|
* @param $discord |
|
51
|
|
|
* @param $logger |
|
52
|
|
|
*/ |
|
53
|
|
View Code Duplication |
function init($config, $discord, $logger) |
|
|
|
|
|
|
54
|
|
|
{ |
|
55
|
|
|
$this->config = $config; |
|
56
|
|
|
$this->discord = $discord; |
|
57
|
|
|
$this->logger = $logger; |
|
58
|
|
|
$this->excludeChannel = $this->config["bot"]["restrictedChannels"]; |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* |
|
63
|
|
|
*/ |
|
64
|
|
|
function tick() |
|
|
|
|
|
|
65
|
|
|
{ |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* @param $msgData |
|
70
|
|
|
* @param $message |
|
71
|
|
|
* @return null |
|
72
|
|
|
*/ |
|
73
|
|
|
function onMessage($msgData, $message) |
|
|
|
|
|
|
74
|
|
|
{ |
|
75
|
|
|
$channelID = (int)$msgData["message"]["channelID"]; |
|
76
|
|
|
|
|
77
|
|
|
if (in_array($channelID, $this->excludeChannel, true)) |
|
78
|
|
|
{ |
|
79
|
|
|
return null; |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
$this->message = $message; |
|
83
|
|
|
|
|
84
|
|
|
$message = $msgData["message"]["message"]; |
|
85
|
|
|
$user = $msgData["message"]["from"]; |
|
86
|
|
|
|
|
87
|
|
|
$data = command($message, $this->information()["trigger"], $this->config["bot"]["trigger"]); |
|
88
|
|
|
if (isset($data["trigger"])) { |
|
89
|
|
|
|
|
90
|
|
|
// Most EVE players on Discord use their ingame name, so lets support @highlights |
|
91
|
|
|
$messageString = stristr($data["messageString"], "@") ? str_replace("<@", "", str_replace(">", "", $data["messageString"])) : $data["messageString"]; |
|
92
|
|
|
if (is_numeric($messageString)) { |
|
93
|
|
|
// The person used @highlighting, so now we got a discord id, lets map that to a name |
|
94
|
|
|
$messageString = dbQueryField("SELECT name FROM usersSeen WHERE id = :id", "name", array(":id" => $messageString)); |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
$cleanString = urlencode($messageString); |
|
98
|
|
|
|
|
99
|
|
|
//API call 1 |
|
100
|
|
|
$url = "https://api.eveonline.com/eve/CharacterID.xml.aspx?names={$cleanString}"; |
|
101
|
|
|
$xml = makeApiRequest($url); |
|
102
|
|
|
$characterID = null; |
|
103
|
|
|
|
|
104
|
|
View Code Duplication |
if (isset($xml->result->rowset->row)) { |
|
|
|
|
|
|
105
|
|
|
foreach ($xml->result->rowset->row as $character) { |
|
106
|
|
|
$characterID = $character->attributes()->characterID; |
|
107
|
|
|
} |
|
108
|
|
|
} |
|
109
|
|
|
if (empty($characterID)) { |
|
110
|
|
|
return $this->message->reply("**Error:** no data available"); |
|
111
|
|
|
} |
|
112
|
|
|
$characterID = urlencode($characterID); |
|
113
|
|
|
|
|
114
|
|
|
//API call 2 |
|
115
|
|
|
$url = "https://api.eveonline.com/eve/CharacterInfo.xml.aspx?characterID={$characterID}"; |
|
116
|
|
|
$xml = makeApiRequest($url); |
|
117
|
|
|
foreach ($xml->result as $characterDetails) { |
|
118
|
|
|
$dob = $characterDetails->DoB; |
|
|
|
|
|
|
119
|
|
|
$corporationName = $characterDetails->corporation; |
|
120
|
|
|
$corporationJoinDate = $characterDetails->corporationDate; |
|
121
|
|
|
$allianceName = $characterDetails->alliance; |
|
122
|
|
|
$securityStatus = $characterDetails->securityStatus; |
|
123
|
|
|
$characterName = $characterDetails->characterName; |
|
124
|
|
|
} |
|
125
|
|
|
|
|
126
|
|
|
//ZKill lookup |
|
127
|
|
|
$url = "https://zkillboard.com/api/orderDirection/desc/limit/1/no-items/characterID/{$characterID}/xml/"; |
|
128
|
|
|
$xml = makeApiRequest($url); |
|
129
|
|
|
if (empty($xml)) { |
|
130
|
|
|
return $this->message->reply("**Error:** ZKill is down. Try again later."); |
|
131
|
|
|
} |
|
132
|
|
|
foreach ($xml->result->rowset->row as $kill) { |
|
133
|
|
|
$lastSeenSystemID = $kill->attributes()->solarSystemID; |
|
134
|
|
|
$lastSeenSystem = apiCharacterName($lastSeenSystemID); |
|
135
|
|
|
$lastSeenDate = $kill->attributes()->killTime; |
|
136
|
|
|
} |
|
137
|
|
|
foreach ($xml->result->rowset->row->rowset->row as $attacker) { |
|
138
|
|
|
if ($attacker->attributes()->characterID == $characterID){ |
|
139
|
|
|
$lastSeenShipID = $attacker->attributes()->shipTypeID; |
|
140
|
|
|
$lastSeenShip = apiTypeName($lastSeenShipID); |
|
141
|
|
|
} |
|
142
|
|
|
} |
|
143
|
|
|
$url = "https://zkillboard.com/character/{$characterID}/"; |
|
144
|
|
|
|
|
145
|
|
|
$msg = "```Name: {$characterName} |
|
|
|
|
|
|
146
|
|
|
|
|
147
|
|
|
Corporation Name: {$corporationName} |
|
|
|
|
|
|
148
|
|
|
Joined Corporation On: {$corporationJoinDate} |
|
|
|
|
|
|
149
|
|
|
Alliance Name: {$allianceName} |
|
|
|
|
|
|
150
|
|
|
Security Status: {$securityStatus} |
|
|
|
|
|
|
151
|
|
|
|
|
152
|
|
|
Last Seen In System: {$lastSeenSystem} |
|
|
|
|
|
|
153
|
|
|
Last Seen Flying a: {$lastSeenShip} |
|
|
|
|
|
|
154
|
|
|
Last Seen On: {$lastSeenDate}``` |
|
|
|
|
|
|
155
|
|
|
|
|
156
|
|
|
For more info, visit: $url"; |
|
157
|
|
|
|
|
158
|
|
|
$this->logger->addInfo("charInfo: Sending character info to {$user}"); |
|
159
|
|
|
$this->message->reply($msg); |
|
160
|
|
|
} |
|
161
|
|
|
return null; |
|
162
|
|
|
} |
|
163
|
|
|
|
|
164
|
|
|
/** |
|
165
|
|
|
* @return array |
|
166
|
|
|
*/ |
|
167
|
|
View Code Duplication |
function information() |
|
|
|
|
|
|
168
|
|
|
{ |
|
169
|
|
|
return array( |
|
170
|
|
|
"name" => "char", |
|
171
|
|
|
"trigger" => array($this->config["bot"]["trigger"] . "char"), |
|
172
|
|
|
"information" => "Returns basic EVE Online data about a character. To use simply type !char character_name" |
|
173
|
|
|
); |
|
174
|
|
|
} |
|
175
|
|
|
|
|
176
|
|
|
function onMessageAdmin() |
|
|
|
|
|
|
177
|
|
|
{ |
|
178
|
|
|
} |
|
179
|
|
|
|
|
180
|
|
|
} |
|
181
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.