public override async Task HandleAsync(IUpdateContext context, UpdateDelegate next, string[] args,
                                               CancellationToken cancellationToken)
        {
            ChatHelper.Init(context);
            _rssService = new RssService(context.Update.Message);

            var isAdminOrPrivateChat = await ChatHelper.IsAdminOrPrivateChat();

            if (isAdminOrPrivateChat)
            {
                var urlFeed = ChatHelper.Message.Text.GetTextWithoutCmd();

                await $"Sedang menghapus {urlFeed}".SendTextAsync();

                var delete = await _rssService.DeleteRssAsync(urlFeed);

                var success = delete.ToBool()
                    ? "berhasil."
                    : "gagal. Mungkin RSS tersebut sudah di hapus atau belum di tambahkan";

                await $"Hapus {urlFeed} {success}".EditAsync();
            }


            ChatHelper.Close();
        }
Ejemplo n.º 2
0
        // private ChatProcessor _chatProcessor;

        public override async Task HandleAsync(IUpdateContext context, UpdateDelegate next, string[] args,
                                               CancellationToken cancellationToken)
        {
            // _chatProcessor = new ChatProcessor(context);
            ChatHelper.Init(context);

            var msg = context.Update.Message;

            var keyboard = new InlineKeyboardMarkup(
                InlineKeyboardButton.WithCallbackData("Ping", "PONG")
                );

            await "ℹ️ Pong!!".AppendTextAsync();
            var isSudoer = msg.From.Id.IsSudoer();

            if (msg.Chat.Type == ChatType.Private && isSudoer)
            {
                // await "\n<b>Engine info.</b>".AppendTextAsync();
                await "🎛 <b>Engine info.</b>".AppendTextAsync();

                // var getWebHookInfo = await _chatProcessor.Client.GetWebhookInfoAsync(cancellationToken);
                var getWebHookInfo = await Bot.Client.GetWebhookInfoAsync(cancellationToken);

                if (getWebHookInfo.Url == "")
                {
                    // sendText += "\n\n<i>Bot run in Poll mode.</i>";
                    await "\n<i>Bot run in Poll mode.</i>".AppendTextAsync(keyboard);
                }
                else
                {
                    var hookInfo = "\n<i>Bot run in Webhook mode.</i>" +
                                   $"\nUrl WebHook: {getWebHookInfo.Url}" +
                                   $"\nUrl Custom Cert: {getWebHookInfo.HasCustomCertificate}" +
                                   $"\nAllowed Updates: {getWebHookInfo.AllowedUpdates}" +
                                   $"\nPending Count: {getWebHookInfo.PendingUpdateCount}" +
                                   $"\nMaxConnection: {getWebHookInfo.MaxConnections}" +
                                   $"\nLast Error: {getWebHookInfo.LastErrorDate}" +
                                   $"\nError Message: {getWebHookInfo.LastErrorMessage}";

                    await hookInfo.AppendTextAsync(keyboard);
                }
            }

            // await sendText.AppendTextAsync(keyboard);

            ChatHelper.Close();
        }
Ejemplo n.º 3
0
        public override async Task HandleAsync(IUpdateContext context, UpdateDelegate next, string[] args,
                                               CancellationToken cancellationToken)
        {
            ChatHelper.Init(context);
            _rssService = new RssService(context.Update.Message);

            var chatId = ChatHelper.Message.Chat.Id;

            if (ChatHelper.Message.From.Id.IsSudoer())
            {
                ConsoleHelper.WriteLine("Test started..");
                await "Sedang mengetes sesuatu".SendTextAsync();

                var data = await new Query("rss_history")
                           .Where("chat_id", chatId)
                           .ExecForMysql()
                           .GetAsync();

                var rssHistories = data
                                   .ToJson()
                                   .MapObject <List <RssHistory> >();

                ConsoleHelper.WriteLine(data.GetType());
                ConsoleHelper.WriteLine(data.ToJson(true));

                ConsoleHelper.WriteLine(rssHistories.GetType());
                ConsoleHelper.WriteLine(rssHistories.ToJson(true));

                ConsoleHelper.WriteLine("Test completed..");
                await "Selesai ngetest".EditAsync();
            }
            else
            {
                await "Unauthorized.".SendTextAsync();
            }

            ChatHelper.Close();
        }
        public override async Task HandleAsync(IUpdateContext context, UpdateDelegate next, string[] args, CancellationToken cancellationToken)
        {
            _rssService = new RssService(ChatHelper.Message);

            ChatHelper.Init(context);

            var chatId  = ChatHelper.Message.Chat.Id.ToString();
            var isAdmin = await ChatHelper.IsAdminGroup();

            if (isAdmin || ChatHelper.IsPrivateChat())
            {
                await "🔄 Sedang meload data..".SendTextAsync();
                var rssData = await _rssService.GetRssSettingsAsync(chatId);

                var sendText = $"📚 <b>List RSS</b>: {rssData.Count} Items.";
                int num      = 1;
                foreach (RssSetting rss in rssData)
                {
                    // var urlFeed = rss["url_feed"].ToString();
                    sendText += $"\n{num++}. {rss.UrlFeed}";
                }

                if (rssData.Count == 0)
                {
                    sendText += "\n\nSepertinya kamu belum menambahkan RSS disini. " +
                                "Kamu dapat menambahkan RSS dengan jumlah tidak terbatas!" +
                                "\nGunakan <code>/setrss https://link_rss_nya</code> untuk menambahkan.";
                }

                await sendText.EditAsync();
            }
            else
            {
                await "Kamu bukan admin, atau kamu bisa mengaturnya di japri ".SendTextAsync();
            }

            ChatHelper.Close();
        }
Ejemplo n.º 5
0
        public override async Task HandleAsync(IUpdateContext context, UpdateDelegate next, string[] args, CancellationToken cancellationToken)
        {
            ChatHelper.Init(context);
            _rssService = new RssService(ChatHelper.Message);

            var url = ChatHelper.Message.Text.GetTextWithoutCmd();

            if (url != null)
            {
                await $"Sedang memeriksa {url}".AppendTextAsync();
                if (url.CheckUrlValid())
                {
                    await $"Sedang memvalidasi {url}".AppendTextAsync();
                    var isValid = await url.IsValidUrlFeed();

                    if (!isValid)
                    {
                        await "Sedang mencari kemungkinan RSS yang valid".AppendTextAsync();
                        var foundUrl = await url.GetBaseUrl().FindUrlFeed();

                        ConsoleHelper.WriteLine($"Found URL Feed: {foundUrl}");

                        if (foundUrl != "")
                        {
                            url = foundUrl;
                        }
                        else
                        {
                            var notfoundRss = $"Kami tidak dapat memvalidasi {url} adalah Link RSS yang valid, " +
                                              $"dan mencoba mencari di {url.GetBaseUrl()} tetap tidak dapat menemukan.";

                            await notfoundRss.EditAsync();

                            ChatHelper.Close();
                            return;
                        }
                    }

                    var isFeedExist = await _rssService.IsExistRssAsync(url);

                    ConsoleHelper.WriteLine($"Is Url Exist: {isFeedExist}");

                    if (!isFeedExist)
                    {
                        await $"Sedang menyimpan..".SendTextAsync();

                        var data = new Dictionary <string, object>()
                        {
                            { "url_feed", url },
                            { "chat_id", ChatHelper.Message.Chat.Id },
                            { "from_id", ChatHelper.Message.From.Id }
                        };

                        await _rssService.SaveRssSettingAsync(data);

                        await $"Url: {url} berhasil di simpan".EditAsync();
                    }
                    else
                    {
                        await $"Url: {url} sudah di simpan".SendTextAsync();
                    }
                }
                else
                {
                    await "Url tersebut sepertinya tidak valid".SendTextAsync();
                }
            }
            else
            {
                await "Apa url Feednya?".SendTextAsync();
            }

            ChatHelper.Close();
        }