Commit fba22125 authored by Armando Lüscher's avatar Armando Lüscher

Clean Admin commands, removing all unnecessary or unused code.

parent a35d2cec
...@@ -13,8 +13,6 @@ namespace Longman\TelegramBot\Commands; ...@@ -13,8 +13,6 @@ namespace Longman\TelegramBot\Commands;
use Longman\TelegramBot\Command; use Longman\TelegramBot\Command;
use Longman\TelegramBot\DB; use Longman\TelegramBot\DB;
use Longman\TelegramBot\Entities\Chat; use Longman\TelegramBot\Entities\Chat;
use Longman\TelegramBot\Entities\Update;
use Longman\TelegramBot\Exception\TelegramException;
use Longman\TelegramBot\Request; use Longman\TelegramBot\Request;
/** /**
...@@ -50,13 +48,6 @@ class ChatsCommand extends Command ...@@ -50,13 +48,6 @@ class ChatsCommand extends Command
*/ */
protected $version = '1.0.0'; protected $version = '1.0.0';
/**
* If this command is enabled
*
* @var boolean
*/
protected $enabled = true;
/** /**
* If this command is public * If this command is public
* *
...@@ -81,12 +72,13 @@ class ChatsCommand extends Command ...@@ -81,12 +72,13 @@ class ChatsCommand extends Command
//Preparing message //Preparing message
$message = $this->getMessage(); $message = $this->getMessage();
$chat_id = $message->getChat()->getId(); $chat_id = $message->getChat()->getId();
$data = [ $data = [
'chat_id' => $chat_id, 'chat_id' => $chat_id,
'text' => 'Sorry no database connection, unable to execute "' . $this->name . '" command.', 'text' => 'Sorry no database connection, unable to execute "' . $this->name . '" command.',
]; ];
$result = Request::sendMessage($data);
return $result->isOk(); return Request::sendMessage($data)->isOk();
} }
/** /**
...@@ -96,12 +88,9 @@ class ChatsCommand extends Command ...@@ -96,12 +88,9 @@ class ChatsCommand extends Command
*/ */
public function execute() public function execute()
{ {
$update = $this->getUpdate();
$message = $this->getMessage(); $message = $this->getMessage();
$chat_id = $message->getChat()->getId(); $chat_id = $message->getChat()->getId();
$message_id = $message->getMessageId();
$text = $message->getText(true);
$results = DB::selectChats( $results = DB::selectChats(
true, //Send to groups (group chat) true, //Send to groups (group chat)
...@@ -133,7 +122,7 @@ class ChatsCommand extends Command ...@@ -133,7 +122,7 @@ class ChatsCommand extends Command
} }
} }
if (($user_chats + $group_chats + $super_group_chats) == 0) { if (($user_chats + $group_chats + $super_group_chats) === 0) {
$text = 'No chats found..'; $text = 'No chats found..';
} else { } else {
$text .= "\n" . 'Private Chats: ' . $user_chats; $text .= "\n" . 'Private Chats: ' . $user_chats;
...@@ -146,7 +135,7 @@ class ChatsCommand extends Command ...@@ -146,7 +135,7 @@ class ChatsCommand extends Command
'chat_id' => $chat_id, 'chat_id' => $chat_id,
'text' => $text, 'text' => $text,
]; ];
$result = Request::sendMessage($data);
return $result->isOk(); return Request::sendMessage($data)->isOk();
} }
} }
...@@ -11,9 +11,6 @@ ...@@ -11,9 +11,6 @@
namespace Longman\TelegramBot\Commands; namespace Longman\TelegramBot\Commands;
use Longman\TelegramBot\Command; use Longman\TelegramBot\Command;
use Longman\TelegramBot\DB;
use Longman\TelegramBot\Entities\Update;
use Longman\TelegramBot\Exception\TelegramException;
use Longman\TelegramBot\Request; use Longman\TelegramBot\Request;
/** /**
...@@ -49,13 +46,6 @@ class SendtoallCommand extends Command ...@@ -49,13 +46,6 @@ class SendtoallCommand extends Command
*/ */
protected $version = '1.2.0'; protected $version = '1.2.0';
/**
* If this command is enabled
*
* @var boolean
*/
protected $enabled = true;
/** /**
* If this command is public * If this command is public
* *
...@@ -80,12 +70,13 @@ class SendtoallCommand extends Command ...@@ -80,12 +70,13 @@ class SendtoallCommand extends Command
//Preparing message //Preparing message
$message = $this->getMessage(); $message = $this->getMessage();
$chat_id = $message->getChat()->getId(); $chat_id = $message->getChat()->getId();
$data = [ $data = [
'chat_id' => $chat_id, 'chat_id' => $chat_id,
'text' => 'Sorry no database connection, unable to execute "' . $this->name . '" command.', 'text' => 'Sorry no database connection, unable to execute "' . $this->name . '" command.',
]; ];
$result = Request::sendMessage($data);
return $result->isOk(); return Request::sendMessage($data)->isOk();
} }
/** /**
...@@ -97,12 +88,9 @@ class SendtoallCommand extends Command ...@@ -97,12 +88,9 @@ class SendtoallCommand extends Command
*/ */
public function execute() public function execute()
{ {
$update = $this->getUpdate();
$message = $this->getMessage(); $message = $this->getMessage();
$chat_id = $message->getChat()->getId(); $chat_id = $message->getChat()->getId();
$message_id = $message->getMessageId();
$text = $message->getText(true);
if (empty($text)) { if (empty($text)) {
$text = 'Write the message to send: /sendall <message>'; $text = 'Write the message to send: /sendall <message>';
...@@ -147,7 +135,7 @@ class SendtoallCommand extends Command ...@@ -147,7 +135,7 @@ class SendtoallCommand extends Command
} }
$text .= 'Delivered: ' . ($tot - $fail) . '/' . $tot . "\n"; $text .= 'Delivered: ' . ($tot - $fail) . '/' . $tot . "\n";
} }
if ($tot == 0) { if ($tot === 0) {
$text = 'No users or chats found..'; $text = 'No users or chats found..';
} }
...@@ -156,7 +144,6 @@ class SendtoallCommand extends Command ...@@ -156,7 +144,6 @@ class SendtoallCommand extends Command
'text' => $text, 'text' => $text,
]; ];
$result = Request::sendMessage($data); return Request::sendMessage($data)->isOk();
return $result->isOk();
} }
} }
...@@ -11,9 +11,6 @@ ...@@ -11,9 +11,6 @@
namespace Longman\TelegramBot\Commands; namespace Longman\TelegramBot\Commands;
use Longman\TelegramBot\Command; use Longman\TelegramBot\Command;
use Longman\TelegramBot\DB;
use Longman\TelegramBot\Entities\Update;
use Longman\TelegramBot\Exception\TelegramException;
use Longman\TelegramBot\Request; use Longman\TelegramBot\Request;
/** /**
...@@ -49,13 +46,6 @@ class SendtochannelCommand extends Command ...@@ -49,13 +46,6 @@ class SendtochannelCommand extends Command
*/ */
protected $version = '0.1.0'; protected $version = '0.1.0';
/**
* If this command is enabled
*
* @var boolean
*/
protected $enabled = true;
/** /**
* If this command is public * If this command is public
* *
...@@ -79,11 +69,9 @@ class SendtochannelCommand extends Command ...@@ -79,11 +69,9 @@ class SendtochannelCommand extends Command
*/ */
public function execute() public function execute()
{ {
$update = $this->getUpdate();
$message = $this->getMessage(); $message = $this->getMessage();
$chat_id = $message->getChat()->getId(); $chat_id = $message->getChat()->getId();
$message_id = $message->getMessageId();
$text = $message->getText(true); $text = $message->getText(true);
if (empty($text)) { if (empty($text)) {
...@@ -109,7 +97,6 @@ class SendtochannelCommand extends Command ...@@ -109,7 +97,6 @@ class SendtochannelCommand extends Command
'text' => $text_back, 'text' => $text_back,
]; ];
$result = Request::sendMessage($data); return Request::sendMessage($data)->isOk();
return $result->isOk();
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment