public Task <bool> IsMatch(Update update)
        {
            if (update.Type != UpdateType.CallbackQuery)
            {
                return(Task.FromResult(false));
            }

            Message message = update.CallbackQuery.Message;

            return(Task.FromResult(!PollsHelper.HasPoll(message.Chat.Id) ||
                                   PollsHelper.GetPoll(message.Chat.Id).MessageId != message.MessageId));
        }
        public async Task Do()
        {
            var polls = PollsHelper.Polls;

            foreach (var poll in polls.Values)
            {
                _logger.LogInformation($"Finish Battle Operation, chatId: {poll.ChatId.ToString()}");

                await _botService.Client.DeleteMessageAsync(
                    chatId : poll.ChatId,
                    messageId : poll.MessageId);
            }
            PollsHelper.RemovePolls();
        }
        public async Task ProcessAsync(Update update)
        {
            _logger.LogInformation($"Processing /poll message..., chatId: {update.Message.Chat.Id.ToString()}");

            if (PollsHelper.HasPoll(update.Message.Chat.Id))
            {
                var poll = PollsHelper.GetPoll(update.Message.Chat.Id);
                var text = $"⇧ <a href='https://t.me/c/{poll.ChatId.ToString().Substring(4)}/{poll.MessageId.ToString()}'>К голосованию</a> ⇧";
                await _botService.Client.SendTextMessageAsync(
                    chatId : poll.ChatId,
                    text : text,
                    parseMode : ParseMode.Html);
            }
            else
            {
                await _botService.Client.SendTextMessageAsync(
                    chatId : update.Message.Chat.Id,
                    text : "Голосования ещё нет");
            }
        }
        public async Task ProcessAsync(Update update)
        {
            _logger.LogInformation($"Processing /pin message..., chatId: {update.Message.Chat.Id.ToString()}");

            if (PollsHelper.HasPoll(update.Message.Chat.Id))
            {
                var poll         = PollsHelper.GetPoll(update.Message.Chat.Id);
                var pressPinText = $"{poll.Pin.Type}{poll.Pin.Company.Logo} Прожимаемся в 📌<a href='{poll.Pin.LinkToMessage}'>пин</a>";
                await _botService.Client.SendTextMessageAsync(
                    chatId : poll.ChatId,
                    text : pressPinText,
                    parseMode : ParseMode.Html);
            }
            else
            {
                await _botService.Client.SendTextMessageAsync(
                    chatId : update.Message.Chat.Id,
                    text : "Пина на битву ещё нет");
            }
        }
Exemplo n.º 5
0
        public async Task ProcessAsync(Update update)
        {
            _logger.LogInformation($"[ {DateTime.Now.ToLocalTime().ToString(CultureInfo.InvariantCulture)} ] Processing . message... , chatId: {update.Message.Chat.Id.ToString()}, {update.Message.From.Username}");

            Pin pin = new Pin(update.Message.ReplyToMessage);

            if (pin.IsActual())
            {
                Poll poll;

                if (PollsHelper.HasPoll(update.Message.Chat.Id))
                {
                    poll = PollsHelper.GetPoll(update.Message.Chat.Id);
                    await _botService.Client.DeleteMessageAsync(
                        chatId : poll.ChatId,
                        messageId : poll.MessageId);

                    PollsHelper.UpdatePoll(poll.ChatId, pin);
                }
                else
                {
                    poll = PollsHelper.CreatePoll(update.Message.Chat.Id, pin);
                }

                PollView pollView = poll.AsView();

                var message = await _botService.Client.SendTextMessageAsync(
                    chatId : update.Message.Chat.Id,
                    text : pollView.Text,
                    parseMode : ParseMode.Html,
                    replyMarkup : pollView.ReplyMarkup);

                poll.ChatId    = message.Chat.Id;
                poll.MessageId = message.MessageId;
            }

            await _botService.Client.DeleteMessageAsync(
                chatId : update.Message.Chat.Id,
                messageId : update.Message.MessageId);
        }
Exemplo n.º 6
0
        public async Task ProcessAsync(Update update)
        {
            _logger.LogInformation($"[ {DateTime.Now.ToLocalTime().ToString(CultureInfo.InvariantCulture)} ] Processing sleep callback... {update.CallbackQuery.From.Username}, chatId: {update.CallbackQuery.Message.Chat.Id.ToString()}");

            Poll     poll            = PollsHelper.GetPoll(update.CallbackQuery.Message.Chat.Id);
            bool     userListUpdated = poll.AddSleepVote(update.CallbackQuery.From);
            PollView pollView        = poll.AsView();

            if (userListUpdated)
            {
                await PollVoteThrottle.Acquire();

                await _botService.Client.EditMessageTextAsync(
                    chatId : poll.ChatId,
                    messageId : poll.MessageId,
                    text : pollView.Text,
                    parseMode : ParseMode.Html,
                    replyMarkup : pollView.ReplyMarkup);
            }

            await _botService.Client.AnswerCallbackQueryAsync(
                callbackQueryId : update.CallbackQuery.Id,
                text : pollView.SleepCallbackQueryAnswer);
        }