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

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

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

            if (isAdmin || response.IsPrivateChat())
            {
#pragma warning disable 4014
                Task.Run(async() =>
#pragma warning restore 4014
                {
                    // Thread.CurrentThread.IsBackground = true;

                    await response.SendTextAsync("Sedang memeriksa RSS feed baru..");
                    // await "Sedang memeriksa RSS feed baru..".SendTextAsync();

                    var newRssCount = await RssHelper.ExecBroadcasterAsync(chatId);
                    if (newRssCount == 0)
                    {
                        await response.EditAsync("Tampaknya tidak ada RSS baru saat ini");
                        // await "Tampaknya tidak ada RSS baru saat ini".EditAsync();
                    }

                    // ChatHelper.Close();
                }, cancellationToken);
            }
        }
Esempio n. 2
0
        public static void InitScheduler()
        {
            Task.Run(async() =>
            {
                ConsoleHelper.WriteLine("Initializing RSS Scheduler.");

                var baseId       = "rss-scheduler";
                var cronInMinute = 10;
                var rssService   = new RssService();

                ConsoleHelper.WriteLine("Getting list Chat ID");
                var listChatId = await rssService.GetListChatIdAsync();
                foreach (RssSetting row in listChatId)
                {
                    // var chatId = row["chat_id"].ToString();

                    var chatId      = row.ChatId;
                    var recurringId = $"{chatId}-{baseId}";

                    ConsoleHelper.WriteLine($"Creating Jobs for {chatId}");

                    RecurringJob.RemoveIfExists(recurringId);
                    RecurringJob.AddOrUpdate(recurringId, ()
                                             => RssHelper.ExecBroadcasterAsync(chatId), $"*/{cronInMinute} * * * *");
                }

                ConsoleHelper.WriteLine("Registering RSS Scheduler complete.");
            });
        }