コード例 #1
0
        public override async Task HandleAsync(IUpdateContext context, UpdateDelegate next, string[] args, CancellationToken cancellationToken)
        {
            _chatProcessor = new ChatProcessor(context);
            var msg      = context.Update.Message;
            var partsMsg = msg.Text.GetTextWithoutCmd().Split("|").ToArray();

            var isSudoer = _chatProcessor.IsSudoer();

            if (isSudoer)
            {
                var sendText = "Maaf, saya harus keluar";

                if (partsMsg[1] != null)
                {
                    sendText += $"\n{partsMsg[1]}";
                }
                var chatId = partsMsg[0].ToInt64();

                ConsoleHelper.WriteLine($"Target out: {chatId}");
                await _chatProcessor.SendAsync(sendText, customChatId : chatId);

                await _chatProcessor.LeaveChat(chatId);
            }
            else
            {
                await _chatProcessor.SendAsync("Kamu tidak punya hak akses.");
            }
        }
コード例 #2
0
        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);
        }
コード例 #3
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);


            ConsoleHelper.WriteLine($"Args: {string.Join(" ", args)}");
            var sendText = "Perintah /welcome hanya untuk grup saja";

            if (msg.Chat.Type != ChatType.Private)
            {
                var chatTitle = msg.Chat.Title;
                var settings  = await _settingsService.GetSettingByGroup();

                var welcomeMessage     = settings.WelcomeMessage;
                var welcomeButton      = settings.WelcomeButton;
                var welcomeMedia       = settings.WelcomeMedia;
                var welcomeMediaType   = settings.WelcomeMediaType;
                var splitWelcomeButton = welcomeButton.Split(',').ToList <string>();

                var keyboard = welcomeButton.ToReplyMarkup(2);
                sendText = $"👥 <b>{chatTitle}</b>\n";
                if (welcomeMessage == "")
                {
                    sendText += "Tidak ada konfigurasi pesan welcome, pesan default akan di terapkan";
                }
                else
                {
                    sendText += welcomeMessage;
                }

//                if (args[0] == "anu")
//                {
//                    sendText += " anu";
//                }

//                sendText += " " + string.Join(", ",args);
                if (welcomeMediaType != "")
                {
                    await _chatProcessor.SendMediaAsync(welcomeMedia, welcomeMediaType, welcomeMessage, keyboard);
                }
                else
                {
                    await _chatProcessor.SendAsync(sendText, keyboard);
                }
            }
            else
            {
                await _chatProcessor.SendAsync(sendText);
            }
        }
コード例 #4
0
        public override async Task HandleAsync(IUpdateContext context, UpdateDelegate next, string[] args,
                                               CancellationToken cancellationToken)
        {
            _chatProcessor = new ChatProcessor(context);
            var msg      = context.Update.Message;
            var sendText = "Balas pesan yg mau di report";

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

                return;
            }

            if (msg.ReplyToMessage != null)
            {
                var repMsg = msg.ReplyToMessage;

                if (msg.From.Id != repMsg.From.Id)
                {
                    var mentionAdmins = await _chatProcessor.GetMentionAdminsStr();

                    sendText = $"Ada laporan nich." +
                               $"\n{msg.GetFromNameLink()} melaporkan {repMsg.GetFromNameLink()}" +
                               $"{mentionAdmins}";

                    var keyboard = new InlineKeyboardMarkup(new[]
                    {
                        new[]
                        {
                            InlineKeyboardButton.WithCallbackData("Hapus", "PONG"),
                            InlineKeyboardButton.WithCallbackData("Tendang", "PONG"),
                        },
                        new[]
                        {
                            InlineKeyboardButton.WithCallbackData("Ban", "PONG"),
                            InlineKeyboardButton.WithCallbackData("Ke Pesan", "PONG"),
                        }
                    });

                    await _chatProcessor.SendAsync(sendText);

                    return;
                }

                sendText = "Melaporkan diri sendiri? 🤔";
            }


            await _chatProcessor.SendAsync(sendText);
        }
コード例 #5
0
        public override async Task HandleAsync(IUpdateContext context, UpdateDelegate next, string[] args,
                                               CancellationToken cancellationToken)
        {
            var msg = context.Update.Message;

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


            var sendText = "Under maintenance";

            if (msg.Chat.Type != ChatType.Private)
            {
                if (msg.From.Id.IsSudoer())
                {
                    var settings = await _settingsService.GetSettingByGroup();

                    await _settingsService.UpdateCache();

                    ConsoleHelper.WriteLine(settings.ToJson());
                    // var rules = settings.Rows[0]["rules_text"].ToString();
                    var rules = settings.RulesText;
                    ConsoleHelper.WriteLine(rules);
                    sendText = rules;
                }
            }
            else
            {
                sendText = "Rules hanya untuk grup";
            }

            await _chatProcessor.SendAsync(sendText);
        }
コード例 #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 data = new Dictionary <string, object>()
            {
                { "user_id", msg.From.Id },
                { "chat_id", msg.Chat.Id },
                { "is_afk", 1 }
            };

            var sendText = $"{msg.GetFromNameLink()} Sedang afk.";

            if (msg.Text.GetTextWithoutCmd() != "")
            {
                var afkReason = msg.Text.GetTextWithoutCmd();
                data.Add("afk_reason", afkReason);

                sendText += $"\n<i>{afkReason}</i>";
            }

            await _chatProcessor.SendAsync(sendText);

            await _afkService.SaveAsync(data);

            await _afkService.UpdateCacheAsync();
        }
コード例 #7
0
        public override async Task HandleAsync(IUpdateContext context, UpdateDelegate next, string[] args,
                                               CancellationToken cancellationToken)
        {
            _chatProcessor = new ChatProcessor(context);

            var notesData = await _notesService.GetNotesByChatId(_chatProcessor.Message.Chat.Id);

            var sendText = "Filters di Obrolan ini.";

            if (notesData.Rows.Count > 0)
            {
                foreach (DataRow note in notesData.Rows)
                {
                    sendText += $"\nID: {note["id_note"]} - ";
                    sendText += $"{note["slug"]}";
                }
            }
            else
            {
                sendText = "Tidak ada Filters di Grup ini." +
                           "\nUntuk menambahkannya ketik /addfilter";
            }

            await _notesService.UpdateCache(_chatProcessor.Message.Chat.Id);

            await _chatProcessor.SendAsync(sendText);
        }
コード例 #8
0
        public override async Task HandleAsync(IUpdateContext context, UpdateDelegate next, string[] args, CancellationToken cancellationToken)
        {
            _chatProcessor = new ChatProcessor(context);

            var botName    = Bot.GlobalConfiguration["Engines:ProductName"];
            var botVer     = Bot.GlobalConfiguration["Engines:Version"];
            var botCompany = Bot.GlobalConfiguration["Engines:Company"];

            string sendText = $"🤖 {botName} {botVer}" +
                              $"\nby {botCompany}." +
                              $"\nAdalah bot debugging, manajemen grup yang di lengkapi dengan alat keamanan. " +
                              $"Agar fungsi saya bekerja dengan fitur penuh, jadikan saya admin dengan level standard. " +
                              $"\nSaran dan fitur bisa di ajukan di @WinTenGroup atau @TgBotID.";

            var urlStart = await "help".GetUrlStart();
            var keyboard = new InlineKeyboardMarkup(
                InlineKeyboardButton.WithUrl("Dapatkan bantuan", urlStart)
                );

            if (_chatProcessor.IsPrivateChat())
            {
                keyboard = new InlineKeyboardMarkup(new[]
                {
                    new[]
                    {
                        InlineKeyboardButton.WithCallbackData("Bantuan", "help home"),
                        InlineKeyboardButton.WithUrl("Pasang Username", "https://t.me/WinTenDev/29")
                    }
                });
            }

            await _chatProcessor.SendAsync(sendText, keyboard);
        }
コード例 #9
0
        private async Task <bool> CheckGlobalBanAsync(User user)
        {
            var userId   = user.Id;
            var isKicked = false;

            var isBan = await _elasticSecurityService.IsExistInCache(userId);

            ConsoleHelper.WriteLine($"{user} IsBan: {isBan}");
            if (!isBan)
            {
                return(isKicked);
            }

            var sendText = $"{user} terdeteksi pada penjaringan WinTenDev ES2 tapi gagal di tendang.";

            isKicked = await _chatProcessor.KickMemberAsync(user);

            if (isKicked)
            {
                await _chatProcessor.UnbanMemberAsync(user);

                sendText = sendText.Replace("tapi gagal", "dan berhasil");
            }
            else
            {
                sendText += " Pastikan saya admin yang dapat menghapus Pengguna";
            }

            await _chatProcessor.SendAsync(sendText);

            return(isKicked);
        }
コード例 #10
0
        public async Task HandleAsync(IUpdateContext context, UpdateDelegate next, CancellationToken cancellationToken)
        {
            Message msg = context.Update.Message;

            _elasticSecurityService = new ElasticSecurityService(msg);
            _chatProcessor          = new ChatProcessor(context);
            var leftMember = msg.LeftChatMember;
            var isBan      = await _elasticSecurityService.IsExistInCache(leftMember.Id);

            if (!isBan)
            {
                ConsoleHelper.WriteLine("Left Chat Members...");

                var chatTitle = msg.Chat.Title;

                var newMembers   = msg.LeftChatMember;
                var leftFullName = newMembers.FirstName;


                // var fromName = msg.From.FirstName;

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

                await _chatProcessor.SendAsync(sendText);
            }
            else
            {
                ConsoleHelper.WriteLine($"Left Message ignored because {leftMember} is Global Banned");
            }
        }
コード例 #11
0
        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)
            {
                msg = msg.ReplyToMessage;
            }

            var userId   = msg.From.Id;
            var nameLink = msg.GetFromNameLink();

            var sendText = $"{nameLink} diturunkan dari admin";

            var promote = await _chatProcessor.DemoteChatMemberAsync(userId);

            if (!promote.IsSuccess)
            {
                var errorCode    = promote.ErrorCode;
                var errorMessage = promote.ErrorMessage;

                sendText = $"Demote {nameLink} gagal" +
                           $"\nPesan: {errorMessage}";
            }

            await _chatProcessor.SendAsync(sendText);
        }
コード例 #12
0
        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..");
        }
コード例 #13
0
        public async Task HandleAsync(IUpdateContext context, UpdateDelegate next, CancellationToken cancellationToken)
        {
            chatProcessor = new ChatProcessor(context);

            Message msg = context.Update.Message;

            ConsoleHelper.WriteLine("Tags Received..");
            var partsText = msg.Text.Split(new char[] { ' ', '\n', ',' })
                            .Where(x => x.Contains("#"));

            var limitedTags = partsText.Take(5);

            //            int count = 1;
            foreach (var split in limitedTags)
            {
                ConsoleHelper.WriteLine("Processing : " + split.TrimStart('#'));
                //                await chatProcessor.SendAsync($"This is tag of {split}");
                var tagData = await tagsService.GetTagByTag(msg.Chat.Id, split.TrimStart('#'));

                var json = tagData.ToJson();
                Console.WriteLine(json);

                // var content = tagData.Result.Rows[0]["content"].ToString();
                // var buttonStr = tagData.Result.Rows[0]["btn_data"].ToString();

                var content   = tagData[0].Content;
                var buttonStr = tagData[0].BtnData;

                IReplyMarkup buttonMarkup = null;
                if (buttonStr != "")
                {
                    buttonMarkup = buttonStr.ToReplyMarkup(2);
                }

                await chatProcessor.SendAsync(content, buttonMarkup);
            }

            if (partsText.Count() > limitedTags.Count())
            {
                await chatProcessor.SendAsync("Due performance reason, we limit 5 batch call tags");
            }
        }
コード例 #14
0
        public override async Task HandleAsync(IUpdateContext context, UpdateDelegate next, string[] args, CancellationToken cancellationToken)
        {
            _chatProcessor = new ChatProcessor(context);

            var msg  = context.Update.Message;
            var json = msg.ToJson(true);

            ConsoleHelper.WriteLine(json.Length);

            var sendText = $"Debug:\n {json}";
            await _chatProcessor.SendAsync(sendText);
        }
コード例 #15
0
        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);
        }
コード例 #16
0
        public async Task HandleAsync(IUpdateContext context, UpdateDelegate next, CancellationToken cancellationToken)
        {
            _chatProcessor = new ChatProcessor(context);
            var msg = context.Update.Message;

            var pinnedMsg = msg.PinnedMessage;
            var sendText  = $"📌 Pesan di sematkan baru!" +
                            $"\nPengirim: {pinnedMsg.GetFromNameLink()}" +
                            $"\nPengepin: {msg.GetFromNameLink()}";

            await _chatProcessor.SendAsync(sendText);
        }
コード例 #17
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);
        }
コード例 #18
0
        public override async Task HandleAsync(IUpdateContext context, UpdateDelegate next, string[] args,
                                               CancellationToken cancellationToken)
        {
            _chatProcessor = new ChatProcessor(context);
            var msg = context.Update.Message;

            var sendText = "Saat ini hanya untuk Sudoer saja.";

            if (msg.From.Id.IsSudoer())
            {
                sendText = "Reply pesan untuk menyaring..";
                if (msg.ReplyToMessage != null)
                {
                    var repMsg = msg.ReplyToMessage;
                    ConsoleHelper.WriteLine(msg.Type);

                    var fileId = repMsg.GetReducedFileId();

                    var isExist = await _mediaFilterService.IsExist("file_id", fileId);

                    if (!isExist)
                    {
                        var data = new Dictionary <string, object>()
                        {
                            { "file_id", fileId },
                            { "type_data", repMsg.Type.ToString().ToLower() },
                            { "blocked_by", msg.From.Id },
                            { "blocked_from", msg.Chat.Id }
                        };

                        await _mediaFilterService.SaveAsync(data);

                        sendText = "File ini berhasil di simpan";
                    }
                    else
                    {
                        sendText = "File ini sudah di simpan";
                    }
                }
            }
            else
            {
                sendText =
                    "Fitur ini membutuhkan akses Sudoer, namun file yang Anda laporkan sudah di teruskan ke Team, " +
                    "terima kasih atas laporan nya.";
            }

            await _chatProcessor.SendAsync(sendText);
        }
コード例 #19
0
        public override async Task HandleAsync(IUpdateContext context, UpdateDelegate next, string[] args, CancellationToken cancellationToken)
        {
            _chatProcessor = new ChatProcessor(context);

            var sendText = "Untuk mendapatkan bantuan klik tombol dibawah ini";
            var urlStart = await "help".GetUrlStart();
            var keyboard = new InlineKeyboardMarkup(
                InlineKeyboardButton.WithUrl("Dapatkan bantuan", urlStart)
                );

            if (_chatProcessor.IsPrivateChat())
            {
                sendText = await "home".LoadInBotDocs();
                keyboard = await "Storage/Buttons/home.json".JsonToButton();
            }

            await _chatProcessor.SendAsync(sendText, keyboard);
        }
コード例 #20
0
        public override async Task HandleAsync(IUpdateContext context, UpdateDelegate next, string[] args,
                                               CancellationToken cancellationToken)
        {
            _chatProcessor = new ChatProcessor(context);
            var msg    = context.Update.Message;
            var client = context.Bot.Client;

            var sendText = "Balas pesan yang akan di pin";

            if (msg.ReplyToMessage != null)
            {
                var pin = client.PinChatMessageAsync(
                    msg.Chat.Id,
                    msg.ReplyToMessage.MessageId);
//                ConsoleHelper.WriteLine(pin.);
            }

            await _chatProcessor.SendAsync(sendText);

//            throw new System.NotImplementedException();
        }
コード例 #21
0
        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);
        }
コード例 #22
0
        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");
            }
        }
コード例 #23
0
        public override async Task HandleAsync(IUpdateContext context, UpdateDelegate next, string[] args,
                                               CancellationToken cancellationToken)
        {
            _chatProcessor = new ChatProcessor(context);
            var     msg    = context.Update.Message;
            Message repMsg = null;
            var     data   = msg.Text.GetTextWithoutCmd();

            if (msg.ReplyToMessage != null)
            {
                repMsg = msg.ReplyToMessage;
                data   = repMsg.Text ?? repMsg.Caption;
            }

            if (data == "")
            {
                var sendText = "<b>Generate QR from text or caption media</b>" +
                               "\n<b>Usage : </b><code>/qr</code> (In-Reply)" +
                               "\n                <code>/qr your text here</code> (In-Message)";
                await _chatProcessor.SendAsync(sendText);

                return;
            }

            InlineKeyboardMarkup keyboard = null;

            if (repMsg != null)
            {
                keyboard = new InlineKeyboardMarkup(
                    InlineKeyboardButton.WithUrl("Sumber", repMsg.GetMessageLink())
                    );
            }

            var urlQr    = data.GenerateUrlQrApi();
            var fileName = $"{msg.Chat.Id}_{msg.MessageId}.jpg";

            // urlQr.SaveUrlTo(fileName);
            await _chatProcessor.SendMediaAsync(urlQr, "photo", replyMarkup : keyboard);
        }
コード例 #24
0
        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)
            {
                msg = msg.ReplyToMessage;
            }

            var chatTitle = msg.Chat.Title;
            var chatId    = msg.Chat.Id;
            var chatType  = msg.Chat.Type;

            var userId   = msg.From.Id;
            var username = msg.From.Username;
            var name     = (msg.From.FirstName + " " + msg.From.LastName).Trim();
            var userLang = msg.From.LanguageCode;

            var text = $"👥 <b>{chatTitle}</b>\n" +
                       $"ID: <code>{chatId}</code>\n" +
                       $"Type: <code>{chatType}</code>\n\n" +
                       $"👤 <b>{name}</b>\n" +
                       $"ID: <code>{userId}</code>\n" +
                       $"Username: @{username}\n" +
                       $"Language: {userLang.ToUpper()}";

            await _chatProcessor.SendAsync(text);

            //            await context.Bot.Client.SendTextMessageAsync(
            //                msg.Chat,
            //                text,
            //                ParseMode.Html,
            //                replyToMessageId: msg.MessageId
            //            );
        }
コード例 #25
0
        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);
            }
        }
コード例 #26
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);
                }
            }
        }
コード例 #27
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");
            }
        }
コード例 #28
0
        public async Task HandleAsync(IUpdateContext context, UpdateDelegate next, CancellationToken cancellationToken)
        {
            Message msg = context.Update.Message;

            _chatProcessor          = new ChatProcessor(context);
            _settingsService        = new SettingsService(msg);
            _elasticSecurityService = new ElasticSecurityService(context.Update.Message);

            ConsoleHelper.WriteLine("New Chat Members...");

            var newMembers  = msg.NewChatMembers;
            var isBootAdded = await newMembers.IsBotAdded();

            if (isBootAdded)
            {
                var botName  = Bot.GlobalConfiguration["Engines:ProductName"];
                var sendText = $"Hai, perkenalkan saya {botName}" +
                               $"\nFYI saya di bangun ulang menggunakan .NET Core, tepatnya ASP .NET Core." +
                               $"\n\nAku adalah bot pendebug dan grup manajemen yang di lengkapi dengan alat keamanan. " +
                               $"Agar saya berfungsi penuh, jadikan saya admin dengan level standard. " +
                               $"\n\nAku akan menerapkan konfigurasi standard jika aku baru pertama kali masuk kesini. " +
                               $"\n\nUntuk melihat daftar perintah bisa ketikkan /help";

                await _chatProcessor.SendAsync(sendText);

                await _settingsService.SaveSettingsAsync(new Dictionary <string, object>()
                {
                    { "chat_id", msg.Chat.Id },
                    { "chat_title", msg.Chat.Title }
                });

                if (newMembers.Length == 1)
                {
                    return;
                }
            }

            var parsedNewMember = await ParseMemberCategory(newMembers);

            var allNewMember  = parsedNewMember.AllNewMember;
            var allNoUsername = parsedNewMember.AllNoUsername;
            var allNewBot     = parsedNewMember.AllNewBot;

            if (allNewMember.Length > 0)
            {
                var chatSettings = await _settingsService.GetSettingByGroup();

                var chatTitle   = msg.Chat.Title;
                var memberCount = await _chatProcessor.GetMemberCount();

                var newMemberCount = newMembers.Length;

                ConsoleHelper.WriteLine("Preparing send Welcome..");

                if (chatSettings.WelcomeMessage == "")
                {
                    chatSettings.WelcomeMessage = $"Hai {allNewMember}" +
                                                  $"\nSelamat datang di kontrakan {chatTitle}" +
                                                  $"\nKamu adalah anggota ke-{memberCount}";
                }

                var sendText = chatSettings.WelcomeMessage.ResolveVariable(new
                {
                    allNewMember,
                    allNoUsername,
                    allNewBot,
                    newMemberCount,
                    chatTitle,
                    memberCount
                });

                IReplyMarkup keyboard = null;
                if (chatSettings.WelcomeButton != "")
                {
                    keyboard = chatSettings.WelcomeButton.ToReplyMarkup(2);
                }


                if (chatSettings.WelcomeMediaType != "")
                {
                    await _chatProcessor.SendMediaAsync(
                        chatSettings.WelcomeMedia,
                        chatSettings.WelcomeMediaType,
                        sendText,
                        keyboard);
                }
                else
                {
                    await _chatProcessor.SendAsync(sendText, keyboard);
                }

                await _settingsService.SaveSettingsAsync(new Dictionary <string, object>()
                {
                    { "chat_id", msg.Chat.Id },
                    { "chat_title", msg.Chat.Title },
                    { "members_count", memberCount }
                });
            }
            else
            {
                ConsoleHelper.WriteLine("Welcome Message ignored because User is Global Banned.");
            }
        }