|
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
|
|
|
use discord\discord; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* Class ops |
|
33
|
|
|
* @property userID |
|
34
|
|
|
* @property apiKey |
|
35
|
|
|
* @property groupID |
|
36
|
|
|
* @property excludeChannel |
|
37
|
|
|
*/ |
|
38
|
|
|
class fleetUpOps |
|
|
|
|
|
|
39
|
|
|
{ |
|
40
|
|
|
public $config; |
|
41
|
|
|
public $discord; |
|
42
|
|
|
public $logger; |
|
43
|
|
|
protected $keyID; |
|
44
|
|
|
protected $vCode; |
|
45
|
|
|
protected $prefix; |
|
46
|
|
|
private $userID; |
|
47
|
|
|
private $groupID; |
|
48
|
|
|
private $apiKey; |
|
49
|
|
|
private $guild; |
|
50
|
|
|
private $excludeChannel; |
|
51
|
|
|
private $message; |
|
52
|
|
|
private $triggers; |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* @param $config |
|
56
|
|
|
* @param $discord |
|
57
|
|
|
* @param $logger |
|
58
|
|
|
*/ |
|
59
|
|
|
public function init($config, $discord, $logger) |
|
60
|
|
|
{ |
|
61
|
|
|
$this->config = $config; |
|
62
|
|
|
$this->discord = $discord; |
|
63
|
|
|
$this->logger = $logger; |
|
64
|
|
|
$this->userID = $config['plugins']['fleetUp']['userID']; |
|
65
|
|
|
$this->groupID = $config['plugins']['fleetUp']['groupID']; |
|
66
|
|
|
$this->apiKey = $config['plugins']['fleetUp']['apiKey']; |
|
67
|
|
|
$this->guild = $config['bot']['guild']; |
|
68
|
|
|
$this->excludeChannel = $this->config['bot']['restrictedChannels']; |
|
69
|
|
|
$this->triggers[] = $this->config['bot']['trigger'] . 'ops'; |
|
70
|
|
|
$this->triggers[] = $this->config['bot']['trigger'] . 'Ops'; |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
/** |
|
74
|
|
|
* @param $msgData |
|
75
|
|
|
* @param $message |
|
76
|
|
|
* @return null |
|
77
|
|
|
*/ |
|
78
|
|
|
public function onMessage($msgData, $message) |
|
79
|
|
|
{ |
|
80
|
|
|
$channelID = (int) $msgData['message']['channelID']; |
|
81
|
|
|
|
|
82
|
|
|
if (in_array($channelID, $this->excludeChannel, true)) |
|
83
|
|
|
{ |
|
84
|
|
|
return null; |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
$this->message = $message; |
|
88
|
|
|
$user = $msgData['message']['from']; |
|
89
|
|
|
$channelID = $msgData['message']['channelID']; |
|
90
|
|
|
$message = $msgData['message']['message']; |
|
91
|
|
|
date_default_timezone_set('UTC'); |
|
92
|
|
|
|
|
93
|
|
|
$data = command($message, $this->information()['trigger'], $this->config['bot']['trigger']); |
|
94
|
|
|
if (isset($data['trigger'])) { |
|
95
|
|
|
|
|
96
|
|
|
// Check if the channel is restricted |
|
97
|
|
|
if ($channelID === $this->excludeChannel) { |
|
98
|
|
|
return $this->message->reply('**Upcoming Ops not allowed in this channel**'); |
|
99
|
|
|
} |
|
100
|
|
|
//fleetUp post upcoming operations |
|
101
|
|
|
$ops = json_decode(downloadData("http://api.fleet-up.com/Api.svc/tlYgBRjmuXj2Yl1lEOyMhlDId/{$this->userID}/{$this->apiKey}/Operations/{$this->groupID}"), true); |
|
102
|
|
|
if ($ops['Data'] === null) { |
|
103
|
|
|
$this->message->reply('No upcoming operations detected.'); |
|
104
|
|
|
return null; |
|
105
|
|
|
} |
|
106
|
|
|
$this->logger->addInfo("Sending ops info to {$user}"); |
|
107
|
|
|
foreach ($ops['Data'] as $operation) { |
|
108
|
|
|
$name = $operation['Subject']; |
|
109
|
|
|
$startTime = $operation['StartString']; |
|
110
|
|
|
$desto = $operation['Location']; |
|
111
|
|
|
$formUp = $operation['LocationInfo']; |
|
112
|
|
|
$info = $operation['Details']; |
|
113
|
|
|
$id = $operation['Id']; |
|
114
|
|
|
$link = "https://fleet-up.com/Operation#{$id}\ |
|
115
|
|
|
"; |
|
116
|
|
|
$this->message->reply(" |
|
117
|
|
|
**Upcoming Operation**. |
|
118
|
|
|
Title - {$name}. |
|
119
|
|
|
Form Up Time - {$startTime}. EVE time |
|
120
|
|
|
Form Up System - {$formUp}. |
|
121
|
|
|
Target System - {$desto}. |
|
122
|
|
|
Details - {$info}. |
|
123
|
|
|
Link - {$link}"); |
|
124
|
|
|
} |
|
125
|
|
|
return null; |
|
126
|
|
|
} |
|
127
|
|
|
return null; |
|
128
|
|
|
} |
|
129
|
|
|
|
|
130
|
|
|
/** |
|
131
|
|
|
* @return array |
|
132
|
|
|
*/ |
|
133
|
|
|
public function information() |
|
134
|
|
|
{ |
|
135
|
|
|
return array( |
|
136
|
|
|
'name' => 'ops', |
|
137
|
|
|
'trigger' => $this->triggers, |
|
138
|
|
|
'information' => 'This shows the upcoming operations. To use simply type <!ops>' |
|
139
|
|
|
); |
|
140
|
|
|
} |
|
141
|
|
|
} |
|
142
|
|
|
|
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.