protected override async Task <bool?> ProcessMessage(Func <Message, PollMessage, IDictionary <string, string>, CancellationToken, Task <bool?> > processor, Message message, CancellationToken cancellationToken = default) { var pollMessage = new PollMessage(message); var result = await processor(message, pollMessage, pollMessage.GetTrackingProperties(), cancellationToken); if (result is bool success) { if (success) { if (pollMessage.Poll is {} poll&& string.IsNullOrEmpty(poll.Title) && myCache.TryGetValue <Message>(message.Chat.Id, out var prevMessage) && (prevMessage.From?.Id == message.From?.Id)) { poll.Title = prevMessage.Text; myCache.Remove(message.Chat.Id); } switch (pollMessage.Poll?.Raid) { // regular pokemons in private chat case Raid raid when raid.RaidBossLevel == null && message.Chat?.Type == ChatType.Private: goto case null; // raid pokemons everywhere case Raid raid when raid.RaidBossLevel != null: goto case null; // polls without raids case null: await myRaidService.AddPollMessage(pollMessage, myUrlHelper, cancellationToken, withLog : true); break; } } } else if ((message.ForwardFrom == null) && (message.ForwardFromChat == null) && (message.Type == MessageType.Text) && ((message.Entities?.Length).GetValueOrDefault() == 0)) { myCache.Set(message.Chat.Id, message, TimeSpan.FromSeconds(15)); } return(result); }
public async Task <(string, bool, string)> Handle(CallbackQuery data, object context = default, CancellationToken cancellationToken = default) { var callback = data.Data.Split(':'); if (callback[0] != "clone") { return(null, false, null); } if (!int.TryParse(callback.ElementAtOrDefault(1) ?? "", NumberStyles.Integer, CultureInfo.InvariantCulture, out var pollId)) { return("Poll is publishing. Try later.", true, null); } var poll = await myContext .Set <Poll>() .Where(_ => _.Id == pollId) .IncludeRelatedData() .FirstOrDefaultAsync(cancellationToken); if (poll == null) { return("Poll is not found", true, null); } var pollMessage = new PollMessage { ChatId = data.From.Id, ChatType = ChatType.Private, UserId = data.From.Id, InlineMesssageId = data.InlineMessageId, Poll = poll }; await myRaidService.AddPollMessage(pollMessage, myUrlHelper, cancellationToken); var botUser = await myBot.GetMeAsync(cancellationToken); return(null, false, $"https://t.me/{botUser.Username}?start={pollMessage.GetExtendedPollId()}"); }