mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Fix sending bot commands in paid chats.
This commit is contained in:
parent
940455f786
commit
d43a6da62b
4 changed files with 51 additions and 3 deletions
|
@ -4917,13 +4917,32 @@ void HistoryWidget::mouseReleaseEvent(QMouseEvent *e) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void HistoryWidget::sendBotCommand(const Bot::SendCommandRequest &request) {
|
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()) {
|
if (_peer != request.peer.get()) {
|
||||||
return;
|
return;
|
||||||
} else if (showSlowmodeError()) {
|
} else if (showSlowmodeError()) {
|
||||||
return;
|
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 forMsgId = _keyboard->forMsgId();
|
||||||
const auto lastKeyboardUsed = (forMsgId == request.replyTo.messageId)
|
const auto lastKeyboardUsed = (forMsgId == request.replyTo.messageId)
|
||||||
&& (forMsgId == FullMsgId(_peer->id, _history->lastKeyboardId));
|
&& (forMsgId == FullMsgId(_peer->id, _history->lastKeyboardId));
|
||||||
|
@ -4933,7 +4952,7 @@ void HistoryWidget::sendBotCommand(const Bot::SendCommandRequest &request) {
|
||||||
? request.command
|
? request.command
|
||||||
: Bot::WrapCommandInChat(_peer, request.command, request.context);
|
: Bot::WrapCommandInChat(_peer, request.command, request.context);
|
||||||
|
|
||||||
auto message = Api::MessageToSend(prepareSendAction({}));
|
auto message = Api::MessageToSend(prepareSendAction(options));
|
||||||
message.textWithTags = { toSend, TextWithTags::Tags() };
|
message.textWithTags = { toSend, TextWithTags::Tags() };
|
||||||
message.action.replyTo = request.replyTo
|
message.action.replyTo = request.replyTo
|
||||||
? ((!_peer->isUser()/* && (botStatus == 0 || botStatus == 2)*/)
|
? ((!_peer->isUser()/* && (botStatus == 0 || botStatus == 2)*/)
|
||||||
|
|
|
@ -491,6 +491,10 @@ private:
|
||||||
std::shared_ptr<Ui::PreparedBundle> bundle,
|
std::shared_ptr<Ui::PreparedBundle> bundle,
|
||||||
Api::SendOptions options);
|
Api::SendOptions options);
|
||||||
|
|
||||||
|
void sendBotCommand(
|
||||||
|
const Bot::SendCommandRequest &request,
|
||||||
|
Api::SendOptions options);
|
||||||
|
|
||||||
void uploadFile(const QByteArray &fileContent, SendMediaType type);
|
void uploadFile(const QByteArray &fileContent, SendMediaType type);
|
||||||
void itemRemoved(not_null<const HistoryItem*> item);
|
void itemRemoved(not_null<const HistoryItem*> item);
|
||||||
|
|
||||||
|
|
|
@ -2724,11 +2724,31 @@ bool RepliesWidget::listIsGoodForAroundPosition(
|
||||||
void RepliesWidget::listSendBotCommand(
|
void RepliesWidget::listSendBotCommand(
|
||||||
const QString &command,
|
const QString &command,
|
||||||
const FullMsgId &context) {
|
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(
|
const auto text = Bot::WrapCommandInChat(
|
||||||
_history->peer,
|
_history->peer,
|
||||||
command,
|
command,
|
||||||
context);
|
context);
|
||||||
auto message = Api::MessageToSend(prepareSendAction({}));
|
auto message = Api::MessageToSend(prepareSendAction(options));
|
||||||
message.textWithTags = { text };
|
message.textWithTags = { text };
|
||||||
session().api().sendMessage(std::move(message));
|
session().api().sendMessage(std::move(message));
|
||||||
finishSending();
|
finishSending();
|
||||||
|
|
|
@ -319,6 +319,11 @@ private:
|
||||||
std::shared_ptr<Ui::PreparedBundle> bundle,
|
std::shared_ptr<Ui::PreparedBundle> bundle,
|
||||||
Api::SendOptions options);
|
Api::SendOptions options);
|
||||||
|
|
||||||
|
void sendBotCommandWithOptions(
|
||||||
|
const QString &command,
|
||||||
|
const FullMsgId &context,
|
||||||
|
Api::SendOptions options);
|
||||||
|
|
||||||
bool sendExistingDocument(
|
bool sendExistingDocument(
|
||||||
not_null<DocumentData*> document,
|
not_null<DocumentData*> document,
|
||||||
Api::MessageToSend messageToSend,
|
Api::MessageToSend messageToSend,
|
||||||
|
|
Loading…
Add table
Reference in a new issue