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
d21f6e9d
Commit
d21f6e9d
authored
Jun 20, 2017
by
Armando Lüscher
Committed by
GitHub
Jun 20, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'develop' into api_3.0_basic_changes
parents
12e412b5
195910c5
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
95 additions
and
95 deletions
+95
-95
CHANGELOG.md
CHANGELOG.md
+2
-0
ChatsCommand.php
src/Commands/AdminCommands/ChatsCommand.php
+24
-18
SendtoallCommand.php
src/Commands/AdminCommands/SendtoallCommand.php
+8
-7
WhoisCommand.php
src/Commands/AdminCommands/WhoisCommand.php
+19
-21
DB.php
src/DB.php
+35
-34
Request.php
src/Request.php
+7
-15
No files found.
CHANGELOG.md
View file @
d21f6e9d
...
...
@@ -9,6 +9,7 @@ Exclamation symbols (:exclamation:) note something of importance e.g. breaking c
-
Allow setting a custom Guzzle HTTP Client for requests (#511).
-
First implementations towards Bots API 3.0.
### Changed
-
[
:exclamation:
][
unreleased-bc-chats-params-array
]
`Request::sendToActiveChats`
and
`DB::selectChats`
now accept parameters as an options array.
### Deprecated
### Removed
-
[
:exclamation:
][
unreleased-bc-up-download-directory
]
Upload and download directories are not set any more by default and must be set manually.
...
...
@@ -106,5 +107,6 @@ Exclamation symbols (:exclamation:) note something of importance e.g. breaking c
### Deprecated
-
Move
`hideKeyboard`
to
`removeKeyboard`
.
[
unreleased-bc-chats-params-array
]:
https://github.com/php-telegram-bot/core/wiki/Breaking-backwards-compatibility#unreleased
[
unreleased-bc-up-download-directory
]:
https://github.com/php-telegram-bot/core/wiki/Breaking-backwards-compatibility#unreleased
[
0.44.0-bc-update-content-type
]:
https://github.com/php-telegram-bot/core/wiki/Breaking-backwards-compatibility#update-getupdatecontent
src/Commands/AdminCommands/ChatsCommand.php
View file @
d21f6e9d
...
...
@@ -35,7 +35,7 @@ class ChatsCommand extends AdminCommand
/**
* @var string
*/
protected
$version
=
'1.
1
.0'
;
protected
$version
=
'1.
2
.0'
;
/**
* @var bool
...
...
@@ -45,7 +45,7 @@ class ChatsCommand extends AdminCommand
/**
* Command execute method
*
* @return
mixed
* @return
\Longman\TelegramBot\Entities\ServerResponse
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
public
function
execute
()
...
...
@@ -55,19 +55,18 @@ class ChatsCommand extends AdminCommand
$chat_id
=
$message
->
getChat
()
->
getId
();
$text
=
trim
(
$message
->
getText
(
true
));
$results
=
DB
::
selectChats
(
true
,
//Select groups (group chat)
true
,
//Select supergroups (super group chat)
true
,
//Select users (single chat)
null
,
//'yyyy-mm-dd hh:mm:ss' date range from
null
,
//'yyyy-mm-dd hh:mm:ss' date range to
null
,
//Specific chat_id to select
(
$text
===
''
||
$text
===
'*'
)
?
null
:
$text
//Text to search in user/group name
);
$results
=
DB
::
selectChats
([
'groups'
=>
true
,
'supergroups'
=>
true
,
'channels'
=>
true
,
'users'
=>
true
,
'text'
=>
(
$text
===
''
||
$text
===
'*'
)
?
null
:
$text
//Text to search in user/group name
]);
$user_chats
=
0
;
$group_chats
=
0
;
$super_group_chats
=
0
;
$user_chats
=
0
;
$group_chats
=
0
;
$supergroup_chats
=
0
;
$channel_chats
=
0
;
if
(
$text
===
''
)
{
$text_back
=
''
;
...
...
@@ -100,24 +99,31 @@ class ChatsCommand extends AdminCommand
$text_back
.=
'- S '
.
$chat
->
getTitle
()
.
' ['
.
$whois
.
']'
.
PHP_EOL
;
}
++
$super
_
group_chats
;
++
$supergroup_chats
;
}
elseif
(
$chat
->
isGroupChat
())
{
if
(
$text
!==
''
)
{
$text_back
.=
'- G '
.
$chat
->
getTitle
()
.
' ['
.
$whois
.
']'
.
PHP_EOL
;
}
++
$group_chats
;
}
elseif
(
$chat
->
isChannel
())
{
if
(
$text
!==
''
)
{
$text_back
.=
'- C '
.
$chat
->
getTitle
()
.
' ['
.
$whois
.
']'
.
PHP_EOL
;
}
++
$channel_chats
;
}
}
}
if
((
$user_chats
+
$group_chats
+
$super
_
group_chats
)
===
0
)
{
if
((
$user_chats
+
$group_chats
+
$supergroup_chats
)
===
0
)
{
$text_back
=
'No chats found..'
;
}
else
{
$text_back
.=
PHP_EOL
.
'Private Chats: '
.
$user_chats
;
$text_back
.=
PHP_EOL
.
'Groups: '
.
$group_chats
;
$text_back
.=
PHP_EOL
.
'Super Groups: '
.
$super_group_chats
;
$text_back
.=
PHP_EOL
.
'Total: '
.
(
$user_chats
+
$group_chats
+
$super_group_chats
);
$text_back
.=
PHP_EOL
.
'Super Groups: '
.
$supergroup_chats
;
$text_back
.=
PHP_EOL
.
'Channels: '
.
$channel_chats
;
$text_back
.=
PHP_EOL
.
'Total: '
.
(
$user_chats
+
$group_chats
+
$supergroup_chats
);
if
(
$text
===
''
)
{
$text_back
.=
PHP_EOL
.
PHP_EOL
.
'List all chats: /'
.
$this
->
name
.
' *'
.
PHP_EOL
.
'Search for chats: /'
.
$this
->
name
.
' <search string>'
;
...
...
src/Commands/AdminCommands/SendtoallCommand.php
View file @
d21f6e9d
...
...
@@ -38,7 +38,7 @@ class SendtoallCommand extends AdminCommand
/**
* @var string
*/
protected
$version
=
'1.
3
.0'
;
protected
$version
=
'1.
4
.0'
;
/**
* @var bool
...
...
@@ -48,7 +48,7 @@ class SendtoallCommand extends AdminCommand
/**
* Execute command
*
* @return
boolean
* @return
\Longman\TelegramBot\Entities\ServerResponse
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
public
function
execute
()
...
...
@@ -64,11 +64,12 @@ class SendtoallCommand extends AdminCommand
$results
=
Request
::
sendToActiveChats
(
'sendMessage'
,
//callback function to execute (see Request.php methods)
[
'text'
=>
$text
],
//Param to evaluate the request
true
,
//Send to groups (group chat)
true
,
//Send to super groups chats (super group chat)
true
,
//Send to users (single chat)
null
,
//'yyyy-mm-dd hh:mm:ss' date range from
null
//'yyyy-mm-dd hh:mm:ss' date range to
[
'groups'
=>
true
,
'supergroups'
=>
true
,
'channels'
=>
false
,
'users'
=>
true
,
]
);
$total
=
0
;
...
...
src/Commands/AdminCommands/WhoisCommand.php
View file @
d21f6e9d
...
...
@@ -42,7 +42,7 @@ class WhoisCommand extends AdminCommand
/**
* @var string
*/
protected
$version
=
'1.
2
.0'
;
protected
$version
=
'1.
3
.0'
;
/**
* @var bool
...
...
@@ -52,7 +52,7 @@ class WhoisCommand extends AdminCommand
/**
* Command execute method
*
* @return
mixed
* @return
\Longman\TelegramBot\Entities\ServerResponse
* @throws \Longman\TelegramBot\Exception\TelegramException
*/
public
function
execute
()
...
...
@@ -89,28 +89,25 @@ class WhoisCommand extends AdminCommand
$result
=
null
;
if
(
is_numeric
(
$text
))
{
$results
=
DB
::
selectChats
(
true
,
//Select groups (group chat)
true
,
//Select supergroups (super group chat)
true
,
//Select users (single chat)
null
,
//'yyyy-mm-dd hh:mm:ss' date range from
null
,
//'yyyy-mm-dd hh:mm:ss' date range to
$user_id
//Specific chat_id to select
);
$results
=
DB
::
selectChats
([
'groups'
=>
true
,
'supergroups'
=>
true
,
'channels'
=>
true
,
'users'
=>
true
,
'chat_id'
=>
$user_id
,
//Specific chat_id to select
]);
if
(
!
empty
(
$results
))
{
$result
=
reset
(
$results
);
}
}
else
{
$results
=
DB
::
selectChats
(
true
,
//Select groups (group chat)
true
,
//Select supergroups (super group chat)
true
,
//Select users (single chat)
null
,
//'yyyy-mm-dd hh:mm:ss' date range from
null
,
//'yyyy-mm-dd hh:mm:ss' date range to
null
,
//Specific chat_id to select
$text
//Text to search in user/group name
);
$results
=
DB
::
selectChats
([
'groups'
=>
true
,
'supergroups'
=>
true
,
'channels'
=>
true
,
'users'
=>
true
,
'text'
=>
$text
//Text to search in user/group name
]);
if
(
is_array
(
$results
)
&&
count
(
$results
)
===
1
)
{
$result
=
reset
(
$results
);
...
...
@@ -118,8 +115,9 @@ class WhoisCommand extends AdminCommand
}
if
(
is_array
(
$result
))
{
$result
[
'id'
]
=
$result
[
'chat_id'
];
$chat
=
new
Chat
(
$result
);
$result
[
'id'
]
=
$result
[
'chat_id'
];
$result
[
'username'
]
=
$result
[
'chat_username'
];
$chat
=
new
Chat
(
$result
);
$user_id
=
$result
[
'id'
];
$created_at
=
$result
[
'chat_created_at'
];
...
...
src/DB.php
View file @
d21f6e9d
...
...
@@ -990,33 +990,32 @@ class DB
}
/**
* Select Group
and/or single Chats
* Select Group
s, Supergroups, Channels and/or single user Chats (also by ID or text)
*
* @param bool $select_groups
* @param bool $select_super_groups
* @param bool $select_users
* @param string $date_from
* @param string $date_to
* @param int $chat_id
* @param string $text
* @param $select_chats_params
*
* @return array|bool
(Selected chats or false if invalid arguments)
* @throws
\Longman\TelegramBot\Exception\
TelegramException
* @return array|bool
* @throws TelegramException
*/
public
static
function
selectChats
(
$select_groups
=
true
,
$select_super_groups
=
true
,
$select_users
=
true
,
$date_from
=
null
,
$date_to
=
null
,
$chat_id
=
null
,
$text
=
null
)
{
public
static
function
selectChats
(
$select_chats_params
)
{
if
(
!
self
::
isDbConnected
())
{
return
false
;
}
if
(
!
$select_groups
&&
!
$select_users
&&
!
$select_super_groups
)
{
// Set defaults for omitted values.
$select
=
array_merge
([
'groups'
=>
true
,
'supergroups'
=>
true
,
'channels'
=>
true
,
'users'
=>
true
,
'date_from'
=>
null
,
'date_to'
=>
null
,
'chat_id'
=>
null
,
'text'
=>
null
,
],
$select_chats_params
);
if
(
!
$select
[
'groups'
]
&&
!
$select
[
'users'
]
&&
!
$select
[
'supergroups'
])
{
return
false
;
}
...
...
@@ -1024,10 +1023,11 @@ class DB
$query
=
'
SELECT * ,
'
.
TB_CHAT
.
'.`id` AS `chat_id`,
'
.
TB_CHAT
.
'.`username` AS `chat_username`,
'
.
TB_CHAT
.
'.`created_at` AS `chat_created_at`,
'
.
TB_CHAT
.
'.`updated_at` AS `chat_updated_at`
'
;
if
(
$select
_users
)
{
if
(
$select
[
'users'
]
)
{
$query
.=
'
, '
.
TB_USER
.
'.`id` AS `user_id`
FROM `'
.
TB_CHAT
.
'`
...
...
@@ -1042,33 +1042,34 @@ class DB
$where
=
[];
$tokens
=
[];
if
(
!
$select
_groups
||
!
$select_users
||
!
$select_super_groups
)
{
if
(
!
$select
[
'groups'
]
||
!
$select
[
'users'
]
||
!
$select
[
'supergroups'
]
)
{
$chat_or_user
=
[];
$select_groups
&&
$chat_or_user
[]
=
TB_CHAT
.
'.`type` = "group"'
;
$select_super_groups
&&
$chat_or_user
[]
=
TB_CHAT
.
'.`type` = "supergroup"'
;
$select_users
&&
$chat_or_user
[]
=
TB_CHAT
.
'.`type` = "private"'
;
$select
[
'groups'
]
&&
$chat_or_user
[]
=
TB_CHAT
.
'.`type` = "group"'
;
$select
[
'supergroups'
]
&&
$chat_or_user
[]
=
TB_CHAT
.
'.`type` = "supergroup"'
;
$select
[
'channels'
]
&&
$chat_or_user
[]
=
TB_CHAT
.
'.`type` = "channel"'
;
$select
[
'users'
]
&&
$chat_or_user
[]
=
TB_CHAT
.
'.`type` = "private"'
;
$where
[]
=
'('
.
implode
(
' OR '
,
$chat_or_user
)
.
')'
;
}
if
(
null
!==
$
date_from
)
{
if
(
null
!==
$
select
[
'date_from'
]
)
{
$where
[]
=
TB_CHAT
.
'.`updated_at` >= :date_from'
;
$tokens
[
':date_from'
]
=
$
date_from
;
$tokens
[
':date_from'
]
=
$
select
[
'date_from'
]
;
}
if
(
null
!==
$
date_to
)
{
if
(
null
!==
$
select
[
'date_to'
]
)
{
$where
[]
=
TB_CHAT
.
'.`updated_at` <= :date_to'
;
$tokens
[
':date_to'
]
=
$
date_to
;
$tokens
[
':date_to'
]
=
$
select
[
'date_to'
]
;
}
if
(
null
!==
$
chat_id
)
{
if
(
null
!==
$
select
[
'chat_id'
]
)
{
$where
[]
=
TB_CHAT
.
'.`id` = :chat_id'
;
$tokens
[
':chat_id'
]
=
$
chat_id
;
$tokens
[
':chat_id'
]
=
$
select
[
'chat_id'
]
;
}
if
(
null
!==
$
text
)
{
if
(
$select
_users
)
{
if
(
null
!==
$
select
[
'text'
]
)
{
if
(
$select
[
'users'
]
)
{
$where
[]
=
'(
LOWER('
.
TB_CHAT
.
'.`title`) LIKE :text
OR LOWER('
.
TB_USER
.
'.`first_name`) LIKE :text
...
...
@@ -1078,7 +1079,7 @@ class DB
}
else
{
$where
[]
=
'LOWER('
.
TB_CHAT
.
'.`title`) LIKE :text'
;
}
$tokens
[
':text'
]
=
'%'
.
strtolower
(
$
text
)
.
'%'
;
$tokens
[
':text'
]
=
'%'
.
strtolower
(
$
select
[
'text'
]
)
.
'%'
;
}
if
(
!
empty
(
$where
))
{
...
...
src/Request.php
View file @
d21f6e9d
...
...
@@ -962,38 +962,30 @@ class Request
/**
* Send message to all active chats
*
* @param string $callback_function
* @param array $data
* @param boolean $send_groups
* @param boolean $send_super_groups
* @param boolean $send_users
* @param string $date_from
* @param string $date_to
* @param string $callback_function
* @param array $data
* @param array $select_chats_params
*
* @return array
* @throws
\Longman\TelegramBot\Exception\
TelegramException
* @throws TelegramException
*/
public
static
function
sendToActiveChats
(
$callback_function
,
array
$data
,
$send_groups
=
true
,
$send_super_groups
=
true
,
$send_users
=
true
,
$date_from
=
null
,
$date_to
=
null
array
$select_chats_params
)
{
$callback_path
=
__NAMESPACE__
.
'\Request'
;
if
(
!
method_exists
(
$callback_path
,
$callback_function
))
{
throw
new
TelegramException
(
'Method "'
.
$callback_function
.
'" not found in class Request.'
);
}
$chats
=
DB
::
selectChats
(
$se
nd_groups
,
$send_super_groups
,
$send_users
,
$date_from
,
$date_to
);
$chats
=
DB
::
selectChats
(
$se
lect_chats_params
);
$results
=
[];
if
(
is_array
(
$chats
))
{
foreach
(
$chats
as
$row
)
{
$data
[
'chat_id'
]
=
$row
[
'chat_id'
];
$results
[]
=
call_user_func
_array
(
$callback_path
.
'::'
.
$callback_function
,
[
$data
]
);
$results
[]
=
call_user_func
(
$callback_path
.
'::'
.
$callback_function
,
$data
);
}
}
...
...
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