@@ -57,6 +57,11 @@ class CleanupCommand extends AdminCommand
5757 */
5858 protected $ version = '1.0.0 ' ;
5959
60+ /**
61+ * @var bool
62+ */
63+ protected $ need_mysql = true ;
64+
6065 /**
6166 * Default tables to clean, cleaning 'chat', 'user' and 'user_chat' by default is bad practice!
6267 *
@@ -318,6 +323,25 @@ private function getQueries($settings)
318323 return $ queries ;
319324 }
320325
326+ /**
327+ * Execution if MySQL is required but not available
328+ *
329+ * @return \Longman\TelegramBot\Entities\ServerResponse
330+ */
331+ public function executeNoDb ()
332+ {
333+ $ message = $ this ->getMessage ();
334+ $ chat_id = $ message ->getChat ()->getId ();
335+
336+ $ data = [
337+ 'chat_id ' => $ chat_id ,
338+ 'parse_mode ' => 'Markdown ' ,
339+ 'text ' => '*No database connection!* ' ,
340+ ];
341+
342+ return Request::sendMessage ($ data );
343+ }
344+
321345 /**
322346 * Command execute method
323347 *
@@ -327,20 +351,14 @@ private function getQueries($settings)
327351 public function execute ()
328352 {
329353 $ message = $ this ->getMessage ();
330- $ chat_id = $ message ->getFrom ()->getId ();
354+ $ user_id = $ message ->getFrom ()->getId ();
331355 $ text = $ message ->getText (true );
332356
333357 $ data = [
334- 'chat_id ' => $ chat_id ,
358+ 'chat_id ' => $ user_id ,
335359 'parse_mode ' => 'Markdown ' ,
336360 ];
337361
338- if (!$ message ->getChat ()->isPrivateChat ()) {
339- $ data ['text ' ] = '/cleanup command is only available in a private chat. ' ;
340-
341- return Request::sendMessage ($ data );
342- }
343-
344362 $ settings = $ this ->getSettings ($ text );
345363 $ queries = $ this ->getQueries ($ settings );
346364
0 commit comments