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
|
|
|
/** |
27
|
|
|
* @property message |
28
|
|
|
*/ |
29
|
|
|
class corpInfo |
|
|
|
|
30
|
|
|
{ |
31
|
|
|
public $config; |
32
|
|
|
public $discord; |
33
|
|
|
public $logger; |
34
|
|
|
private $excludeChannel; |
35
|
|
|
private $message; |
36
|
|
|
private $triggers; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @param $config |
40
|
|
|
* @param $discord |
41
|
|
|
* @param $logger |
42
|
|
|
*/ |
43
|
|
View Code Duplication |
public function init($config, $discord, $logger) |
|
|
|
|
44
|
|
|
{ |
45
|
|
|
$this->config = $config; |
46
|
|
|
$this->discord = $discord; |
47
|
|
|
$this->logger = $logger; |
48
|
|
|
$this->excludeChannel = $this->config['bot']['restrictedChannels']; |
49
|
|
|
$this->triggers[] = $this->config['bot']['trigger'] . 'corp'; |
50
|
|
|
$this->triggers[] = $this->config['bot']['trigger'] . 'Corp'; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @param $msgData |
55
|
|
|
* @param $message |
56
|
|
|
* @return null |
57
|
|
|
*/ |
58
|
|
|
public function onMessage($msgData, $message) |
59
|
|
|
{ |
60
|
|
|
$channelID = (int) $msgData['message']['channelID']; |
61
|
|
|
|
62
|
|
|
if (in_array($channelID, $this->excludeChannel, true)) |
63
|
|
|
{ |
64
|
|
|
return null; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
$this->message = $message; |
68
|
|
|
|
69
|
|
|
$message = $msgData['message']['message']; |
70
|
|
|
$user = $msgData['message']['from']; |
71
|
|
|
|
72
|
|
|
$data = command($message, $this->information()['trigger'], $this->config['bot']['trigger']); |
73
|
|
|
if (isset($data['trigger'])) { |
74
|
|
|
$messageString = $data['messageString']; |
75
|
|
|
$cleanString = urlencode($messageString); |
76
|
|
|
$corpID = corpID($cleanString); |
77
|
|
|
|
78
|
|
|
if (empty($corpID)) { |
79
|
|
|
return $this->message->reply('**Error:** Unable to find any group matching that name.'); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
$corporation = corpDetails($corpID); |
83
|
|
|
if (null === $corporation) { |
84
|
|
|
return $this->message->reply('**Error:** ESI is down. Try again later.'); |
85
|
|
|
} |
86
|
|
|
$corporationName = $corporation['corporation_name']; |
87
|
|
|
$allianceID = $corporation['alliance_id']; |
88
|
|
|
$allianceName = allianceName($allianceID); |
89
|
|
|
$ceoID = $corporation['ceo_id']; |
90
|
|
|
$ceoName = characterName($ceoID); |
91
|
|
|
$memberCount = $corporation['member_count']; |
92
|
|
|
$corpTicker = $corporation['ticker']; |
93
|
|
|
$url = "https://zkillboard.com/corporation/{$corpID}/"; |
94
|
|
|
|
95
|
|
|
if ($corporationName === null || $corporationName === '') { |
96
|
|
|
return $this->message->reply('**Error:** No corporation found.'); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
|
100
|
|
|
$msg = "```Corp Name: {$corporationName} |
101
|
|
|
Corp Ticker: {$corpTicker} |
102
|
|
|
CEO: {$ceoName} |
103
|
|
|
Alliance Name: {$allianceName} |
104
|
|
|
Member Count: {$memberCount} |
105
|
|
|
``` |
106
|
|
|
For more info, visit: $url"; |
107
|
|
|
|
108
|
|
|
$this->logger->addInfo("corpInfo: Sending corp info to {$user}"); |
109
|
|
|
$this->message->reply($msg); |
110
|
|
|
} |
111
|
|
|
return null; |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* @return array |
116
|
|
|
*/ |
117
|
|
|
public function information() |
118
|
|
|
{ |
119
|
|
|
return array( |
120
|
|
|
'name' => 'corp', |
121
|
|
|
'trigger' => $this->triggers, |
122
|
|
|
'information' => 'Returns basic EVE Online data about a corporation from CREST and ESI. To use simply type !corp corporation_name' |
123
|
|
|
); |
124
|
|
|
} |
125
|
|
|
} |
126
|
|
|
|
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.