| 1 | <?php |
||
| 2 | |||
| 3 | namespace CSlant\TelegramGitNotifier\Trait; |
||
| 4 | |||
| 5 | use CSlant\TelegramGitNotifier\Constants\SettingConstant; |
||
| 6 | |||
| 7 | trait BotSettingTrait |
||
| 8 | { |
||
| 9 | public function updateSetting(?string $settingFile = null): void |
||
| 10 | { |
||
| 11 | if ($this->setting->getSettingFile()) { |
||
| 12 | return; |
||
| 13 | } |
||
| 14 | $settingFile = $settingFile ?? config('telegram-git-notifier.data_file.setting'); |
||
| 15 | $this->setting->setSettingFile($settingFile); |
||
| 16 | $this->setting->setSettingConfig(); |
||
| 17 | } |
||
| 18 | |||
| 19 | public function setMyCommands( |
||
| 20 | array $menuCommand, |
||
| 21 | ?string $view = null |
||
| 22 | ): void { |
||
| 23 | $this->telegram->setMyCommands([ |
||
| 24 | 'commands' => json_encode($menuCommand), |
||
| 25 | ]); |
||
| 26 | $this->sendMessage( |
||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 27 | tgn_view( |
||
| 28 | $view ?? |
||
| 29 | config('telegram-git-notifier.view.tools.set_menu_cmd') |
||
| 30 | ) |
||
| 31 | ); |
||
| 32 | } |
||
| 33 | |||
| 34 | public function settingHandle(?string $view = null): void |
||
| 35 | { |
||
| 36 | $this->sendMessage( |
||
| 37 | tgn_view($view ?? config('telegram-git-notifier.view.tools.settings')), |
||
| 38 | ['reply_markup' => $this->settingMarkup()] |
||
| 39 | ); |
||
| 40 | } |
||
| 41 | |||
| 42 | public function settingMarkup(): array |
||
| 43 | { |
||
| 44 | $markup = [ |
||
| 45 | [ |
||
| 46 | $this->telegram->buildInlineKeyBoardButton( |
||
| 47 | $this->setting->getSettings()[SettingConstant::T_IS_NOTIFIED] |
||
| 48 | ? '✅ Allow notifications' |
||
| 49 | : 'Allow notifications', |
||
| 50 | '', |
||
| 51 | SettingConstant::SETTING_IS_NOTIFIED |
||
| 52 | ), |
||
| 53 | ], |
||
| 54 | [ |
||
| 55 | $this->telegram->buildInlineKeyBoardButton( |
||
| 56 | $this->setting->getSettings()[SettingConstant::T_ALL_EVENTS_NOTIFICATION] |
||
| 57 | ? '✅ Enable All Events Notify' |
||
| 58 | : 'Enable All Events Notify', |
||
| 59 | '', |
||
| 60 | SettingConstant::SETTING_ALL_EVENTS_NOTIFY |
||
| 61 | ), |
||
| 62 | ], |
||
| 63 | ]; |
||
| 64 | |||
| 65 | $markup = $this->customEventMarkup($markup); |
||
| 66 | |||
| 67 | $markup[] = [ |
||
| 68 | $this->telegram->buildInlineKeyBoardButton( |
||
| 69 | '🔙 Back to menu', |
||
| 70 | '', |
||
| 71 | SettingConstant::SETTING_BACK . 'menu' |
||
| 72 | ), |
||
| 73 | ]; |
||
| 74 | |||
| 75 | return $markup; |
||
| 76 | } |
||
| 77 | |||
| 78 | public function customEventMarkup(array $markup): array |
||
| 79 | { |
||
| 80 | if (!$this->setting->getSettings()[SettingConstant::T_ALL_EVENTS_NOTIFICATION]) { |
||
| 81 | $markup[] = [ |
||
| 82 | $this->telegram->buildInlineKeyBoardButton( |
||
| 83 | '🦑 Custom github events', |
||
| 84 | '', |
||
| 85 | SettingConstant::SETTING_GITHUB_EVENTS |
||
| 86 | ), |
||
| 87 | $this->telegram->buildInlineKeyBoardButton( |
||
| 88 | '🦊 Custom gitlab events', |
||
| 89 | '', |
||
| 90 | SettingConstant::SETTING_GITLAB_EVENTS |
||
| 91 | ), |
||
| 92 | ]; |
||
| 93 | } |
||
| 94 | |||
| 95 | return $markup; |
||
| 96 | } |
||
| 97 | } |
||
| 98 |