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
|
|
|
* Class price |
28
|
|
|
*/ |
29
|
|
|
class price |
|
|
|
|
30
|
|
|
{ |
31
|
|
|
/** |
32
|
|
|
* @var array |
33
|
|
|
*/ |
34
|
|
|
public $triggers = array(); |
35
|
|
|
private $excludeChannel; |
36
|
|
|
private $message; |
37
|
|
|
private $config; |
38
|
|
|
private $discord; |
39
|
|
|
private $logger; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @param $config |
43
|
|
|
* @param $discord |
44
|
|
|
* @param $logger |
45
|
|
|
*/ |
46
|
|
|
public function init($config, $discord, $logger) |
47
|
|
|
{ |
48
|
|
|
$this->config = $config; |
49
|
|
|
$this->discord = $discord; |
50
|
|
|
$this->logger = $logger; |
51
|
|
|
$this->triggers[] = $this->config['bot']['trigger'] . 'pc'; |
52
|
|
|
$this->triggers[] = $this->config['bot']['trigger'] . strtolower('Jita'); |
53
|
|
|
$this->triggers[] = $this->config['bot']['trigger'] . strtolower('Amarr'); |
54
|
|
|
$this->triggers[] = $this->config['bot']['trigger'] . strtolower('Rens'); |
55
|
|
|
$this->triggers[] = $this->config['bot']['trigger'] . strtolower('Dodixie'); |
56
|
|
|
$this->triggers[] = $this->config['bot']['trigger'] . 'Pc'; |
57
|
|
|
$this->triggers[] = $this->config['bot']['trigger'] . 'Jita'; |
58
|
|
|
$this->triggers[] = $this->config['bot']['trigger'] . 'Amarr'; |
59
|
|
|
$this->triggers[] = $this->config['bot']['trigger'] . 'Rens'; |
60
|
|
|
$this->triggers[] = $this->config['bot']['trigger'] . 'Dodixie'; |
61
|
|
|
$this->excludeChannel = $this->config['bot']['restrictedChannels']; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* @param $msgData |
66
|
|
|
* @param $message |
67
|
|
|
* @return null |
68
|
|
|
*/ |
69
|
|
|
public function onMessage($msgData, $message) |
70
|
|
|
{ |
71
|
|
|
$this->message = $message; |
72
|
|
|
$user = $msgData['message']['from']; |
73
|
|
|
$channelID = (int) $msgData['message']['channelID']; |
74
|
|
|
|
75
|
|
|
if (in_array($channelID, $this->excludeChannel, true)) |
76
|
|
|
{ |
77
|
|
|
return null; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
|
81
|
|
|
// Bind a few things to vars for the plugins |
82
|
|
|
$message = $msgData['message']['message']; |
83
|
|
|
|
84
|
|
|
$data = command(strtolower($message), $this->information()['trigger'], $this->config['bot']['trigger']); |
85
|
|
|
|
86
|
|
|
if (isset($data['trigger'])) { |
87
|
|
|
|
88
|
|
|
$systemName = $data['trigger']; |
89
|
|
|
$itemName = $data['messageString']; |
90
|
|
|
$single = getTypeID($itemName); |
91
|
|
|
|
92
|
|
|
// Check if the channel is restricted |
93
|
|
|
if (in_array($channelID, $this->excludeChannel, true)) { |
94
|
|
|
return $this->message->reply('**Price Check not allowed in this channel**'); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
// If there is a single result, we'll get data now! |
98
|
|
|
if ($single) { |
99
|
|
|
$typeID = $single; |
100
|
|
|
|
101
|
|
|
if ($systemName === 'pc') { |
102
|
|
|
$solarSystemID = 'global'; |
103
|
|
|
} else { |
104
|
|
|
$solarSystemID = getSystemID($systemName); |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
// Get pricing data |
108
|
|
|
if ($solarSystemID === 'global') { |
109
|
|
|
$data = new SimpleXMLElement(downloadData("https://api.eve-central.com/api/marketstat?typeid={$typeID}")); |
110
|
|
|
} else { |
111
|
|
|
$data = new SimpleXMLElement(downloadData("https://api.eve-central.com/api/marketstat?usesystem={$solarSystemID}&typeid={$typeID}")); |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
$lowBuy = str_pad(number_format((float) $data->marketstat->type->buy->min, 2),18," ",STR_PAD_LEFT); |
115
|
|
|
$avgBuy = str_pad(number_format((float) $data->marketstat->type->buy->avg, 2),18," ",STR_PAD_LEFT); |
116
|
|
|
$highBuy = str_pad(number_format((float) $data->marketstat->type->buy->max, 2),18," ",STR_PAD_LEFT); |
117
|
|
|
$lowSell = str_pad(number_format((float) $data->marketstat->type->sell->min, 2),18," ",STR_PAD_LEFT); |
118
|
|
|
$avgSell = str_pad(number_format((float) $data->marketstat->type->sell->avg, 2),18," ",STR_PAD_LEFT); |
119
|
|
|
$highSell = str_pad(number_format((float) $data->marketstat->type->sell->max, 2),18," ",STR_PAD_LEFT); |
120
|
|
|
|
121
|
|
|
$this->logger->addInfo("Price: Sending pricing info to {$user}"); |
122
|
|
|
$solarSystemName = $systemName === 'pc' ? 'Global' : ucfirst($systemName); |
123
|
|
|
$messageData = " |
124
|
|
|
``` System: {$solarSystemName} |
125
|
|
|
Item: {$itemName}``` |
126
|
|
|
**Buy:** |
127
|
|
|
``` Low: {$lowBuy} |
128
|
|
|
Avg: {$avgBuy} |
129
|
|
|
High: {$highBuy}``` |
130
|
|
|
**Sell:** |
131
|
|
|
``` Low: {$lowSell} |
132
|
|
|
Avg: {$avgSell} |
133
|
|
|
High: {$highSell}```"; |
134
|
|
|
$this->message->reply($messageData); |
135
|
|
|
} else { |
136
|
|
|
$this->message->reply("**Error:** ***{$itemName}*** not found"); |
137
|
|
|
} |
138
|
|
|
} |
139
|
|
|
return null; |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
/** |
143
|
|
|
* @return array |
144
|
|
|
*/ |
145
|
|
|
public function information() |
146
|
|
|
{ |
147
|
|
|
return array( |
148
|
|
|
'name' => 'pc', |
149
|
|
|
'trigger' => $this->triggers, |
150
|
|
|
'information' => 'Shows price information for items in EVE. To use simply type **!pc item_name** for global stats or **!jita/amarr/rens_or_dodixie item_name** for hub specific info.' |
151
|
|
|
); |
152
|
|
|
} |
153
|
|
|
} |
154
|
|
|
|
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.