Skip to content

Commit

Permalink
Refactor help command fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
0xEAB committed Sep 4, 2017
1 parent 7177550 commit 38585c8
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions Commands/HelpCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ public function execute()
$chat_id = $message->getChat()->getId();
$command_str = trim($message->getText(true));

// Admin commands shouldn't be shown in group chats
$safe_to_show = $message->getChat()->isPrivateChat();

$data = [
'chat_id' => $chat_id,
'parse_mode' => 'markdown',
Expand All @@ -64,9 +67,7 @@ public function execute()
$data['text'] .= '/' . $user_command->getName() . ' - ' . $user_command->getDescription() . PHP_EOL;
}

if ((count($admin_commands) > 0) &&
!$message->getChat()->isGroupChat() && $this->telegram->isAdmin($message->getFrom()->getId())) {

if ((count($admin_commands) > 0) && $safe_to_show) {
$data['text'] .= PHP_EOL . '*Admin Commands List*:' . PHP_EOL;
foreach ($admin_commands as $admin_command) {
$data['text'] .= '/' . $admin_command->getName() . ' - ' . $admin_command->getDescription() . PHP_EOL;
Expand All @@ -79,9 +80,7 @@ public function execute()
}

$command_str = str_replace('/', '', $command_str);
if (isset($all_commands[$command_str]) && (!$all_commands[$command_str]->isAdminCommand()) ||
(!$message->getChat()->isGroupChat() && $this->telegram->isAdmin($message->getFrom()->getId()))) {

if (isset($all_commands[$command_str]) && ($safe_to_show || !$all_commands[$command_str]->isAdminCommand())) {
$command = $all_commands[$command_str];
$data['text'] = sprintf(
'Command: %s (v%s)' . PHP_EOL .
Expand Down

0 comments on commit 38585c8

Please sign in to comment.