1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Botonomous; |
4
|
|
|
|
5
|
|
|
use Botonomous\listener\AbstractBaseListener; |
6
|
|
|
use Botonomous\utility\FormattingUtility; |
7
|
|
|
use Botonomous\utility\LoggerUtility; |
8
|
|
|
use Botonomous\utility\MessageUtility; |
9
|
|
|
use Botonomous\utility\RequestUtility; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* Class AbstractBot. |
13
|
|
|
*/ |
14
|
|
|
abstract class AbstractBot |
15
|
|
|
{ |
16
|
|
|
/** |
17
|
|
|
* Dependencies. |
18
|
|
|
*/ |
19
|
|
|
protected $config; |
20
|
|
|
protected $listener; |
21
|
|
|
protected $messageUtility; |
22
|
|
|
protected $commandContainer; |
23
|
|
|
protected $formattingUtility; |
24
|
|
|
protected $loggerUtility; |
25
|
|
|
protected $oauth; |
26
|
|
|
protected $blackList; |
27
|
|
|
protected $whiteList; |
28
|
|
|
protected $sender; |
29
|
|
|
protected $dictionary; |
30
|
|
|
protected $commandExtractor; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @param null $key |
34
|
|
|
* |
35
|
|
|
* @return mixed |
36
|
|
|
*/ |
37
|
|
|
abstract public function getRequest($key = null); |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @return Config |
41
|
|
|
*/ |
42
|
43 |
|
public function getConfig(): Config |
43
|
|
|
{ |
44
|
43 |
|
if ($this->config === null) { |
45
|
37 |
|
$this->config = (new Config()); |
46
|
|
|
} |
47
|
|
|
|
48
|
43 |
|
return $this->config; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @param Config $config |
53
|
|
|
*/ |
54
|
11 |
|
public function setConfig(Config $config) |
55
|
|
|
{ |
56
|
11 |
|
$this->config = $config; |
57
|
11 |
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @throws \Exception |
61
|
|
|
* |
62
|
|
|
* @return AbstractBaseListener |
63
|
|
|
*/ |
64
|
33 |
|
public function getListener(): AbstractBaseListener |
65
|
|
|
{ |
66
|
33 |
|
if (!isset($this->listener)) { |
67
|
31 |
|
$listenerClass = __NAMESPACE__.'\\listener\\'.ucwords($this->getConfig()->get('listener')).'Listener'; |
68
|
31 |
|
$this->setListener(new $listenerClass()); |
69
|
|
|
} |
70
|
|
|
|
71
|
33 |
|
return $this->listener; |
72
|
|
|
} |
73
|
|
|
|
74
|
33 |
|
public function setListener(AbstractBaseListener $listener) |
75
|
|
|
{ |
76
|
33 |
|
$this->listener = $listener; |
77
|
33 |
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* @return MessageUtility |
81
|
|
|
*/ |
82
|
4 |
|
public function getMessageUtility(): MessageUtility |
83
|
|
|
{ |
84
|
4 |
|
if (!isset($this->messageUtility)) { |
85
|
4 |
|
$this->setMessageUtility(new MessageUtility()); |
86
|
|
|
} |
87
|
|
|
|
88
|
4 |
|
return $this->messageUtility; |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* @param MessageUtility $messageUtility |
93
|
|
|
*/ |
94
|
4 |
|
public function setMessageUtility(MessageUtility $messageUtility) |
95
|
|
|
{ |
96
|
4 |
|
$this->messageUtility = $messageUtility; |
97
|
4 |
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* @return CommandContainer |
101
|
|
|
*/ |
102
|
1 |
|
public function getCommandContainer(): CommandContainer |
103
|
|
|
{ |
104
|
1 |
|
if (!isset($this->commandContainer)) { |
105
|
1 |
|
$this->setCommandContainer(new CommandContainer()); |
106
|
|
|
} |
107
|
|
|
|
108
|
1 |
|
return $this->commandContainer; |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* @param CommandContainer $commandContainer |
113
|
|
|
*/ |
114
|
1 |
|
public function setCommandContainer(CommandContainer $commandContainer) |
115
|
|
|
{ |
116
|
1 |
|
$this->commandContainer = $commandContainer; |
117
|
1 |
|
} |
118
|
|
|
|
119
|
|
|
/** |
120
|
|
|
* @return FormattingUtility |
121
|
|
|
*/ |
122
|
2 |
|
public function getFormattingUtility(): FormattingUtility |
123
|
|
|
{ |
124
|
2 |
|
if (!isset($this->formattingUtility)) { |
125
|
1 |
|
$this->setFormattingUtility(new FormattingUtility()); |
126
|
|
|
} |
127
|
|
|
|
128
|
2 |
|
return $this->formattingUtility; |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
/** |
132
|
|
|
* @param FormattingUtility $formattingUtility |
133
|
|
|
*/ |
134
|
2 |
|
public function setFormattingUtility(FormattingUtility $formattingUtility) |
135
|
|
|
{ |
136
|
2 |
|
$this->formattingUtility = $formattingUtility; |
137
|
2 |
|
} |
138
|
|
|
|
139
|
|
|
/** |
140
|
|
|
* @return LoggerUtility |
141
|
|
|
*/ |
142
|
1 |
|
public function getLoggerUtility(): LoggerUtility |
143
|
|
|
{ |
144
|
1 |
|
if (!isset($this->loggerUtility)) { |
145
|
1 |
|
$this->setLoggerUtility(new LoggerUtility()); |
146
|
|
|
} |
147
|
|
|
|
148
|
1 |
|
return $this->loggerUtility; |
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
/** |
152
|
|
|
* @param LoggerUtility $loggerUtility |
153
|
|
|
*/ |
154
|
1 |
|
public function setLoggerUtility(LoggerUtility $loggerUtility) |
155
|
|
|
{ |
156
|
1 |
|
$this->loggerUtility = $loggerUtility; |
157
|
1 |
|
} |
158
|
|
|
|
159
|
|
|
/** |
160
|
|
|
* @return OAuth |
161
|
|
|
*/ |
162
|
2 |
|
public function getOauth(): OAuth |
163
|
|
|
{ |
164
|
2 |
|
if (!isset($this->oauth)) { |
165
|
1 |
|
$this->setOauth(new OAuth()); |
166
|
|
|
} |
167
|
|
|
|
168
|
2 |
|
return $this->oauth; |
169
|
|
|
} |
170
|
|
|
|
171
|
|
|
/** |
172
|
|
|
* @param OAuth $oauth |
173
|
|
|
*/ |
174
|
2 |
|
public function setOauth(OAuth $oauth) |
175
|
|
|
{ |
176
|
2 |
|
$this->oauth = $oauth; |
177
|
2 |
|
} |
178
|
|
|
|
179
|
|
|
/** |
180
|
|
|
* @throws \Exception |
181
|
|
|
* |
182
|
|
|
* @return RequestUtility |
183
|
|
|
*/ |
184
|
2 |
|
public function getRequestUtility(): RequestUtility |
185
|
|
|
{ |
186
|
2 |
|
return $this->getListener()->getRequestUtility(); |
187
|
|
|
} |
188
|
|
|
|
189
|
|
|
/** |
190
|
|
|
* @param RequestUtility $requestUtility |
191
|
|
|
* |
192
|
|
|
* @throws \Exception |
193
|
|
|
*/ |
194
|
3 |
|
public function setRequestUtility(RequestUtility $requestUtility) |
195
|
|
|
{ |
196
|
3 |
|
$this->getListener()->setRequestUtility($requestUtility); |
197
|
3 |
|
} |
198
|
|
|
|
199
|
|
|
/** |
200
|
|
|
* @throws \Exception |
201
|
|
|
* |
202
|
|
|
* @return BlackList |
203
|
|
|
*/ |
204
|
2 |
|
public function getBlackList(): BlackList |
205
|
|
|
{ |
206
|
2 |
|
if (!isset($this->blackList)) { |
207
|
1 |
|
$this->setBlackList(new BlackList($this->getListener()->getRequest())); |
208
|
|
|
} |
209
|
|
|
|
210
|
2 |
|
return $this->blackList; |
211
|
|
|
} |
212
|
|
|
|
213
|
|
|
/** |
214
|
|
|
* @param BlackList $blackList |
215
|
|
|
*/ |
216
|
2 |
|
public function setBlackList(BlackList $blackList) |
217
|
|
|
{ |
218
|
2 |
|
$this->blackList = $blackList; |
219
|
2 |
|
} |
220
|
|
|
|
221
|
|
|
/** |
222
|
|
|
* @throws \Exception |
223
|
|
|
* |
224
|
|
|
* @return WhiteList |
225
|
|
|
*/ |
226
|
1 |
|
public function getWhiteList(): WhiteList |
227
|
|
|
{ |
228
|
1 |
|
if (!isset($this->whiteList)) { |
229
|
1 |
|
$this->setWhiteList(new WhiteList($this->getListener()->getRequest())); |
230
|
|
|
} |
231
|
|
|
|
232
|
1 |
|
return $this->whiteList; |
233
|
|
|
} |
234
|
|
|
|
235
|
|
|
/** |
236
|
|
|
* @param WhiteList $whiteList |
237
|
|
|
*/ |
238
|
1 |
|
public function setWhiteList(WhiteList $whiteList) |
239
|
|
|
{ |
240
|
1 |
|
$this->whiteList = $whiteList; |
241
|
1 |
|
} |
242
|
|
|
|
243
|
|
|
/** |
244
|
|
|
* @return Sender |
245
|
|
|
*/ |
246
|
4 |
|
public function getSender(): Sender |
247
|
|
|
{ |
248
|
4 |
|
if (!isset($this->sender)) { |
249
|
4 |
|
$this->setSender(new Sender($this)); |
250
|
|
|
} |
251
|
|
|
|
252
|
4 |
|
return $this->sender; |
253
|
|
|
} |
254
|
|
|
|
255
|
|
|
/** |
256
|
|
|
* @param Sender $sender |
257
|
|
|
*/ |
258
|
4 |
|
public function setSender(Sender $sender) |
259
|
|
|
{ |
260
|
4 |
|
$this->sender = $sender; |
261
|
4 |
|
} |
262
|
|
|
|
263
|
|
|
/** |
264
|
|
|
* @return Dictionary |
265
|
|
|
*/ |
266
|
3 |
|
public function getDictionary(): Dictionary |
267
|
|
|
{ |
268
|
3 |
|
if (!isset($this->dictionary)) { |
269
|
3 |
|
$this->setDictionary(new Dictionary()); |
270
|
|
|
} |
271
|
|
|
|
272
|
3 |
|
return $this->dictionary; |
273
|
|
|
} |
274
|
|
|
|
275
|
|
|
/** |
276
|
|
|
* @param Dictionary $dictionary |
277
|
|
|
*/ |
278
|
3 |
|
public function setDictionary(Dictionary $dictionary) |
279
|
|
|
{ |
280
|
3 |
|
$this->dictionary = $dictionary; |
281
|
3 |
|
} |
282
|
|
|
|
283
|
|
|
/** |
284
|
|
|
* @return CommandExtractor |
285
|
|
|
*/ |
286
|
4 |
|
public function getCommandExtractor(): CommandExtractor |
287
|
|
|
{ |
288
|
4 |
|
if (!isset($this->commandExtractor)) { |
289
|
4 |
|
$this->setCommandExtractor(new CommandExtractor()); |
290
|
|
|
} |
291
|
|
|
|
292
|
4 |
|
return $this->commandExtractor; |
293
|
|
|
} |
294
|
|
|
|
295
|
|
|
/** |
296
|
|
|
* @param CommandExtractor $commandExtractor |
297
|
|
|
*/ |
298
|
4 |
|
public function setCommandExtractor(CommandExtractor $commandExtractor) |
299
|
|
|
{ |
300
|
4 |
|
$this->commandExtractor = $commandExtractor; |
301
|
4 |
|
} |
302
|
|
|
} |
303
|
|
|
|