Exemplo n.º 1
0
    public static async Task <bool> OnUpdatePreTaskAsync(this TelegramService telegramService)
    {
        var op = Operation.Begin("Run PreTask for ChatId: {ChatId}", telegramService.ChatId);

        if (telegramService.IsUpdateTooOld())
        {
            return(false);
        }

        var hasRestricted = await telegramService.CheckChatRestriction();

        if (hasRestricted)
        {
            return(false);
        }

        var floodCheck = await telegramService.FloodCheckAsync();

        if (floodCheck.IsFlood)
        {
            return(false);
        }

        var featureConfig = await telegramService.GetFeatureConfig();

        if (!featureConfig.NextHandler)
        {
            return(false);
        }

        await telegramService.FireAnalyzer();

        var checkUpdateHistory = await telegramService.CheckUpdateHistoryAsync();

        if (checkUpdateHistory)
        {
            return(false);
        }

        if (!await telegramService.AnswerChatJoinRequestAsync())
        {
            return(false);
        }

        var checkAntiSpamResult = await telegramService.AntiSpamCheckAsync();

        if (checkAntiSpamResult.IsAnyBanned)
        {
            return(false);
        }

        var checkScanMessageTask      = telegramService.ScanMessageAsync();
        var userUsernameTask          = telegramService.RunCheckUserUsername();
        var checkUserProfilePhotoTask = telegramService.RunCheckUserProfilePhoto();

        await Task.WhenAll(
            checkScanMessageTask,
            userUsernameTask,
            checkUserProfilePhotoTask
            );

        if (!await userUsernameTask)
        {
            return(false);
        }

        if (!await checkUserProfilePhotoTask)
        {
            return(false);
        }

        if (await checkScanMessageTask)
        {
            return(false);
        }

        op.Complete();

        return(true);
    }