Beispiel #1
0
        public static void RegisterScheduler(this long chatId)
        {
            Log.Information("Initializing RSS Scheduler.");

            var baseId       = "rss";
            var cronInMinute = 5;

            chatId = chatId.ToInt64().ReduceChatId();
            var recurringId = $"{baseId}-{chatId}";

            Log.Information($"Creating Jobs for {chatId}");

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

            Log.Information($"Registering RSS Scheduler for {chatId} complete.");
        }
        public override async Task HandleAsync(IUpdateContext context, UpdateDelegate next, string[] args,
                                               CancellationToken cancellationToken)
        {
            // ChatHelper.Init(context);
            _telegramService = new TelegramService(context);

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

            var chatId  = _telegramService.Message.Chat.Id;
            var isAdmin = await _telegramService.IsAdminGroup()
                          .ConfigureAwait(false);

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

                    await _telegramService.SendTextAsync("Sedang memeriksa RSS feed baru..")
                    .ConfigureAwait(false);
                    // await "Sedang memeriksa RSS feed baru..".SendTextAsync();

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

                    // ChatHelper.Close();
                }, cancellationToken);
            }
        }