MCPcopy Create free account
hub / github.com/TDesktop-x64/tdesktop / SendDice

Function SendDice

Telegram/SourceFiles/api/api_sending.cpp:347–493  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

345}
346
347bool SendDice(MessageToSend &message) {
348 const auto full = QStringView(message.textWithTags.text).trimmed();
349 auto length = 0;
350 if (!Ui::Emoji::Find(full.data(), full.data() + full.size(), &length)
351 || length != full.size()
352 || !message.textWithTags.tags.isEmpty()) {
353 return false;
354 }
355 auto &config = message.action.history->session().appConfig();
356 static const auto hardcoded = std::vector<QString>{
357 Stickers::DicePacks::kDiceString,
358 Stickers::DicePacks::kDartString,
359 Stickers::DicePacks::kSlotString,
360 Stickers::DicePacks::kFballString,
361 Stickers::DicePacks::kFballString + QChar(0xFE0F),
362 Stickers::DicePacks::kBballString,
363 };
364 const auto list = config.get<std::vector<QString>>(
365 "emojies_send_dice",
366 hardcoded);
367 const auto emoji = full.toString();
368 if (!ranges::contains(list, emoji)) {
369 return false;
370 }
371 const auto history = message.action.history;
372 const auto peer = history->peer;
373 const auto session = &history->session();
374 const auto api = &session->api();
375
376 message.textWithTags = TextWithTags();
377 message.action.clearDraft = false;
378 message.action.generateLocal = true;
379
380 auto &action = message.action;
381 api->sendAction(action);
382
383 const auto newId = FullMsgId(
384 peer->id,
385 session->data().nextLocalMessageId());
386 const auto randomId = base::RandomValue<uint64>();
387
388 auto &histories = history->owner().histories();
389 auto flags = NewMessageFlags(peer);
390 auto sendFlags = MTPmessages_SendMedia::Flags(0);
391 if (action.replyTo) {
392 flags |= MessageFlag::HasReplyInfo;
393 sendFlags |= MTPmessages_SendMedia::Flag::f_reply_to;
394 }
395 const auto silentPost = ShouldSendSilent(peer, action.options);
396 InnerFillMessagePostFlags(action.options, peer, flags);
397 if (silentPost) {
398 sendFlags |= MTPmessages_SendMedia::Flag::f_silent;
399 }
400 const auto sendAs = action.options.sendAs;
401 if (sendAs) {
402 sendFlags |= MTPmessages_SendMedia::Flag::f_send_as;
403 }
404 if (action.options.scheduled) {

Callers 2

sendMessageMethod · 0.85
MakeHandlerMethod · 0.85

Calls 15

NewMessageFlagsFunction · 0.85
ShouldSendSilentFunction · 0.85
QByteArrayClass · 0.85
NewMessageFromIdFunction · 0.85
NewMessageDateFunction · 0.85
NewMessagePostAuthorFunction · 0.85
TextWithEntitiesClass · 0.85
MTP_flagsFunction · 0.85
MTP_stringFunction · 0.85
MTP_bytesFunction · 0.85

Tested by

no test coverage detected