|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace CSlant\TelegramGitNotifier; |
|
4
|
|
|
|
|
5
|
|
|
use CSlant\TelegramGitNotifier\Constants\EventConstant; |
|
6
|
|
|
use CSlant\TelegramGitNotifier\Exceptions\ConfigFileException; |
|
7
|
|
|
use CSlant\TelegramGitNotifier\Interfaces\BotInterface; |
|
8
|
|
|
use CSlant\TelegramGitNotifier\Interfaces\EventInterface; |
|
9
|
|
|
use CSlant\TelegramGitNotifier\Interfaces\SettingInterface; |
|
10
|
|
|
use CSlant\TelegramGitNotifier\Interfaces\Structures\AppInterface; |
|
11
|
|
|
use CSlant\TelegramGitNotifier\Models\Event; |
|
12
|
|
|
use CSlant\TelegramGitNotifier\Models\Setting; |
|
13
|
|
|
use CSlant\TelegramGitNotifier\Structures\App; |
|
14
|
|
|
use CSlant\TelegramGitNotifier\Structures\TelegramBot; |
|
15
|
|
|
use CSlant\TelegramGitNotifier\Trait\BotSettingTrait; |
|
16
|
|
|
use CSlant\TelegramGitNotifier\Trait\EventSettingTrait; |
|
17
|
|
|
use CSlant\TelegramGitNotifier\Trait\EventTrait; |
|
18
|
|
|
use Telegram; |
|
19
|
|
|
|
|
20
|
|
|
class Bot implements AppInterface, BotInterface, EventInterface, SettingInterface |
|
21
|
|
|
{ |
|
22
|
|
|
use App; |
|
23
|
|
|
use TelegramBot; |
|
24
|
|
|
|
|
25
|
|
|
use EventTrait; |
|
|
|
|
|
|
26
|
|
|
use BotSettingTrait; |
|
27
|
|
|
use EventSettingTrait; |
|
28
|
|
|
|
|
29
|
|
|
public Event $event; |
|
30
|
|
|
|
|
31
|
|
|
public Setting $setting; |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* @param Telegram|null $telegram |
|
35
|
|
|
* @param string|null $chatBotId |
|
36
|
|
|
* @param Event|null $event |
|
37
|
|
|
* @param string|null $platform |
|
38
|
|
|
* @param string|null $platformFile |
|
39
|
|
|
* @param Setting|null $setting |
|
40
|
|
|
* @param string|null $settingFile |
|
41
|
|
|
* |
|
42
|
|
|
* @throws ConfigFileException |
|
43
|
|
|
*/ |
|
44
|
|
|
public function __construct( |
|
45
|
|
|
Telegram $telegram = null, |
|
46
|
|
|
?string $chatBotId = null, |
|
47
|
|
|
Event $event = null, |
|
48
|
|
|
?string $platform = EventConstant::DEFAULT_PLATFORM, |
|
49
|
|
|
?string $platformFile = null, |
|
50
|
|
|
Setting $setting = null, |
|
51
|
|
|
?string $settingFile = null, |
|
52
|
|
|
) { |
|
53
|
|
|
$this->event = $event ?? new Event(); |
|
54
|
|
|
$this->setPlatFormForEvent($platform, $platformFile); |
|
55
|
|
|
$this->validatePlatformFile(); |
|
56
|
|
|
|
|
57
|
|
|
$this->setting = $setting ?? new Setting(); |
|
58
|
|
|
$this->updateSetting($settingFile); |
|
59
|
|
|
$this->validateSettingFile(); |
|
60
|
|
|
|
|
61
|
|
|
$this->telegram = $telegram ?? new Telegram(config('telegram-git-notifier.bot.token')); |
|
62
|
|
|
$this->setCurrentChatBotId($chatBotId); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
public function validateSettingFile(): void |
|
66
|
|
|
{ |
|
67
|
|
|
if (empty($this->setting->getSettingFile())) { |
|
68
|
|
|
throw ConfigFileException::settingFile($this->setting->getSettingFile()); |
|
69
|
|
|
} |
|
70
|
|
|
} |
|
71
|
|
|
} |
|
72
|
|
|
|