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)
        {
            chatProcessor = new ChatProcessor(context);

            await chatProcessor.SendAsync("Migrate starting..");

            Thread.Sleep(3000);

            await chatProcessor.EditAsync("Migrate finish..");
        }
        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 override async Task HandleAsync(IUpdateContext context, UpdateDelegate next, string[] args,
                                               CancellationToken cancellationToken)
        {
            _chatProcessor = new ChatProcessor(context);
            var msg = context.Update.Message;

            if (msg.ReplyToMessage != null)
            {
                var repMsg = msg.ReplyToMessage;
                await _chatProcessor.SendAsync("Mengumpulkan informasi");

                var partsContent = repMsg.Text.Split(new[] { "\n\n" }, StringSplitOptions.None);
                var partsMsgText = msg.Text.GetTextWithoutCmd().Split("\n\n");

                ConsoleHelper.WriteLine(msg.Text);
                ConsoleHelper.WriteLine(repMsg.Text);
                ConsoleHelper.WriteLine(partsContent.ToJson());
                ConsoleHelper.WriteLine(partsMsgText.ToJson());

                var data = new Dictionary <string, object>()
                {
                    { "slug", partsMsgText[0] },
                    { "content", partsContent[0] },
                    { "chat_id", msg.Chat.Id },
                    { "user_id", msg.From.Id }
                };

                if (partsMsgText[1] != "")
                {
                    data.Add("btn_data", partsMsgText[1]);
                }

                await _chatProcessor.EditAsync("Menyimpan..");

                await _notesService.SaveNote(data);

                await _chatProcessor.EditAsync("Berhasil");
            }
        }
        public override async Task HandleAsync(IUpdateContext context, UpdateDelegate next, string[] args, CancellationToken cancellationToken)
        {
            var msg = context.Update.Message;

            chatProcessor = new ChatProcessor(context);

            await chatProcessor.SendAsync("🍽 Loading..");

            //            var admins = context.Update.Message.Chat.AllMembersAreAdministrators;
            var admins = await context.Bot.Client.GetChatAdministratorsAsync(msg.Chat.Id, cancellationToken);

            var creatorStr = string.Empty;
            var adminStr   = string.Empty;
            int number     = 1;

            foreach (var admin in admins)
            {
                var user     = admin.User;
                var nameLink = MemberHelper.GetNameLink(user.Id, (user.FirstName + " " + user.LastName).Trim());
                if (admin.Status == ChatMemberStatus.Creator)
                {
                    creatorStr = nameLink;
                }
                else
                {
                    adminStr += $"{number++}. {nameLink}\n";
                }

                //                Console.WriteLine(TextHelper.ToJson(admin));
                //                await chatProcessor.EditAsync(TextHelper.ToJson(admin));
            }

            var sendText = $"👤 <b>Creator</b>" +
                           $"\n└ {creatorStr}" +
                           $"\n" +
                           $"\n👥️ <b>Administrators</b>" +
                           $"\n{adminStr}";

            await chatProcessor.EditAsync(sendText);
        }
Ejemplo n.º 6
0
        public override async Task HandleAsync(IUpdateContext context, UpdateDelegate next, string[] args, CancellationToken cancellationToken)
        {
            _chatProcessor = new ChatProcessor(context);
            var msg = context.Update.Message;

            var isAdmin = await _chatProcessor.IsAdminGroup();

            var tagVal   = args[0];
            var sendText = "Perintah Untag hanya untuk ngadmin.";

            if (isAdmin)
            {
                await _chatProcessor.SendAsync("Memeriksa..");

                var isExist = await _tagsService.IsExist(_chatProcessor.Message.Chat.Id, tagVal);

                if (isExist)
                {
                    ConsoleHelper.WriteLine($"Sedang menghapus tag {tagVal}");
                    var unTag = await _tagsService.DeleteTag(_chatProcessor.Message.Chat.Id, tagVal);

                    if (unTag)
                    {
                        sendText = $"Hapus tag {tagVal} berhasil";
                    }

                    await _chatProcessor.EditAsync(sendText);

                    return;
                }
                else
                {
                    sendText = $"Tag {tagVal} tidak di temukan";
                }
            }

            await _chatProcessor.SendAsync(sendText);
        }
Ejemplo n.º 7
0
        public override async Task HandleAsync(IUpdateContext context, UpdateDelegate next, string[] args,
                                               CancellationToken cancellationToken)
        {
            _chatProcessor = new ChatProcessor(context);
            var msg = context.Update.Message;

            _settingsService = new SettingsService(msg);

            if (msg.Chat.Type == ChatType.Private)
            {
                await _chatProcessor.SendAsync("Welcome hanya untuk grup saja");

                return;
            }

            var partsMsg = msg.Text.Split(' ').ToArray();

            string[] commands = { "message", "msg", "button", "btn" };
            ConsoleHelper.WriteLine(partsMsg.ToJson());

            var isAdmin = await _chatProcessor.IsAdminGroup();

            if (isAdmin)
            {
                if (msg.ReplyToMessage != null)
                {
                    var repMsg = msg.ReplyToMessage;
                    if (repMsg.GetFileId() != "")
                    {
                        var mediaType = repMsg.Type.ToString().ToLower();
                        await _chatProcessor.SendAsync("Sedang menyimpan Welcome Media..");

                        await _settingsService.UpdateCell("welcome_media", repMsg.GetFileId());

                        await _settingsService.UpdateCell("welcome_media_type", mediaType);

                        ConsoleHelper.WriteLine("Save media success..");

                        await _chatProcessor.EditAsync("Welcome Media berhasil di simpan.");

                        return;
                    }
                    else
                    {
                        await _chatProcessor.SendAsync("Media tidak terdeteksi di pesan yg di reply tersebut.");

                        return;
                    }
                }

                ConsoleHelper.WriteLine(partsMsg.Length);

                var missParamText = $"Parameter yg di dukung {string.Join(", ", commands)}" +
                                    $"\nContoh: <code>/setwelcome message</code>";

                if (partsMsg.Length > 1)
                {
                    if (commands.Contains(partsMsg[1]))
                    {
                        if (partsMsg[2] != null)
                        {
                            var target = partsMsg[1]
                                         .Replace("msg", "message")
                                         .Replace("btn", "button");
                            var columnTarget = $"welcome_{target}";
                            var data         = msg.Text
                                               .Replace(partsMsg[0], "")
                                               .Replace(partsMsg[1], "").Trim();

                            // ConsoleHelper.WriteLine(columnTarget);
                            // ConsoleHelper.WriteLine(data);

                            await _chatProcessor.SendAsync("Sedang menyimpan Welcome Message..");

                            await _settingsService.UpdateCell(columnTarget, data);

                            await _chatProcessor.EditAsync($"Welcome {target} berhasil di simpan!");
                        }
                        else
                        {
                            await _chatProcessor.SendAsync("Masukan Pesan atau tombol yang akan di tetapkan");
                        }
                    }
                    else
                    {
                        await _chatProcessor.SendAsync(missParamText);
                    }
                }
                else
                {
                    await _chatProcessor.SendAsync(missParamText);
                }
            }
        }
        public override async Task HandleAsync(IUpdateContext context, UpdateDelegate next, string[] args,
                                               CancellationToken cancellationToken)
        {
            var msg = context.Update.Message;

            _chatProcessor = new ChatProcessor(context);
            var isSudoer = msg.From.Id.IsSudoer();

            var sendText = "ℹ Simpan tag ke Cloud Tags" +
                           "\nContoh: <code>/tag tagnya [tombol|link.tombol]</code> - Reply pesan" +
                           "\nPanjang tag minimal 3 karakter." +
                           "\nTanda [ ] artinya tidak harus" +
                           "\n" +
                           "\n📝 <i>Jika untuk grup, di rekomendasikan membuat sebuah channel, " +
                           "lalu link ke post di tautkan sebagai tombol.</i>";

            if (!isSudoer)
            {
                sendText = "This feature currently limited";
            }

            if (msg.ReplyToMessage != null && isSudoer)
            {
                ConsoleHelper.WriteLine("Replied message detected..");
                ConsoleHelper.WriteLine($"Arg0: {args[0]}");

                if (args[0].Length >= 3)
                {
                    await _chatProcessor.SendAsync("📖 Mengumpulkan informasi..");

//                    ConsoleHelper.WriteLine(TextHelper.ToJson(msg.ReplyToMessage));

                    var content = msg.ReplyToMessage.Text;
                    ConsoleHelper.WriteLine(content);

                    bool isExist = await _tagsService.IsExist(msg.Chat.Id, args[0].Trim());

                    ConsoleHelper.WriteLine($"Tag isExist: {isExist}");
                    if (!isExist)
                    {
                        var data = new Dictionary <string, object>()
                        {
                            { "id_chat", msg.Chat.Id },
                            { "id_user", msg.From.Id },
                            { "tag", args[0].Trim() },
                            { "content", content }
                        };

                        await _chatProcessor.EditAsync("📝 Menyimpan tag data..");

                        await _tagsService.SaveTag(data);

//                        var keyboard = new InlineKeyboardMarkup(
//                            InlineKeyboardButton.WithCallbackData("OK", "tag finish-create")
//                        );

                        await _chatProcessor.EditAsync("✅ Tag berhasil di simpan..");

                        await _tagsService.UpdateCacheAsync(msg);

                        return;
                    }

                    await _chatProcessor.EditAsync(
                        "✅ Tag sudah ada. Silakan ganti Tag jika ingin isi konten berbeda");
                }

                await _chatProcessor.EditAsync("Slug Tag minimal 3 karakter");
            }
            else
            {
                foreach (var arg in args)
                {
                    Console.WriteLine(arg);
                }

                await _chatProcessor.SendAsync(sendText);
            }
        }