Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
TelegramBot
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kulya
TelegramBot
Commits
c5a5923d
Unverified
Commit
c5a5923d
authored
Mar 31, 2018
by
Armando Lüscher
Committed by
GitHub
Mar 31, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #810 from noplanman/improve_admin_send_commands
Improve admin send commands
parents
db530e2a
e6aca7a3
Changes
3
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
149 additions
and
135 deletions
+149
-135
CHANGELOG.md
CHANGELOG.md
+1
-0
SendtoallCommand.php
src/Commands/AdminCommands/SendtoallCommand.php
+47
-55
SendtochannelCommand.php
src/Commands/AdminCommands/SendtochannelCommand.php
+101
-80
No files found.
CHANGELOG.md
View file @
c5a5923d
...
...
@@ -13,6 +13,7 @@ Exclamation symbols (:exclamation:) note something of importance e.g. breaking c
-
Updated Travis to use Trusty containers (for HHVM) and add PHP 7.2 to the tests.
-
Add debug log entry instead of throwing an exception for duplicate updates.
-
`Telegram::handleGetUpdates()`
can now work without a database connection (not enabled by default).
-
Improved
`/sendtochannel`
and
`/sendtoall`
commands, using new message helpers.
### Deprecated
### Removed
### Fixed
...
...
src/Commands/AdminCommands/SendtoallCommand.php
View file @
c5a5923d
...
...
@@ -38,7 +38,7 @@ class SendtoallCommand extends AdminCommand
/**
* @var string
*/
protected
$version
=
'1.
4
.0'
;
protected
$version
=
'1.
5
.0'
;
/**
* @var bool
...
...
@@ -53,67 +53,59 @@ class SendtoallCommand extends AdminCommand
*/
public
function
execute
()
{
$message
=
$this
->
getMessage
();
$chat_id
=
$message
->
getChat
()
->
getId
();
$text
=
$message
->
getText
(
true
);
$text
=
$this
->
getMessage
()
->
getText
(
true
);
if
(
$text
===
''
)
{
$text
=
'Write the message to send: /sendtoall <message>'
;
}
else
{
$results
=
Request
::
sendToActiveChats
(
'sendMessage'
,
//callback function to execute (see Request.php methods)
[
'text'
=>
$text
],
//Param to evaluate the request
[
'groups'
=>
true
,
'supergroups'
=>
true
,
'channels'
=>
false
,
'users'
=>
true
,
]
);
$total
=
0
;
$failed
=
0
;
$text
=
'Message sent to:'
.
PHP_EOL
;
/** @var ServerResponse $result */
foreach
(
$results
as
$result
)
{
$name
=
''
;
$type
=
''
;
if
(
$result
->
isOk
())
{
$status
=
'✔️'
;
/** @var Message $message */
$message
=
$result
->
getResult
();
$chat
=
$message
->
getChat
();
if
(
$chat
->
isPrivateChat
())
{
$name
=
$chat
->
getFirstName
();
$type
=
'user'
;
}
else
{
$name
=
$chat
->
getTitle
();
$type
=
'chat'
;
}
return
$this
->
replyToChat
(
'Usage: '
.
$this
->
getUsage
());
}
/** @var ServerResponse[] $results */
$results
=
Request
::
sendToActiveChats
(
'sendMessage'
,
//callback function to execute (see Request.php methods)
[
'text'
=>
$text
],
//Param to evaluate the request
[
'groups'
=>
true
,
'supergroups'
=>
true
,
'channels'
=>
false
,
'users'
=>
true
,
]
);
if
(
empty
(
$results
))
{
return
$this
->
replyToChat
(
'No users or chats found.'
);
}
$total
=
0
;
$failed
=
0
;
$text
=
'Message sent to:'
.
PHP_EOL
;
foreach
(
$results
as
$result
)
{
$name
=
''
;
$type
=
''
;
if
(
$result
->
isOk
())
{
$status
=
'✔️'
;
/** @var Message $message */
$message
=
$result
->
getResult
();
$chat
=
$message
->
getChat
();
if
(
$chat
->
isPrivateChat
())
{
$name
=
$chat
->
getFirstName
();
$type
=
'user'
;
}
else
{
$
status
=
'✖️'
;
++
$failed
;
$
name
=
$chat
->
getTitle
()
;
$type
=
'chat'
;
}
++
$total
;
$text
.=
$total
.
') '
.
$status
.
' '
.
$type
.
' '
.
$name
.
PHP_EOL
;
}
else
{
$status
=
'✖️'
;
++
$failed
;
}
$text
.=
'Delivered: '
.
(
$total
-
$failed
)
.
'/'
.
$total
.
PHP_EOL
;
++
$total
;
if
(
$total
===
0
)
{
$text
=
'No users or chats found..'
;
}
$text
.=
$total
.
') '
.
$status
.
' '
.
$type
.
' '
.
$name
.
PHP_EOL
;
}
$text
.=
'Delivered: '
.
(
$total
-
$failed
)
.
'/'
.
$total
.
PHP_EOL
;
$data
=
[
'chat_id'
=>
$chat_id
,
'text'
=>
$text
,
];
return
Request
::
sendMessage
(
$data
);
return
$this
->
replyToChat
(
$text
);
}
}
src/Commands/AdminCommands/SendtochannelCommand.php
View file @
c5a5923d
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment