Passed
Pull Request — master (#117)
by Bob
02:42
created

fleetUpOps::tick()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
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
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
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
53
    /**
54
     * @param $config
55
     * @param $discord
56
     * @param $logger
57
     */
58 View Code Duplication
    public function init($config, $discord, $logger)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
59
    {
60
        $this->config = $config;
61
        $this->discord = $discord;
62
        $this->logger = $logger;
63
        $this->userID = $config['plugins']['fleetUpOps']['userID'];
64
        $this->groupID = $config['plugins']['fleetUpOps']['groupID'];
65
        $this->apiKey = $config['plugins']['fleetUpOps']['apiKey'];
66
        $this->guild = $config['bot']['guild'];
67
        $this->excludeChannel = $this->config['bot']['restrictedChannels'];
68
    }
69
70
    /**
71
     * @param $msgData
72
     * @param $message
73
     * @return null
74
     */
75
    public function onMessage($msgData, $message)
76
    {
77
        $channelID = (int) $msgData['message']['channelID'];
78
79
        if (in_array($channelID, $this->excludeChannel, true))
80
        {
81
            return null;
82
        }
83
84
        $this->message = $message;
85
        $user = $msgData['message']['from'];
86
        $channelID = $msgData['message']['channelID'];
87
        $message = $msgData['message']['message'];
88
        date_default_timezone_set('UTC');
89
90
        $data = command($message, $this->information()['trigger'], $this->config['bot']['trigger']);
91
        if (isset($data['trigger'])) {
92
93
            // Check if the channel is restricted
94
            if ($channelID == $this->excludeChannel) {
95
                return $this->message->reply('**Upcoming Ops not allowed in this channel**');
96
            }
97
            //fleetUp post upcoming operations
98
            $ops = json_decode(downloadData("http://api.fleet-up.com/Api.svc/tlYgBRjmuXj2Yl1lEOyMhlDId/{$this->userID}/{$this->apiKey}/Operations/{$this->groupID}"), true);
99
            foreach ($ops['Data'] as $operation) {
100
                $name = $operation['Subject'];
101
                $startTime = $operation['StartString'];
102
                preg_match_all('!\d+!', $operation['Start'], $epochStart);
103
                $desto = $operation['Location'];
104
                $formUp = $operation['LocationInfo'];
105
                $info = $operation['Details'];
106
                $id = $operation['Id'];
107
                $link = "https://fleet-up.com/Operation#{$id}\
108
	    ";
109
                $this->logger->addInfo("Sending ops info to {$user}");
110
                $this->message->reply("
111
**Upcoming Operation**.
112
Title - {$name}.
113
Form Up Time - {$startTime}. EVE time
114
Form Up System - {$formUp}.
115
Target System - {$desto}.
116
Details - {$info}.
117
Link - {$link}");
118
            }
119
        }
120
        return null;
121
    }
122
123
    /**
124
     * @return array
125
     */
126 View Code Duplication
    public function information()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
127
    {
128
        return array(
129
            'name' => 'ops',
130
            'trigger' => array($this->config['bot']['trigger'] . 'ops'),
131
            'information' => 'This shows the upcoming operations. To use simply type <!ops>'
132
        );
133
    }
134
}
135