Unverified Commit 7564a3af authored by Armando Lüscher's avatar Armando Lüscher

Merge branch 'develop' into 811-helper_for_media_groups

parents 28624d8b 0efd5677
...@@ -8,10 +8,13 @@ Exclamation symbols (:exclamation:) note something of importance e.g. breaking c ...@@ -8,10 +8,13 @@ Exclamation symbols (:exclamation:) note something of importance e.g. breaking c
- Helper for sending `InputMedia` objects using `Request::sendMediaGroup()` and `Request::editMediaMessage()` methods. - Helper for sending `InputMedia` objects using `Request::sendMediaGroup()` and `Request::editMediaMessage()` methods.
- Allow passing absolute file path for InputFile fields, instead of `Request::encodeFile($path)`. - Allow passing absolute file path for InputFile fields, instead of `Request::encodeFile($path)`.
### Changed ### Changed
- All Message field types dynamically search for an existing Command class that can handle them.
### Deprecated ### Deprecated
- Botan.io service has been discontinued. - Botan.io service has been discontinued.
- Most built-in System Commands will be handled by GenericmessageCommand by default in a future release and will require a custom implementation.
### Removed ### Removed
### Fixed ### Fixed
- Constraint errors in `/cleanup` command.
- Return correct objects for requests. - Return correct objects for requests.
### Security ### Security
......
...@@ -164,6 +164,7 @@ class CleanupCommand extends AdminCommand ...@@ -164,6 +164,7 @@ class CleanupCommand extends AdminCommand
SELECT `id` SELECT `id`
FROM `%4$s` FROM `%4$s`
WHERE `chat_id` = `%4$s`.`id` WHERE `chat_id` = `%4$s`.`id`
AND `updated_at` < \'%1$s\'
) )
AND ( AND (
`message_id` IS NOT NULL `message_id` IS NOT NULL
...@@ -301,6 +302,11 @@ class CleanupCommand extends AdminCommand ...@@ -301,6 +302,11 @@ class CleanupCommand extends AdminCommand
if (in_array('message', $tables_to_clean, true)) { if (in_array('message', $tables_to_clean, true)) {
$queries[] = sprintf( $queries[] = sprintf(
'DELETE FROM `%1$s` 'DELETE FROM `%1$s`
WHERE id IN (
SELECT id
FROM (
SELECT id
FROM `message`
WHERE `date` < \'%2$s\' WHERE `date` < \'%2$s\'
AND `id` NOT IN ( AND `id` NOT IN (
SELECT `message_id` SELECT `message_id`
...@@ -312,9 +318,22 @@ class CleanupCommand extends AdminCommand ...@@ -312,9 +318,22 @@ class CleanupCommand extends AdminCommand
FROM `%4$s` FROM `%4$s`
WHERE `message_id` = `%1$s`.`id` WHERE `message_id` = `%1$s`.`id`
) )
AND `id` NOT IN (
SELECT `message_id`
FROM `%5$s`
WHERE `message_id` = `%1$s`.`id`
)
AND `id` NOT IN (
SELECT a.`reply_to_message` FROM `%1$s` a
INNER JOIN `%1$s` b ON b.`id` = a.`reply_to_message` AND b.`chat_id` = a.`reply_to_chat`
)
ORDER BY `id` DESC
) a
)
', ',
TB_MESSAGE, TB_MESSAGE,
$clean_older_than['message'], $clean_older_than['message'],
TB_EDITED_MESSAGE,
TB_TELEGRAM_UPDATE, TB_TELEGRAM_UPDATE,
TB_CALLBACK_QUERY TB_CALLBACK_QUERY
); );
......
...@@ -14,6 +14,8 @@ use Longman\TelegramBot\Commands\SystemCommand; ...@@ -14,6 +14,8 @@ use Longman\TelegramBot\Commands\SystemCommand;
/** /**
* Channel chat created command * Channel chat created command
*
* @todo Remove due to deprecation!
*/ */
class ChannelchatcreatedCommand extends SystemCommand class ChannelchatcreatedCommand extends SystemCommand
{ {
...@@ -43,6 +45,8 @@ class ChannelchatcreatedCommand extends SystemCommand ...@@ -43,6 +45,8 @@ class ChannelchatcreatedCommand extends SystemCommand
//$message = $this->getMessage(); //$message = $this->getMessage();
//$channel_chat_created = $message->getChannelChatCreated(); //$channel_chat_created = $message->getChannelChatCreated();
trigger_error(__CLASS__ . ' is deprecated and will be removed and handled by ' . GenericmessageCommand::class . ' by default in a future release.', E_USER_DEPRECATED);
return parent::execute(); return parent::execute();
} }
} }
...@@ -14,6 +14,8 @@ use Longman\TelegramBot\Commands\SystemCommand; ...@@ -14,6 +14,8 @@ use Longman\TelegramBot\Commands\SystemCommand;
/** /**
* Channel post command * Channel post command
*
* @todo Remove due to deprecation!
*/ */
class ChannelpostCommand extends SystemCommand class ChannelpostCommand extends SystemCommand
{ {
...@@ -42,6 +44,8 @@ class ChannelpostCommand extends SystemCommand ...@@ -42,6 +44,8 @@ class ChannelpostCommand extends SystemCommand
{ {
//$channel_post = $this->getUpdate()->getChannelPost(); //$channel_post = $this->getUpdate()->getChannelPost();
trigger_error(__CLASS__ . ' is deprecated and will be removed and handled by ' . GenericmessageCommand::class . ' by default in a future release.', E_USER_DEPRECATED);
return parent::execute(); return parent::execute();
} }
} }
...@@ -14,6 +14,8 @@ use Longman\TelegramBot\Commands\SystemCommand; ...@@ -14,6 +14,8 @@ use Longman\TelegramBot\Commands\SystemCommand;
/** /**
* Chosen inline result command * Chosen inline result command
*
* @todo Remove due to deprecation!
*/ */
class ChoseninlineresultCommand extends SystemCommand class ChoseninlineresultCommand extends SystemCommand
{ {
...@@ -45,6 +47,8 @@ class ChoseninlineresultCommand extends SystemCommand ...@@ -45,6 +47,8 @@ class ChoseninlineresultCommand extends SystemCommand
//$inline_query = $update->getChosenInlineResult(); //$inline_query = $update->getChosenInlineResult();
//$query = $inline_query->getQuery(); //$query = $inline_query->getQuery();
trigger_error(__CLASS__ . ' is deprecated and will be removed and handled by ' . GenericmessageCommand::class . ' by default in a future release.', E_USER_DEPRECATED);
return parent::execute(); return parent::execute();
} }
} }
...@@ -14,6 +14,8 @@ use Longman\TelegramBot\Commands\SystemCommand; ...@@ -14,6 +14,8 @@ use Longman\TelegramBot\Commands\SystemCommand;
/** /**
* Delete chat photo command * Delete chat photo command
*
* @todo Remove due to deprecation!
*/ */
class DeletechatphotoCommand extends SystemCommand class DeletechatphotoCommand extends SystemCommand
{ {
...@@ -43,6 +45,8 @@ class DeletechatphotoCommand extends SystemCommand ...@@ -43,6 +45,8 @@ class DeletechatphotoCommand extends SystemCommand
//$message = $this->getMessage(); //$message = $this->getMessage();
//$delete_chat_photo = $message->getDeleteChatPhoto(); //$delete_chat_photo = $message->getDeleteChatPhoto();
trigger_error(__CLASS__ . ' is deprecated and will be removed and handled by ' . GenericmessageCommand::class . ' by default in a future release.', E_USER_DEPRECATED);
return parent::execute(); return parent::execute();
} }
} }
...@@ -14,6 +14,8 @@ use Longman\TelegramBot\Commands\SystemCommand; ...@@ -14,6 +14,8 @@ use Longman\TelegramBot\Commands\SystemCommand;
/** /**
* Edited channel post command * Edited channel post command
*
* @todo Remove due to deprecation!
*/ */
class EditedchannelpostCommand extends SystemCommand class EditedchannelpostCommand extends SystemCommand
{ {
...@@ -42,6 +44,8 @@ class EditedchannelpostCommand extends SystemCommand ...@@ -42,6 +44,8 @@ class EditedchannelpostCommand extends SystemCommand
{ {
//$edited_channel_post = $this->getUpdate()->getEditedChannelPost(); //$edited_channel_post = $this->getUpdate()->getEditedChannelPost();
trigger_error(__CLASS__ . ' is deprecated and will be removed and handled by ' . GenericmessageCommand::class . ' by default in a future release.', E_USER_DEPRECATED);
return parent::execute(); return parent::execute();
} }
} }
...@@ -14,6 +14,8 @@ use Longman\TelegramBot\Commands\SystemCommand; ...@@ -14,6 +14,8 @@ use Longman\TelegramBot\Commands\SystemCommand;
/** /**
* Edited message command * Edited message command
*
* @todo Remove due to deprecation!
*/ */
class EditedmessageCommand extends SystemCommand class EditedmessageCommand extends SystemCommand
{ {
...@@ -43,6 +45,8 @@ class EditedmessageCommand extends SystemCommand ...@@ -43,6 +45,8 @@ class EditedmessageCommand extends SystemCommand
//$update = $this->getUpdate(); //$update = $this->getUpdate();
//$edited_message = $update->getEditedMessage(); //$edited_message = $update->getEditedMessage();
trigger_error(__CLASS__ . ' is deprecated and will be removed and handled by ' . GenericmessageCommand::class . ' by default in a future release.', E_USER_DEPRECATED);
return parent::execute(); return parent::execute();
} }
} }
...@@ -14,6 +14,8 @@ use Longman\TelegramBot\Commands\SystemCommand; ...@@ -14,6 +14,8 @@ use Longman\TelegramBot\Commands\SystemCommand;
/** /**
* Group chat created command * Group chat created command
*
* @todo Remove due to deprecation!
*/ */
class GroupchatcreatedCommand extends SystemCommand class GroupchatcreatedCommand extends SystemCommand
{ {
...@@ -43,6 +45,8 @@ class GroupchatcreatedCommand extends SystemCommand ...@@ -43,6 +45,8 @@ class GroupchatcreatedCommand extends SystemCommand
//$message = $this->getMessage(); //$message = $this->getMessage();
//$group_chat_created = $message->getGroupChatCreated(); //$group_chat_created = $message->getGroupChatCreated();
trigger_error(__CLASS__ . ' is deprecated and will be removed and handled by ' . GenericmessageCommand::class . ' by default in a future release.', E_USER_DEPRECATED);
return parent::execute(); return parent::execute();
} }
} }
...@@ -14,6 +14,8 @@ use Longman\TelegramBot\Commands\SystemCommand; ...@@ -14,6 +14,8 @@ use Longman\TelegramBot\Commands\SystemCommand;
/** /**
* Left chat member command * Left chat member command
*
* @todo Remove due to deprecation!
*/ */
class LeftchatmemberCommand extends SystemCommand class LeftchatmemberCommand extends SystemCommand
{ {
...@@ -43,6 +45,8 @@ class LeftchatmemberCommand extends SystemCommand ...@@ -43,6 +45,8 @@ class LeftchatmemberCommand extends SystemCommand
//$message = $this->getMessage(); //$message = $this->getMessage();
//$member = $message->getLeftChatMember(); //$member = $message->getLeftChatMember();
trigger_error(__CLASS__ . ' is deprecated and will be removed and handled by ' . GenericmessageCommand::class . ' by default in a future release.', E_USER_DEPRECATED);
return parent::execute(); return parent::execute();
} }
} }
...@@ -14,6 +14,8 @@ use Longman\TelegramBot\Commands\SystemCommand; ...@@ -14,6 +14,8 @@ use Longman\TelegramBot\Commands\SystemCommand;
/** /**
* Migrate from chat id command * Migrate from chat id command
*
* @todo Remove due to deprecation!
*/ */
class MigratefromchatidCommand extends SystemCommand class MigratefromchatidCommand extends SystemCommand
{ {
...@@ -43,6 +45,8 @@ class MigratefromchatidCommand extends SystemCommand ...@@ -43,6 +45,8 @@ class MigratefromchatidCommand extends SystemCommand
//$message = $this->getMessage(); //$message = $this->getMessage();
//$migrate_from_chat_id = $message->getMigrateFromChatId(); //$migrate_from_chat_id = $message->getMigrateFromChatId();
trigger_error(__CLASS__ . ' is deprecated and will be removed and handled by ' . GenericmessageCommand::class . ' by default in a future release.', E_USER_DEPRECATED);
return parent::execute(); return parent::execute();
} }
} }
...@@ -14,6 +14,8 @@ use Longman\TelegramBot\Commands\SystemCommand; ...@@ -14,6 +14,8 @@ use Longman\TelegramBot\Commands\SystemCommand;
/** /**
* Migrate to chat id command * Migrate to chat id command
*
* @todo Remove due to deprecation!
*/ */
class MigratetochatidCommand extends SystemCommand class MigratetochatidCommand extends SystemCommand
{ {
...@@ -43,6 +45,8 @@ class MigratetochatidCommand extends SystemCommand ...@@ -43,6 +45,8 @@ class MigratetochatidCommand extends SystemCommand
//$message = $this->getMessage(); //$message = $this->getMessage();
//$migrate_to_chat_id = $message->getMigrateToChatId(); //$migrate_to_chat_id = $message->getMigrateToChatId();
trigger_error(__CLASS__ . ' is deprecated and will be removed and handled by ' . GenericmessageCommand::class . ' by default in a future release.', E_USER_DEPRECATED);
return parent::execute(); return parent::execute();
} }
} }
...@@ -14,6 +14,8 @@ use Longman\TelegramBot\Commands\SystemCommand; ...@@ -14,6 +14,8 @@ use Longman\TelegramBot\Commands\SystemCommand;
/** /**
* New chat members command * New chat members command
*
* @todo Remove due to deprecation!
*/ */
class NewchatmembersCommand extends SystemCommand class NewchatmembersCommand extends SystemCommand
{ {
...@@ -43,6 +45,8 @@ class NewchatmembersCommand extends SystemCommand ...@@ -43,6 +45,8 @@ class NewchatmembersCommand extends SystemCommand
//$message = $this->getMessage(); //$message = $this->getMessage();
//$members = $message->getNewChatMembers(); //$members = $message->getNewChatMembers();
trigger_error(__CLASS__ . ' is deprecated and will be removed and handled by ' . GenericmessageCommand::class . ' by default in a future release.', E_USER_DEPRECATED);
return parent::execute(); return parent::execute();
} }
} }
...@@ -14,6 +14,8 @@ use Longman\TelegramBot\Commands\SystemCommand; ...@@ -14,6 +14,8 @@ use Longman\TelegramBot\Commands\SystemCommand;
/** /**
* New chat photo command * New chat photo command
*
* @todo Remove due to deprecation!
*/ */
class NewchatphotoCommand extends SystemCommand class NewchatphotoCommand extends SystemCommand
{ {
...@@ -43,6 +45,8 @@ class NewchatphotoCommand extends SystemCommand ...@@ -43,6 +45,8 @@ class NewchatphotoCommand extends SystemCommand
//$message = $this->getMessage(); //$message = $this->getMessage();
//$new_chat_photo = $message->getNewChatPhoto(); //$new_chat_photo = $message->getNewChatPhoto();
trigger_error(__CLASS__ . ' is deprecated and will be removed and handled by ' . GenericmessageCommand::class . ' by default in a future release.', E_USER_DEPRECATED);
return parent::execute(); return parent::execute();
} }
} }
...@@ -14,6 +14,8 @@ use Longman\TelegramBot\Commands\SystemCommand; ...@@ -14,6 +14,8 @@ use Longman\TelegramBot\Commands\SystemCommand;
/** /**
* New chat title command * New chat title command
*
* @todo Remove due to deprecation!
*/ */
class NewchattitleCommand extends SystemCommand class NewchattitleCommand extends SystemCommand
{ {
...@@ -43,6 +45,8 @@ class NewchattitleCommand extends SystemCommand ...@@ -43,6 +45,8 @@ class NewchattitleCommand extends SystemCommand
//$message = $this->getMessage(); //$message = $this->getMessage();
//$new_chat_title = $message->getNewChatTitle(); //$new_chat_title = $message->getNewChatTitle();
trigger_error(__CLASS__ . ' is deprecated and will be removed and handled by ' . GenericmessageCommand::class . ' by default in a future release.', E_USER_DEPRECATED);
return parent::execute(); return parent::execute();
} }
} }
...@@ -14,6 +14,8 @@ use Longman\TelegramBot\Commands\SystemCommand; ...@@ -14,6 +14,8 @@ use Longman\TelegramBot\Commands\SystemCommand;
/** /**
* Pinned message command * Pinned message command
*
* @todo Remove due to deprecation!
*/ */
class PinnedmessageCommand extends SystemCommand class PinnedmessageCommand extends SystemCommand
{ {
...@@ -43,6 +45,8 @@ class PinnedmessageCommand extends SystemCommand ...@@ -43,6 +45,8 @@ class PinnedmessageCommand extends SystemCommand
//$message = $this->getMessage(); //$message = $this->getMessage();
//$pinned_message = $message->getPinnedMessage(); //$pinned_message = $message->getPinnedMessage();
trigger_error(__CLASS__ . ' is deprecated and will be removed and handled by ' . GenericmessageCommand::class . ' by default in a future release.', E_USER_DEPRECATED);
return parent::execute(); return parent::execute();
} }
} }
...@@ -15,6 +15,8 @@ use Longman\TelegramBot\Request; ...@@ -15,6 +15,8 @@ use Longman\TelegramBot\Request;
/** /**
* Start command * Start command
*
* @todo Remove due to deprecation!
*/ */
class StartCommand extends SystemCommand class StartCommand extends SystemCommand
{ {
...@@ -50,6 +52,8 @@ class StartCommand extends SystemCommand ...@@ -50,6 +52,8 @@ class StartCommand extends SystemCommand
//$chat_id = $message->getChat()->getId(); //$chat_id = $message->getChat()->getId();
//$user_id = $message->getFrom()->getId(); //$user_id = $message->getFrom()->getId();
trigger_error(__CLASS__ . ' is deprecated and will be removed and handled by ' . GenericmessageCommand::class . ' by default in a future release.', E_USER_DEPRECATED);
return parent::execute(); return parent::execute();
} }
} }
...@@ -14,6 +14,8 @@ use Longman\TelegramBot\Commands\SystemCommand; ...@@ -14,6 +14,8 @@ use Longman\TelegramBot\Commands\SystemCommand;
/** /**
* Super group chat created command * Super group chat created command
*
* @todo Remove due to deprecation!
*/ */
class SupergroupchatcreatedCommand extends SystemCommand class SupergroupchatcreatedCommand extends SystemCommand
{ {
...@@ -43,6 +45,8 @@ class SupergroupchatcreatedCommand extends SystemCommand ...@@ -43,6 +45,8 @@ class SupergroupchatcreatedCommand extends SystemCommand
//$message = $this->getMessage(); //$message = $this->getMessage();
//$supergroup_chat_created = $message->getSuperGroupChatCreated(); //$supergroup_chat_created = $message->getSuperGroupChatCreated();
trigger_error(__CLASS__ . ' is deprecated and will be removed and handled by ' . GenericmessageCommand::class . ' by default in a future release.', E_USER_DEPRECATED);
return parent::execute(); return parent::execute();
} }
} }
...@@ -445,47 +445,36 @@ class Telegram ...@@ -445,47 +445,36 @@ class Telegram
$this->update = $update; $this->update = $update;
$this->last_update_id = $update->getUpdateId(); $this->last_update_id = $update->getUpdateId();
//Load admin commands
if ($this->isAdmin()) {
$this->addCommandsPath(TB_BASE_COMMANDS_PATH . '/AdminCommands', false);
}
//Make sure we have an up-to-date command list
//This is necessary to "require" all the necessary command files!
$this->getCommandsList();
//If all else fails, it's a generic message. //If all else fails, it's a generic message.
$command = 'genericmessage'; $command = 'genericmessage';
$update_type = $this->update->getUpdateType(); $update_type = $this->update->getUpdateType();
if ($update_type === 'message') { if ($update_type === 'message') {
$message = $this->update->getMessage(); $message = $this->update->getMessage();
//Load admin commands
if ($this->isAdmin()) {
$this->addCommandsPath(TB_BASE_COMMANDS_PATH . '/AdminCommands', false);
}
$type = $message->getType(); $type = $message->getType();
if ($type === 'command') { if ($type === 'command') {
$command = $message->getCommand(); $command = $message->getCommand();
} elseif (in_array($type, [ } else {
'new_chat_members', // Let's check if the message object has the type field we're looking for
'left_chat_member', // and if a fitting command class is available.
'new_chat_title', $command_tmp = $this->getCommandFromType($type);
'new_chat_photo', if ($this->getCommandObject($command_tmp) !== null) {
'delete_chat_photo', $command = $command_tmp;
'group_chat_created', }
'supergroup_chat_created',
'channel_chat_created',
'migrate_to_chat_id',
'migrate_from_chat_id',
'pinned_message',
'invoice',
'successful_payment',
], true)
) {
$command = $this->getCommandFromType($type);
} }
} else { } else {
$command = $this->getCommandFromType($update_type); $command = $this->getCommandFromType($update_type);
} }
//Make sure we have an up-to-date command list
//This is necessary to "require" all the necessary command files!
$this->getCommandsList();
//Make sure we don't try to process update that was already processed //Make sure we don't try to process update that was already processed
$last_id = DB::selectTelegramUpdate(1, $this->update->getUpdateId()); $last_id = DB::selectTelegramUpdate(1, $this->update->getUpdateId());
if ($last_id && count($last_id) === 1) { if ($last_id && count($last_id) === 1) {
......
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