Skip to content

Commit

Permalink
fix: optimize code
Browse files Browse the repository at this point in the history
  • Loading branch information
tanhongit committed Oct 20, 2023
1 parent 307c85e commit b1b419b
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 35 deletions.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "lbiltech/telegram-git-notifier-app",
"description": "Send notification from Gitlab and Github events to Telegram",
"description": "The PHP app to send notification from Gitlab and Github events to Telegram",
"keywords": [
"lbiltech",
"telegram-bot",
Expand All @@ -22,7 +22,7 @@
"require": {
"php": "^8.0",
"ext-json": "*",
"lbiltech/telegram-git-notifier": "dev-main"
"lbiltech/telegram-git-notifier": "^1.2.0"
},
"autoload": {
"psr-4": {
Expand Down
File renamed without changes
19 changes: 4 additions & 15 deletions src/Services/CallbackService.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@
use LbilTech\TelegramGitNotifier\Bot;
use LbilTech\TelegramGitNotifier\Constants\SettingConstant;
use LbilTech\TelegramGitNotifier\Exceptions\MessageIsEmptyException;
use LbilTech\TelegramGitNotifierApp\Traits\Markup;

class CallbackService
{
use Markup;

private Bot $bot;

public function __construct(Bot $bot)
Expand Down Expand Up @@ -42,7 +45,7 @@ public function answerBackButton(string $callback): void
break;
case 'menu':
$view = view('tools.menu');
$markup = $this->menuMarkup();
$markup = $this->menuMarkup($this->bot->telegram);
break;
default:
$this->bot->answerCallbackQuery('Unknown callback');
Expand All @@ -53,18 +56,4 @@ public function answerBackButton(string $callback): void
'reply_markup' => $markup,
]);
}

/**
* @return array[]
*/
public function menuMarkup(): array
{
return [
[
$this->bot->telegram->buildInlineKeyBoardButton('🗨 Discussion', config('telegram-git-notifier.author.discussion'))
], [
$this->bot->telegram->buildInlineKeyBoardButton('💠 Source Code', config('telegram-git-notifier.author.source_code'))
]
];
}
}
20 changes: 3 additions & 17 deletions src/Services/CommandService.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@

use LbilTech\TelegramGitNotifier\Bot;
use LbilTech\TelegramGitNotifier\Exceptions\EntryNotFoundException;
use Telegram;
use LbilTech\TelegramGitNotifierApp\Traits\Markup;

class CommandService
{
use Markup;

public const MENU_COMMANDS
= [
[
Expand All @@ -34,22 +36,6 @@ class CommandService
],
];

/**
* Generate menu markup
*
* @return array[]
*/
public function menuMarkup(Telegram $telegram): array
{
return [
[
$telegram->buildInlineKeyBoardButton("🗨 Discussion", config('telegram-git-notifier.author.discussion'))
], [
$telegram->buildInlineKeyBoardButton("💠 Source Code", config('telegram-git-notifier.author.source_code'))
]
];
}

/**
* @param Bot $bot
*
Expand Down
24 changes: 24 additions & 0 deletions src/Traits/Markup.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

namespace LbilTech\TelegramGitNotifierApp\Traits;

use Telegram;

trait Markup
{
/**
* Generate menu markup
*
* @return array[]
*/
public function menuMarkup(Telegram $telegram): array
{
return [
[
$telegram->buildInlineKeyBoardButton('🗨 Discussion', config('telegram-git-notifier.author.discussion'))
], [
$telegram->buildInlineKeyBoardButton('💠 Source Code', config('telegram-git-notifier.author.source_code'))
]
];
}
}
1 change: 0 additions & 1 deletion storage/.htaccess

This file was deleted.

0 comments on commit b1b419b

Please sign in to comment.