@@ -38,7 +38,7 @@ class SendtoallCommand extends AdminCommand
38
38
/**
39
39
* @var string
40
40
*/
41
- protected $ version = '1.4 .0 ' ;
41
+ protected $ version = '1.5 .0 ' ;
42
42
43
43
/**
44
44
* @var bool
@@ -53,67 +53,59 @@ class SendtoallCommand extends AdminCommand
53
53
*/
54
54
public function execute ()
55
55
{
56
- $ message = $ this ->getMessage ();
57
-
58
- $ chat_id = $ message ->getChat ()->getId ();
59
- $ text = $ message ->getText (true );
56
+ $ text = $ this ->getMessage ()->getText (true );
60
57
61
58
if ($ text === '' ) {
62
- $ text = 'Write the message to send: /sendtoall <message> ' ;
63
- } else {
64
- $ results = Request::sendToActiveChats (
65
- 'sendMessage ' , //callback function to execute (see Request.php methods)
66
- ['text ' => $ text ], //Param to evaluate the request
67
- [
68
- 'groups ' => true ,
69
- 'supergroups ' => true ,
70
- 'channels ' => false ,
71
- 'users ' => true ,
72
- ]
73
- );
74
-
75
- $ total = 0 ;
76
- $ failed = 0 ;
77
-
78
- $ text = 'Message sent to: ' . PHP_EOL ;
79
-
80
- /** @var ServerResponse $result */
81
- foreach ($ results as $ result ) {
82
- $ name = '' ;
83
- $ type = '' ;
84
- if ($ result ->isOk ()) {
85
- $ status = '✔️ ' ;
86
-
87
- /** @var Message $message */
88
- $ message = $ result ->getResult ();
89
- $ chat = $ message ->getChat ();
90
- if ($ chat ->isPrivateChat ()) {
91
- $ name = $ chat ->getFirstName ();
92
- $ type = 'user ' ;
93
- } else {
94
- $ name = $ chat ->getTitle ();
95
- $ type = 'chat ' ;
96
- }
59
+ return $ this ->replyToChat ('Usage: ' . $ this ->getUsage ());
60
+ }
61
+
62
+ /** @var ServerResponse[] $results */
63
+ $ results = Request::sendToActiveChats (
64
+ 'sendMessage ' , //callback function to execute (see Request.php methods)
65
+ ['text ' => $ text ], //Param to evaluate the request
66
+ [
67
+ 'groups ' => true ,
68
+ 'supergroups ' => true ,
69
+ 'channels ' => false ,
70
+ 'users ' => true ,
71
+ ]
72
+ );
73
+
74
+ if (empty ($ results )) {
75
+ return $ this ->replyToChat ('No users or chats found. ' );
76
+ }
77
+
78
+ $ total = 0 ;
79
+ $ failed = 0 ;
80
+
81
+ $ text = 'Message sent to: ' . PHP_EOL ;
82
+
83
+ foreach ($ results as $ result ) {
84
+ $ name = '' ;
85
+ $ type = '' ;
86
+ if ($ result ->isOk ()) {
87
+ $ status = '✔️ ' ;
88
+
89
+ /** @var Message $message */
90
+ $ message = $ result ->getResult ();
91
+ $ chat = $ message ->getChat ();
92
+ if ($ chat ->isPrivateChat ()) {
93
+ $ name = $ chat ->getFirstName ();
94
+ $ type = 'user ' ;
97
95
} else {
98
- $ status = ' ✖️ ' ;
99
- ++ $ failed ;
96
+ $ name = $ chat -> getTitle () ;
97
+ $ type = ' chat ' ;
100
98
}
101
- ++ $ total ;
102
-
103
- $ text .= $ total . ' ) ' . $ status . ' ' . $ type . ' ' . $ name . PHP_EOL ;
99
+ } else {
100
+ $ status = ' ✖️ ' ;
101
+ ++ $ failed ;
104
102
}
105
- $ text .= ' Delivered: ' . ( $ total - $ failed ) . ' / ' . $ total . PHP_EOL ;
103
+ ++ $ total ;
106
104
107
- if ($ total === 0 ) {
108
- $ text = 'No users or chats found.. ' ;
109
- }
105
+ $ text .= $ total . ') ' . $ status . ' ' . $ type . ' ' . $ name . PHP_EOL ;
110
106
}
107
+ $ text .= 'Delivered: ' . ($ total - $ failed ) . '/ ' . $ total . PHP_EOL ;
111
108
112
- $ data = [
113
- 'chat_id ' => $ chat_id ,
114
- 'text ' => $ text ,
115
- ];
116
-
117
- return Request::sendMessage ($ data );
109
+ return $ this ->replyToChat ($ text );
118
110
}
119
111
}
0 commit comments