Fix sending bot commands in paid chats.

This commit is contained in:
John Preston 2025-03-05 18:02:40 +04:00
parent 940455f786
commit d43a6da62b
4 changed files with 51 additions and 3 deletions

View file

@ -4917,13 +4917,32 @@ void HistoryWidget::mouseReleaseEvent(QMouseEvent *e) {
}
void HistoryWidget::sendBotCommand(const Bot::SendCommandRequest &request) {
// replyTo != 0 from ReplyKeyboardMarkup, == 0 from command links
sendBotCommand(request, {});
}
void HistoryWidget::sendBotCommand(
const Bot::SendCommandRequest &request,
Api::SendOptions options) {
// replyTo != 0 from ReplyKeyboardMarkup, == 0 from command links
if (_peer != request.peer.get()) {
return;
} else if (showSlowmodeError()) {
return;
}
const auto withPaymentApproved = [=](int approved) {
auto copy = options;
copy.starsApproved = approved;
sendBotCommand(request, copy);
};
const auto checked = checkSendPayment(
1,
options.starsApproved,
withPaymentApproved);
if (!checked) {
return;
}
const auto forMsgId = _keyboard->forMsgId();
const auto lastKeyboardUsed = (forMsgId == request.replyTo.messageId)
&& (forMsgId == FullMsgId(_peer->id, _history->lastKeyboardId));
@ -4933,7 +4952,7 @@ void HistoryWidget::sendBotCommand(const Bot::SendCommandRequest &request) {
? request.command
: Bot::WrapCommandInChat(_peer, request.command, request.context);
auto message = Api::MessageToSend(prepareSendAction({}));
auto message = Api::MessageToSend(prepareSendAction(options));
message.textWithTags = { toSend, TextWithTags::Tags() };
message.action.replyTo = request.replyTo
? ((!_peer->isUser()/* && (botStatus == 0 || botStatus == 2)*/)

View file

@ -491,6 +491,10 @@ private:
std::shared_ptr<Ui::PreparedBundle> bundle,
Api::SendOptions options);
void sendBotCommand(
const Bot::SendCommandRequest &request,
Api::SendOptions options);
void uploadFile(const QByteArray &fileContent, SendMediaType type);
void itemRemoved(not_null<const HistoryItem*> item);

View file

@ -2724,11 +2724,31 @@ bool RepliesWidget::listIsGoodForAroundPosition(
void RepliesWidget::listSendBotCommand(
const QString &command,
const FullMsgId &context) {
sendBotCommandWithOptions(command, context, {});
}
void RepliesWidget::sendBotCommandWithOptions(
const QString &command,
const FullMsgId &context,
Api::SendOptions options) {
const auto withPaymentApproved = [=](int approved) {
auto copy = options;
copy.starsApproved = approved;
sendBotCommandWithOptions(command, context, copy);
};
const auto checked = checkSendPayment(
1,
options.starsApproved,
withPaymentApproved);
if (!checked) {
return;
}
const auto text = Bot::WrapCommandInChat(
_history->peer,
command,
context);
auto message = Api::MessageToSend(prepareSendAction({}));
auto message = Api::MessageToSend(prepareSendAction(options));
message.textWithTags = { text };
session().api().sendMessage(std::move(message));
finishSending();

View file

@ -319,6 +319,11 @@ private:
std::shared_ptr<Ui::PreparedBundle> bundle,
Api::SendOptions options);
void sendBotCommandWithOptions(
const QString &command,
const FullMsgId &context,
Api::SendOptions options);
bool sendExistingDocument(
not_null<DocumentData*> document,
Api::MessageToSend messageToSend,