|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* T3Bot. |
|
4
|
|
|
* |
|
5
|
|
|
* @author Frank Nägler <[email protected]> |
|
6
|
|
|
* |
|
7
|
|
|
* @link http://www.t3bot.de |
|
8
|
|
|
* @link http://wiki.typo3.org/T3Bot |
|
9
|
|
|
*/ |
|
10
|
|
|
namespace T3Bot\Commands; |
|
11
|
|
|
|
|
12
|
|
|
use Slack\Payload; |
|
13
|
|
|
use Slack\RealTimeClient; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* Class UtilCommand. |
|
17
|
|
|
* |
|
18
|
|
|
* @property string commandName |
|
19
|
|
|
* @property array helpCommands |
|
20
|
|
|
*/ |
|
21
|
|
|
class UtilCommand extends AbstractCommand |
|
22
|
|
|
{ |
|
23
|
|
|
/** |
|
24
|
|
|
* AbstractCommand constructor. |
|
25
|
|
|
* |
|
26
|
|
|
* @param Payload $payload |
|
27
|
|
|
* @param RealTimeClient $client |
|
28
|
|
|
* @param array|null $configuration |
|
29
|
|
|
*/ |
|
30
|
6 |
View Code Duplication |
public function __construct(Payload $payload, RealTimeClient $client, array $configuration = null) |
|
31
|
|
|
{ |
|
32
|
6 |
|
$this->commandName = 'util'; |
|
33
|
6 |
|
$this->helpCommands = [ |
|
34
|
|
|
'help' => 'shows this help', |
|
35
|
|
|
'coin [options]' => 'coin toss with [options] (separate by comma)', |
|
36
|
|
|
]; |
|
37
|
6 |
|
parent::__construct($payload, $client, $configuration); |
|
38
|
6 |
|
} |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* @return string |
|
42
|
|
|
*/ |
|
43
|
5 |
|
protected function processCoin() : string |
|
44
|
|
|
{ |
|
45
|
5 |
|
$params = $this->params; |
|
46
|
5 |
|
array_shift($params); |
|
47
|
5 |
|
$params = implode(' ', $params); |
|
48
|
5 |
|
$options = array_map('trim', explode(',', $params)); |
|
49
|
5 |
|
if (count($options) === 1) { |
|
50
|
2 |
|
return '*Botty says:* _A complicated decision ..._'; |
|
51
|
|
|
} |
|
52
|
3 |
|
if (count(array_count_values($options)) === 1) { |
|
53
|
1 |
|
return '*Botty says:* _it is undecidable ..._'; |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
2 |
|
$option = $options[random_int(0, count($options) - 1)]; |
|
57
|
|
|
|
|
58
|
2 |
|
return '*Botty says:* _' . $option . '_'; |
|
59
|
|
|
} |
|
60
|
|
|
} |
|
61
|
|
|
|