|
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
|
|
|
use Discord\Discord; |
|
26
|
|
|
use Discord\Parts\Channel\Message; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* @property message |
|
30
|
|
|
*/ |
|
31
|
|
|
class charInfo |
|
|
|
|
|
|
32
|
|
|
{ |
|
33
|
|
|
/* |
|
34
|
|
|
* @var |
|
35
|
|
|
*/ |
|
36
|
|
|
public $config; |
|
37
|
|
|
/* |
|
38
|
|
|
* @var |
|
39
|
|
|
*/ |
|
40
|
|
|
public $discord; |
|
41
|
|
|
/* |
|
42
|
|
|
* @var |
|
43
|
|
|
*/ |
|
44
|
|
|
public $logger; |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* @param $config |
|
48
|
|
|
* @param $discord |
|
49
|
|
|
* @param $logger |
|
50
|
|
|
*/ |
|
51
|
|
|
public function init($config, $discord, $logger) |
|
52
|
|
|
{ |
|
53
|
|
|
$this->config = $config; |
|
54
|
|
|
$this->discord = $discord; |
|
55
|
|
|
$this->logger = $logger; |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
|
|
59
|
|
|
public function tick() |
|
60
|
|
|
{ |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* @param $msgData |
|
65
|
|
|
* @param $message |
|
66
|
|
|
* |
|
67
|
|
|
* @return null |
|
68
|
|
|
*/ |
|
69
|
|
|
public function onMessage($msgData, $message) |
|
70
|
|
|
{ |
|
71
|
|
|
$this->message = $message; |
|
|
|
|
|
|
72
|
|
|
|
|
73
|
|
|
$message = $msgData['message']['message']; |
|
74
|
|
|
$user = $msgData['message']['from']; |
|
75
|
|
|
|
|
76
|
|
|
$data = command($message, $this->information()['trigger'], $this->config['bot']['trigger']); |
|
77
|
|
|
if (isset($data['trigger'])) { |
|
78
|
|
|
|
|
79
|
|
|
// Most EVE players on Discord use their ingame name, so lets support @highlights |
|
80
|
|
|
$messageString = stristr($data['messageString'], '@') ? str_replace('<@', '', str_replace('>', '', $data['messageString'])) : $data['messageString']; |
|
81
|
|
|
if (is_numeric($messageString)) { |
|
82
|
|
|
// The person used @highlighting, so now we got a discord id, lets map that to a name |
|
83
|
|
|
$messageString = dbQueryField('SELECT name FROM usersSeen WHERE id = :id', 'name', [':id' => $messageString]); |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
$cleanString = urlencode($messageString); |
|
87
|
|
|
|
|
88
|
|
|
$url = "https://api.eveonline.com/eve/CharacterID.xml.aspx?names={$cleanString}"; |
|
89
|
|
|
$xml = makeApiRequest($url); |
|
90
|
|
|
$characterID = null; |
|
91
|
|
|
|
|
92
|
|
View Code Duplication |
if (isset($xml->result->rowset->row)) { |
|
|
|
|
|
|
93
|
|
|
foreach ($xml->result->rowset->row as $character) { |
|
94
|
|
|
$characterID = $character->attributes()->characterID; |
|
95
|
|
|
} |
|
96
|
|
|
} |
|
97
|
|
|
if (empty($characterID)) { |
|
98
|
|
|
return $this->message->reply('**Error:** no data available'); |
|
99
|
|
|
} |
|
100
|
|
|
// Get stats |
|
101
|
|
|
$statsURL = 'https://beta.eve-kill.net/api/charInfo/characterID/'.urlencode($characterID).'/'; |
|
102
|
|
|
$stats = json_decode(downloadData($statsURL), true); |
|
103
|
|
|
|
|
104
|
|
|
if (empty($stats)) { |
|
105
|
|
|
return $this->message->reply('**Error:** no data available'); |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
$characterName = @$stats['characterName']; |
|
109
|
|
|
if (empty($characterName)) { |
|
110
|
|
|
return $this->message->reply('**Error:** No Character Found'); |
|
111
|
|
|
} |
|
112
|
|
|
$corporationName = @$stats['corporationName']; |
|
113
|
|
|
$allianceName = isset($stats['allianceName']) ? $stats['allianceName'] : 'None'; |
|
114
|
|
|
$factionName = isset($stats['factionName']) ? $stats['factionName'] : 'None'; |
|
115
|
|
|
$securityStatus = @$stats['securityStatus']; |
|
116
|
|
|
$lastSeenSystem = @$stats['lastSeenSystem']; |
|
117
|
|
|
$lastSeenRegion = @$stats['lastSeenRegion']; |
|
118
|
|
|
$lastSeenShip = @$stats['lastSeenShip']; |
|
119
|
|
|
$lastSeenDate = @$stats['lastSeenDate']; |
|
120
|
|
|
$corporationActiveArea = @$stats['corporationActiveArea']; |
|
121
|
|
|
$allianceActiveArea = @$stats['allianceActiveArea']; |
|
122
|
|
|
$soloKills = @$stats['soloKills']; |
|
123
|
|
|
$blobKills = @$stats['blobKills']; |
|
124
|
|
|
$lifeTimeKills = @$stats['lifeTimeKills']; |
|
125
|
|
|
$lifeTimeLosses = @$stats['lifeTimeLosses']; |
|
126
|
|
|
$amountOfSoloPVPer = @$stats['percentageSoloPVPer']; |
|
127
|
|
|
$ePeenSize = @$stats['ePeenSize']; |
|
128
|
|
|
$facepalms = @$stats['facepalms']; |
|
129
|
|
|
$lastUpdated = @$stats['lastUpdatedOnBackend']; |
|
130
|
|
|
$url = 'https://beta.eve-kill.net/character/'.$stats['characterID'].'/'; |
|
131
|
|
|
|
|
132
|
|
|
|
|
133
|
|
|
$msg = "```characterName: {$characterName} |
|
134
|
|
|
corporationName: {$corporationName} |
|
135
|
|
|
allianceName: {$allianceName} |
|
136
|
|
|
factionName: {$factionName} |
|
137
|
|
|
securityStatus: {$securityStatus} |
|
138
|
|
|
lastSeenSystem: {$lastSeenSystem} |
|
139
|
|
|
lastSeenRegion: {$lastSeenRegion} |
|
140
|
|
|
lastSeenShip: {$lastSeenShip} |
|
141
|
|
|
lastSeenDate: {$lastSeenDate} |
|
142
|
|
|
corporationActiveArea: {$corporationActiveArea} |
|
143
|
|
|
allianceActiveArea: {$allianceActiveArea} |
|
144
|
|
|
soloKills: {$soloKills} |
|
145
|
|
|
blobKills: {$blobKills} |
|
146
|
|
|
lifeTimeKills: {$lifeTimeKills} |
|
147
|
|
|
lifeTimeLosses: {$lifeTimeLosses} |
|
148
|
|
|
percentageSoloPVPer: {$amountOfSoloPVPer} |
|
149
|
|
|
ePeenSize: {$ePeenSize} |
|
150
|
|
|
facepalms: {$facepalms} |
|
151
|
|
|
lastUpdated: $lastUpdated``` |
|
152
|
|
|
For more info, visit: $url"; |
|
153
|
|
|
|
|
154
|
|
|
$this->logger->addInfo("Sending character info to {$user}"); |
|
155
|
|
|
$this->message->reply($msg); |
|
156
|
|
|
} |
|
157
|
|
|
} |
|
158
|
|
|
|
|
159
|
|
|
/** |
|
160
|
|
|
* @return array |
|
161
|
|
|
*/ |
|
162
|
|
View Code Duplication |
public function information() |
|
|
|
|
|
|
163
|
|
|
{ |
|
164
|
|
|
return [ |
|
165
|
|
|
'name' => 'char', |
|
166
|
|
|
'trigger' => [$this->config['bot']['trigger'].'char'], |
|
167
|
|
|
'information' => 'Returns basic EVE Online data about a character from projectRena. To use simply type !char character_name', |
|
168
|
|
|
]; |
|
169
|
|
|
} |
|
170
|
|
|
|
|
171
|
|
|
/** |
|
172
|
|
|
* @param $msgData |
|
173
|
|
|
*/ |
|
174
|
|
|
public function onMessageAdmin($msgData) |
|
|
|
|
|
|
175
|
|
|
{ |
|
176
|
|
|
} |
|
177
|
|
|
} |
|
178
|
|
|
|
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.