public override async Task HandleAsync(IUpdateContext context, UpdateDelegate next, string[] args,
                                               CancellationToken cancellationToken)
        {
            var msg    = context.Update.Message;
            var chatId = msg.Chat.Id;
            var fromId = msg.From.Id;

            _chatProcessor          = new ChatProcessor(context);
            _elasticSecurityService = new ElasticSecurityService(msg);

            if (fromId.IsSudoer())
            {
                if (msg.ReplyToMessage != null)
                {
                    var repMsg = msg.ReplyToMessage;
                    var userId = repMsg.From.Id;

                    ConsoleHelper.WriteLine("Execute Global DelBan");
                    await _chatProcessor.SendAsync("Mempersiapkan..");

                    await _chatProcessor.DeleteAsync(msg.MessageId);

                    var isBan = await _elasticSecurityService.IsExist(userId);

                    ConsoleHelper.WriteLine($"IsBan: {isBan}");
                    if (isBan)
                    {
                        await _chatProcessor.EditAsync("Memperbarui informasi..");

                        var save = await _elasticSecurityService.DeleteBanAsync(userId);

                        ConsoleHelper.WriteLine($"SaveBan: {save}");

                        await _chatProcessor.EditAsync("Menulis ke Cache..");

                        await _elasticSecurityService.UpdateCacheAsync();

                        await _chatProcessor.EditAsync("Misi berhasil.");
                    }
                    else
                    {
                        await _chatProcessor.EditAsync("Pengguna tidak di ban");
                    }
                }
                else
                {
                    await _chatProcessor.SendAsync("Balas seseorang yang mau di ban");
                }
            }
            else
            {
                await _chatProcessor.SendAsync("Unauthorized");
            }

            await _chatProcessor.DeleteAsync(delay : 3000);
        }
        public override async Task HandleAsync(IUpdateContext context, UpdateDelegate next, string[] args,
                                               CancellationToken cancellationToken)
        {
            Message msg = context.Update.Message;

            _chatProcessor   = new ChatProcessor(context);
            _settingsService = new SettingsService(msg);

            var id       = msg.From.Id;
            var sendText = "Under maintenance";

            ConsoleHelper.WriteLine(id.IsSudoer());

            await _chatProcessor.DeleteAsync(msg.MessageId);

            await _chatProcessor.SendAsync("🔄 Loading tags..");

            var tagsData = await _tagsService.GetTagsByGroupAsync("*", msg.Chat.Id);

            var tagsStr = string.Empty;

            foreach (var tag in tagsData)
            {
                tagsStr += $"#{tag.Tag} ";
            }

            sendText = $"#️⃣<b> {tagsData.Count} Tags</b>\n" +
                       $"\n{tagsStr}";

            await _chatProcessor.EditAsync(sendText);

            //            var jsonSettings = TextHelper.ToJson(currentSetting);
            //            ConsoleHelper.WriteLine($"CurrentSettings: {jsonSettings}");

            // var lastTagsMsgId = int.Parse(currentSetting.Rows[0]["last_tags_message_id"].ToString());

            var currentSetting = await _settingsService.GetSettingByGroup();

            var lastTagsMsgId = currentSetting.LastTagsMessageId;

            ConsoleHelper.WriteLine($"LastTagsMsgId: {lastTagsMsgId}");

            await _chatProcessor.DeleteAsync(lastTagsMsgId.ToInt());

            await _tagsService.UpdateCacheAsync(msg);

            ConsoleHelper.WriteLine(_chatProcessor.SentMessageId);
            await _settingsService.UpdateCell("last_tags_message_id", _chatProcessor.SentMessageId);


//            var json = TextHelper.ToJson(tagsData);
            //                Console.WriteLine(json);
        }
        public async Task HandleAsync(IUpdateContext context, UpdateDelegate next, CancellationToken cancellationToken)
        {
            _chatProcessor = new ChatProcessor(context);
            var msg = context.Update.Message;

            ConsoleHelper.WriteLine("Media received... ");
            var isBan = await _mediaFilterService.IsExistInCache("file_id", msg.GetReducedFileId());

//            var isBan = await _mediaFilterService.IsExist("file_id", msg.GetReducedFileId());
            if (isBan)
            {
                await _chatProcessor.DeleteAsync(msg.MessageId);
            }

            ConsoleHelper.WriteLine($"Media isBan: {isBan}");

            if (Bot.HostingEnvironment.IsProduction())
            {
                await _mediaFilterService.UpdateCacheAsync();
            }
            else
            {
                ConsoleHelper.WriteLine($"Update cache skipped because local Env");
            }

            ConsoleHelper.WriteLine("Media Filter complete.");

            await next(context);
        }
Example #4
0
        public override async Task HandleAsync(IUpdateContext context, UpdateDelegate next, string[] args, CancellationToken cancellationToken)
        {
            _chatProcessor = new ChatProcessor(context);

            var kickTargets = new List <User>();

            var     msg    = context.Update.Message;
            Message repMsg = null;
            var     fromId = msg.From.Id;

            // var idTargets = new List<int>();

            kickTargets.Add(msg.From);

            if (msg.ReplyToMessage != null)
            {
                repMsg = msg.ReplyToMessage;
                // idTarget = repMsg.From.id;
                kickTargets.Add(repMsg.From);

                if (repMsg.NewChatMembers != null)
                {
                    kickTargets.Clear();
                    var userTargets = repMsg.NewChatMembers;
                    kickTargets.AddRange(userTargets);

                    // foreach (var target in userTargets)
                    // {
                    //     idTargets.Add(target.Id);
                    // }
                }
            }

            await _chatProcessor.DeleteAsync(msg.MessageId);

            var isAdmin = await _chatProcessor.IsAdminGroup();

            if (kickTargets[0].Id != msg.From.Id && isAdmin)
            {
                var isKicked = false;
                foreach (var target in kickTargets)
                {
                    var idTarget = target.Id;
                    var sendText = string.Empty;

                    // await _chatProcessor.AppendTextAsync($"Sedang menendang {idTarget}");
                    isKicked = await _chatProcessor.KickMemberAsync(target);

                    await _chatProcessor.UnbanMemberAsync(target);

                    if (isKicked)
                    {
                        sendText = $"{target} berhasil di tendank ";

                        sendText += idTarget == fromId ? $"oleh Self-kick" : $".";
                    }
                    else
                    {
                        sendText = $"Gagal menendang {idTarget}";
                    }

                    await _chatProcessor.AppendTextAsync(sendText);
                }

                if (isKicked)
                {
                    await _chatProcessor.AppendTextAsync($"Sebanyak {kickTargets.Count} berhasil di tendang.");
                }
                else
                {
                    await _chatProcessor.AppendTextAsync("Gagal menendang bbrp anggota");
                }
            }
            else if (kickTargets[0].Id == fromId)
            {
                var idTarget = kickTargets[0];
                var isKicked = false;
                // await _chatProcessor.AppendTextAsync($"Sedang menendang {idTarget}");
                isKicked = await _chatProcessor.KickMemberAsync(idTarget);

                if (isKicked)
                {
                    var sendText = $"{idTarget} berhasil di tendang ";
                    sendText += idTarget.Id == fromId ? $"oleh Self-kick" : $".";
                    await _chatProcessor.AppendTextAsync(sendText);
                }
                else
                {
                    var sendTexts = $"Tendang {idTarget} gagal.";
                    await _chatProcessor.SendAsync(sendTexts);
                }
            }
            else
            {
                await _chatProcessor.SendAsync("Hanya admin yang bisa mengeksekusi");
            }
        }