예제 #1
0
        private async Task HandleAuthenticationMessageRequest(Message message)
        {
            if (message.Text?.Length != 36)
            {
                return;
            }

            var chatExist = await _chatsRepository.ExistsAsync(message.Chat.Id);

            if (chatExist)
            {
                await _botClient.SendTextMessageAsync(message.Chat.Id, "You are already subscribed to the updates.");

                return;
            }

            var atExists = await _accessTokenRepository.ExistsAsync(message.Text);

            if (!atExists)
            {
                await _botClient.SendTextMessageAsync(message.Chat.Id, "This token is invalid.");

                return;
            }

            var isUsed = await _accessTokenRepository.IsUsedAsync(message.Text);

            if (isUsed)
            {
                await _botClient.SendTextMessageAsync(message.Chat.Id, "This token is already used.");

                return;
            }

            await _accessTokenRepository.MakeUsedAsync(message.Text);

            await _chatsRepository.AddChatAsync(message.Chat.Id);

            await _botClient.SendTextMessageAsync(message.Chat.Id, "*Authenticated*", ParseMode.Markdown);

            await _botClient.SendTextMessageAsync(message.Chat.Id, "*I will keep you updated about good bets.*",
                                                  ParseMode.Markdown);
        }