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
- 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)`.
### Changed
- All Message field types dynamically search for an existing Command class that can handle them.
### Deprecated
- 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
### Fixed
- Constraint errors in `/cleanup` command.
- Return correct objects for requests.
### Security
......
......@@ -164,6 +164,7 @@ class CleanupCommand extends AdminCommand
SELECT `id`
FROM `%4$s`
WHERE `chat_id` = `%4$s`.`id`
AND `updated_at` < \'%1$s\'
)
AND (
`message_id` IS NOT NULL
......@@ -301,20 +302,38 @@ class CleanupCommand extends AdminCommand
if (in_array('message', $tables_to_clean, true)) {
$queries[] = sprintf(
'DELETE FROM `%1$s`
WHERE `date` < \'%2$s\'
AND `id` NOT IN (
SELECT `message_id`
FROM `%3$s`
WHERE `message_id` = `%1$s`.`id`
)
AND `id` NOT IN (
SELECT `message_id`
FROM `%4$s`
WHERE `message_id` = `%1$s`.`id`
)
WHERE id IN (
SELECT id
FROM (
SELECT id
FROM `message`
WHERE `date` < \'%2$s\'
AND `id` NOT IN (
SELECT `message_id`
FROM `%3$s`
WHERE `message_id` = `%1$s`.`id`
)
AND `id` NOT IN (
SELECT `message_id`
FROM `%4$s`
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,
$clean_older_than['message'],
TB_EDITED_MESSAGE,
TB_TELEGRAM_UPDATE,
TB_CALLBACK_QUERY
);
......
......@@ -14,6 +14,8 @@ use Longman\TelegramBot\Commands\SystemCommand;
/**
* Channel chat created command
*
* @todo Remove due to deprecation!
*/
class ChannelchatcreatedCommand extends SystemCommand
{
......@@ -43,6 +45,8 @@ class ChannelchatcreatedCommand extends SystemCommand
//$message = $this->getMessage();
//$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();
}
}
......@@ -14,6 +14,8 @@ use Longman\TelegramBot\Commands\SystemCommand;
/**
* Channel post command
*
* @todo Remove due to deprecation!
*/
class ChannelpostCommand extends SystemCommand
{
......@@ -42,6 +44,8 @@ class ChannelpostCommand extends SystemCommand
{
//$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();
}
}
......@@ -14,6 +14,8 @@ use Longman\TelegramBot\Commands\SystemCommand;
/**
* Chosen inline result command
*
* @todo Remove due to deprecation!
*/
class ChoseninlineresultCommand extends SystemCommand
{
......@@ -45,6 +47,8 @@ class ChoseninlineresultCommand extends SystemCommand
//$inline_query = $update->getChosenInlineResult();
//$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();
}
}
......@@ -14,6 +14,8 @@ use Longman\TelegramBot\Commands\SystemCommand;
/**
* Delete chat photo command
*
* @todo Remove due to deprecation!
*/
class DeletechatphotoCommand extends SystemCommand
{
......@@ -43,6 +45,8 @@ class DeletechatphotoCommand extends SystemCommand
//$message = $this->getMessage();
//$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();
}
}
......@@ -14,6 +14,8 @@ use Longman\TelegramBot\Commands\SystemCommand;
/**
* Edited channel post command
*
* @todo Remove due to deprecation!
*/
class EditedchannelpostCommand extends SystemCommand
{
......@@ -42,6 +44,8 @@ class EditedchannelpostCommand extends SystemCommand
{
//$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();
}
}
......@@ -14,6 +14,8 @@ use Longman\TelegramBot\Commands\SystemCommand;
/**
* Edited message command
*
* @todo Remove due to deprecation!
*/
class EditedmessageCommand extends SystemCommand
{
......@@ -43,6 +45,8 @@ class EditedmessageCommand extends SystemCommand
//$update = $this->getUpdate();
//$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();
}
}
......@@ -14,6 +14,8 @@ use Longman\TelegramBot\Commands\SystemCommand;
/**
* Group chat created command
*
* @todo Remove due to deprecation!
*/
class GroupchatcreatedCommand extends SystemCommand
{
......@@ -43,6 +45,8 @@ class GroupchatcreatedCommand extends SystemCommand
//$message = $this->getMessage();
//$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();
}
}
......@@ -14,6 +14,8 @@ use Longman\TelegramBot\Commands\SystemCommand;
/**
* Left chat member command
*
* @todo Remove due to deprecation!
*/
class LeftchatmemberCommand extends SystemCommand
{
......@@ -43,6 +45,8 @@ class LeftchatmemberCommand extends SystemCommand
//$message = $this->getMessage();
//$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();
}
}
......@@ -14,6 +14,8 @@ use Longman\TelegramBot\Commands\SystemCommand;
/**
* Migrate from chat id command
*
* @todo Remove due to deprecation!
*/
class MigratefromchatidCommand extends SystemCommand
{
......@@ -43,6 +45,8 @@ class MigratefromchatidCommand extends SystemCommand
//$message = $this->getMessage();
//$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();
}
}
......@@ -14,6 +14,8 @@ use Longman\TelegramBot\Commands\SystemCommand;
/**
* Migrate to chat id command
*
* @todo Remove due to deprecation!
*/
class MigratetochatidCommand extends SystemCommand
{
......@@ -43,6 +45,8 @@ class MigratetochatidCommand extends SystemCommand
//$message = $this->getMessage();
//$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();
}
}
......@@ -14,6 +14,8 @@ use Longman\TelegramBot\Commands\SystemCommand;
/**
* New chat members command
*
* @todo Remove due to deprecation!
*/
class NewchatmembersCommand extends SystemCommand
{
......@@ -43,6 +45,8 @@ class NewchatmembersCommand extends SystemCommand
//$message = $this->getMessage();
//$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();
}
}
......@@ -14,6 +14,8 @@ use Longman\TelegramBot\Commands\SystemCommand;
/**
* New chat photo command
*
* @todo Remove due to deprecation!
*/
class NewchatphotoCommand extends SystemCommand
{
......@@ -43,6 +45,8 @@ class NewchatphotoCommand extends SystemCommand
//$message = $this->getMessage();
//$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();
}
}
......@@ -14,6 +14,8 @@ use Longman\TelegramBot\Commands\SystemCommand;
/**
* New chat title command
*
* @todo Remove due to deprecation!
*/
class NewchattitleCommand extends SystemCommand
{
......@@ -43,6 +45,8 @@ class NewchattitleCommand extends SystemCommand
//$message = $this->getMessage();
//$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();
}
}
......@@ -14,6 +14,8 @@ use Longman\TelegramBot\Commands\SystemCommand;
/**
* Pinned message command
*
* @todo Remove due to deprecation!
*/
class PinnedmessageCommand extends SystemCommand
{
......@@ -43,6 +45,8 @@ class PinnedmessageCommand extends SystemCommand
//$message = $this->getMessage();
//$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();
}
}
......@@ -15,6 +15,8 @@ use Longman\TelegramBot\Request;
/**
* Start command
*
* @todo Remove due to deprecation!
*/
class StartCommand extends SystemCommand
{
......@@ -50,6 +52,8 @@ class StartCommand extends SystemCommand
//$chat_id = $message->getChat()->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();
}
}
......@@ -14,6 +14,8 @@ use Longman\TelegramBot\Commands\SystemCommand;
/**
* Super group chat created command
*
* @todo Remove due to deprecation!
*/
class SupergroupchatcreatedCommand extends SystemCommand
{
......@@ -43,6 +45,8 @@ class SupergroupchatcreatedCommand extends SystemCommand
//$message = $this->getMessage();
//$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();
}
}
......@@ -445,47 +445,36 @@ class Telegram
$this->update = $update;
$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.
$command = 'genericmessage';
$update_type = $this->update->getUpdateType();
if ($update_type === 'message') {
$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') {
$command = $message->getCommand();
} elseif (in_array($type, [
'new_chat_members',
'left_chat_member',
'new_chat_title',
'new_chat_photo',
'delete_chat_photo',
'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 {
// Let's check if the message object has the type field we're looking for
// and if a fitting command class is available.
$command_tmp = $this->getCommandFromType($type);
if ($this->getCommandObject($command_tmp) !== null) {
$command = $command_tmp;
}
}
} else {
$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
$last_id = DB::selectTelegramUpdate(1, $this->update->getUpdateId());
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