|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace TgBotApi\BotApiBase\Method; |
|
6
|
|
|
|
|
7
|
|
|
use TgBotApi\BotApiBase\Exception\BadArgumentException; |
|
8
|
|
|
use TgBotApi\BotApiBase\Method\Interfaces\SendMethodAliasInterface; |
|
9
|
|
|
use TgBotApi\BotApiBase\Method\Traits\FillFromArrayTrait; |
|
10
|
|
|
use TgBotApi\BotApiBase\Method\Traits\SendToChatVariablesTrait; |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* Class SendDiceMethod. |
|
14
|
|
|
* |
|
15
|
|
|
* Use this method to send a dice, which will have a random value from 1 to 6. |
|
16
|
|
|
* On success, the sent Message is returned. |
|
17
|
|
|
* (Yes, we're aware of the βproperβ singular of die. |
|
18
|
|
|
* But it's awkward, and we decided to help it change. |
|
19
|
|
|
* One dice at a time!) |
|
20
|
|
|
* |
|
21
|
|
|
* @see https://core.telegram.org/bots/api#senddice |
|
22
|
|
|
*/ |
|
23
|
|
|
class SendDiceMethod implements SendMethodAliasInterface |
|
24
|
|
|
{ |
|
25
|
|
|
use SendToChatVariablesTrait; |
|
26
|
|
|
use FillFromArrayTrait; |
|
27
|
|
|
|
|
28
|
|
|
public const EMOJI_DICE = 'π²'; |
|
29
|
|
|
public const EMOJI_DARTS = 'π―'; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* Emoji on which the dice throw animation is based. Currently, must be one of βπ²β or βπ―β. Defauts to βπ²β. |
|
33
|
|
|
* |
|
34
|
|
|
* @var string|null |
|
35
|
|
|
*/ |
|
36
|
|
|
public $emoji; |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* @param int|string $chatId |
|
40
|
|
|
* |
|
41
|
|
|
* @throws BadArgumentException |
|
42
|
|
|
*/ |
|
43
|
|
|
public static function create($chatId, array $data = null): SendDiceMethod |
|
44
|
|
|
{ |
|
45
|
|
|
$instance = new static(); |
|
46
|
|
|
$instance->chatId = $chatId; |
|
47
|
|
|
|
|
48
|
|
|
if ($data) { |
|
49
|
|
|
$instance->fill($data); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
return $instance; |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* @param $chatId |
|
57
|
|
|
* |
|
58
|
|
|
* @throws BadArgumentException |
|
59
|
|
|
*/ |
|
60
|
|
|
public static function createWithDice($chatId, array $data = null): SendDiceMethod |
|
61
|
|
|
{ |
|
62
|
|
|
$instance = static::create($chatId, $data); |
|
63
|
|
|
$instance->emoji = static::EMOJI_DICE; |
|
64
|
|
|
|
|
65
|
|
|
return $instance; |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* @param $chatId |
|
70
|
|
|
* |
|
71
|
|
|
* @throws BadArgumentException |
|
72
|
|
|
*/ |
|
73
|
|
|
public static function createWithDarts($chatId, array $data = null): SendDiceMethod |
|
74
|
|
|
{ |
|
75
|
|
|
$instance = static::create($chatId, $data); |
|
76
|
|
|
$instance->emoji = self::EMOJI_DARTS; |
|
77
|
|
|
|
|
78
|
|
|
return $instance; |
|
79
|
|
|
} |
|
80
|
|
|
} |
|
81
|
|
|
|