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
|
|
|
public $config; |
34
|
|
|
public $discord; |
35
|
|
|
public $logger; |
36
|
|
|
private $excludeChannel; |
37
|
|
|
private $message; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @param $config |
41
|
|
|
* @param $discord |
42
|
|
|
* @param $logger |
43
|
|
|
*/ |
44
|
|
View Code Duplication |
public function init($config, $discord, $logger) |
|
|
|
|
45
|
|
|
{ |
46
|
|
|
$this->config = $config; |
47
|
|
|
$this->discord = $discord; |
48
|
|
|
$this->logger = $logger; |
49
|
|
|
$this->excludeChannel = $this->config['bot']['restrictedChannels']; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @param $msgData |
54
|
|
|
* @param $message |
55
|
|
|
* @return null |
56
|
|
|
*/ |
57
|
|
|
public function onMessage($msgData, $message) |
58
|
|
|
{ |
59
|
|
|
$channelID = (int) $msgData['message']['channelID']; |
60
|
|
|
|
61
|
|
|
if (in_array($channelID, $this->excludeChannel, true)) |
62
|
|
|
{ |
63
|
|
|
return null; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
$this->message = $message; |
67
|
|
|
|
68
|
|
|
$message = $msgData['message']['message']; |
69
|
|
|
$user = $msgData['message']['from']; |
70
|
|
|
|
71
|
|
|
$data = command($message, $this->information()['trigger'], $this->config['bot']['trigger']); |
72
|
|
|
if (isset($data['trigger'])) { |
73
|
|
|
|
74
|
|
|
// Most EVE players on Discord use their ingame name, so lets support @highlights |
75
|
|
|
$messageString = strstr($data['messageString'], '@') ? str_replace('<@', '', str_replace('>', '', $data['messageString'])) : $data['messageString']; |
76
|
|
|
if (is_numeric($messageString)) { |
77
|
|
|
// The person used @highlighting, so now we got a discord id, lets map that to a name |
78
|
|
|
$messageString = dbQueryField('SELECT name FROM usersSeen WHERE id = :id', 'name', array(':id' => $messageString)); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
$cleanString = urlencode($messageString); |
82
|
|
|
$characterID = urlencode(characterID($cleanString)); |
83
|
|
|
|
84
|
|
|
if (empty($characterID)) { |
85
|
|
|
return $this->message->reply('**Error:** no data available'); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
//Get details |
89
|
|
|
$characterDetails = characterDetails($characterID); |
90
|
|
|
if (null === $characterDetails) { |
91
|
|
|
return $this->message->reply('**Error:** ESI is down. Try again later.'); |
92
|
|
|
} |
93
|
|
|
$corporationID = $characterDetails['corporation_id']; |
94
|
|
|
$corporationName = corpName($corporationID); |
95
|
|
|
if (null === $corporationName) { |
96
|
|
|
return $this->message->reply('**Error:** ESI is down. Try again later.'); |
97
|
|
|
} |
98
|
|
|
$corporationDetails = corpDetails($corporationID); |
99
|
|
|
$allianceID = $corporationDetails['alliance_id']; |
100
|
|
|
$allianceName = allianceName($allianceID); |
101
|
|
|
$characterName = $characterDetails['name']; |
102
|
|
|
$dateOfBirth = $characterDetails['birthday']; |
103
|
|
|
|
104
|
|
|
if ($characterName === null || $characterName === '') { |
105
|
|
|
return $this->message->reply('**Error:** No character found.'); |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
//ZKill lookup |
109
|
|
|
$url = "https://zkillboard.com/api/orderDirection/desc/limit/1/no-items/characterID/{$characterID}/xml/"; |
110
|
|
|
$xml = makeApiRequest($url); |
111
|
|
|
if (empty($xml)) { |
112
|
|
|
return $this->message->reply('**Error:** ZKill is down. Try again later.'); |
113
|
|
|
} |
114
|
|
|
foreach ($xml->result->rowset->row as $kill) { |
115
|
|
|
$lastSeenSystemID = $kill->attributes()->solarSystemID; |
116
|
|
|
$lastSeenSystem = systemName($lastSeenSystemID); |
117
|
|
|
$lastSeenDate = $kill->attributes()->killTime; |
118
|
|
|
} |
119
|
|
|
foreach ($xml->result->rowset->row->rowset->row as $attacker) { |
120
|
|
|
if ($attacker->attributes()->characterID == $characterID) { |
121
|
|
|
$lastSeenShipID = $attacker->attributes()->shipTypeID; |
122
|
|
|
$lastSeenShip = apiTypeName($lastSeenShipID); |
123
|
|
|
} |
124
|
|
|
} |
125
|
|
|
$url = "https://zkillboard.com/character/{$characterID}/"; |
126
|
|
|
|
127
|
|
|
$msg = "```Name: {$characterName} |
128
|
|
|
DOB: {$dateOfBirth} |
129
|
|
|
|
130
|
|
|
Corporation Name: {$corporationName} |
131
|
|
|
Alliance Name: {$allianceName} |
132
|
|
|
|
133
|
|
|
Last Seen In System: {$lastSeenSystem} |
|
|
|
|
134
|
|
|
Last Seen Flying a: {$lastSeenShip} |
|
|
|
|
135
|
|
|
Last Seen On: {$lastSeenDate}``` |
|
|
|
|
136
|
|
|
|
137
|
|
|
For more info, visit: $url"; |
138
|
|
|
|
139
|
|
|
$this->logger->addInfo("charInfo: Sending character info to {$user}"); |
140
|
|
|
$this->message->reply($msg); |
141
|
|
|
} |
142
|
|
|
return null; |
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
/** |
146
|
|
|
* @return array |
147
|
|
|
*/ |
148
|
|
View Code Duplication |
public function information() |
|
|
|
|
149
|
|
|
{ |
150
|
|
|
return array( |
151
|
|
|
'name' => 'char', |
152
|
|
|
'trigger' => array($this->config['bot']['trigger'] . 'char'), |
153
|
|
|
'information' => 'Returns basic EVE Online data about a character. To use simply type !char character_name' |
154
|
|
|
); |
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
} |
158
|
|
|
|
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.