コード例 #1
0
    public async Task <NewChatMembers> CheckNewChatMembers(
        long chatId,
        User[] users,
        Func <CallbackAnswer, Task <CallbackResult> > funcCallbackAnswer
        )
    {
        _chatSetting = await _settingsService.GetSettingsByGroup(chatId);

        var newChatMembers = new NewChatMembers
        {
            AllNewChatMembers = users.AsEnumerable()
        };

        _logger.LogDebug("Parsing new {Length} members..", users.Length);
        foreach (var user in users)
        {
            var callbackAnswerParam = new CallbackAnswer();
            var userId = user.Id;

            var banResult = await _antiSpamService.CheckSpam(chatId, userId);

            callbackAnswerParam.TargetUserId = userId;

            if (banResult.IsAnyBanned)
            {
                newChatMembers.NewKickedChatMembers.Add(user);
                callbackAnswerParam.CallbackAnswerModes.Add(CallbackAnswerMode.KickMember);
            }
            else
            {
                if (_chatSetting.EnableHumanVerification)
                {
                    newChatMembers.NewPassedChatMembers.Add(user);
                    callbackAnswerParam.CallbackAnswerModes.Add(CallbackAnswerMode.MuteMember);
                    callbackAnswerParam.CallbackAnswerModes.Add(CallbackAnswerMode.ScheduleKickMember);
                }

                newChatMembers.NewPassedChatMembers.Add(user);
            }

            await funcCallbackAnswer(callbackAnswerParam);
        }

        newChatMembers.AllNewChatMembersStr    = users.Select(user => user.GetNameLink());
        newChatMembers.NewPassedChatMembersStr = newChatMembers.NewPassedChatMembers.Select(user => user.GetNameLink());

        newChatMembers.NewNoUsernameChatMembers    = users.Where(user => user.Username.IsNullOrEmpty());
        newChatMembers.NewNoUsernameChatMembersStr = newChatMembers.NewNoUsernameChatMembers.Select(user => user.GetNameLink());

        newChatMembers.NewBotChatMembers    = users.Where(user => user.IsBot);
        newChatMembers.NewBotChatMembersStr = newChatMembers.NewBotChatMembers.Select(user => user.GetNameLink());

        return(newChatMembers);
    }
コード例 #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="fromId"></param>
        /// <param name="funcAntiSpamResult"></param>
        /// <returns></returns>
        public async Task <AntiSpamResult> CheckAntiSpam(
            long chatId,
            long fromId,
            Func <AntiSpamResult, Task> funcAntiSpamResult
            )
        {
            var result = await _antiSpamService.CheckSpam(chatId, fromId);

            await funcAntiSpamResult(result);

            return(result);
        }
コード例 #3
0
        /// <summary>
        /// Check the anti spam
        /// </summary>
        /// <returns>The check anti spam</returns>
        private async Task <AntiSpamResult> CheckAntiSpam()
        {
            var checkAntiSpam = await _antiSpamService.CheckSpam(
                Chat.Id,
                From.Id,
                async result => {
                var userId = result.UserId;

                if (result.IsAnyBanned)
                {
                    _logger.LogDebug("Kicking User Id '{UserId}' because FBan", userId);
                    await Bot.KickChatMemberAsync(Chat.Id, userId);
                }
            }
                );

            return(checkAntiSpam);
        }
コード例 #4
0
    public async Task HandleAsync(
        IUpdateContext context,
        UpdateDelegate next,
        CancellationToken cancellationToken
        )
    {
        await _telegramService.AddUpdateContext(context);

        var chatId    = _telegramService.ChatId;
        var chatTitle = _telegramService.ChatTitle;

        var msg        = _telegramService.Message;
        var leftMember = msg.LeftChatMember;

        if (leftMember == null)
        {
            return;
        }

        var leftUserId = leftMember.Id;
        var checkSpam  = await _antiSpamService.CheckSpam(chatId, leftUserId);

        if (checkSpam.IsAnyBanned)
        {
            Log.Information("Left Message ignored because {LeftMember} is Global Banned", leftMember);
            return;
        }

        Log.Information("Left Chat Members...");

        var leftFullName = leftMember.FirstName;

        var sendText = $"Sampai jumpa lagi {leftFullName} " +
                       $"\nKami di <b>{chatTitle}</b> menunggumu kembali.. :(";

        await _telegramService.SendTextMessageAsync(sendText, replyToMsgId : 0);
    }
コード例 #5
0
        private async Task <List <User> > ScanMembersAsync(
            long chatId,
            User[] users
            )
        {
            var members = new List <User>();

            foreach (var user in users)
            {
                var userId        = user.Id;
                var checkAntiSpam = await _antiSpamService.CheckSpam(
                    chatId,
                    userId,
                    FuncAntiSpamResult
                    );

                if (!checkAntiSpam.IsAnyBanned)
                {
                    members.Add(user);
                }
            }

            return(members);
        }