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(); }
public override async Task HandleAsync( IUpdateContext context, UpdateDelegate next, string[] args ) { await _telegramService.AddUpdateContext(context); var chatId = _telegramService.ChatId; var checkUserPermission = await _telegramService.CheckUserPermission(); if (!checkUserPermission) { Log.Warning("Delete RSS only for admin or private chat!"); await _telegramService.DeleteAsync(); return; } var urlFeed = _telegramService.Message.Text.GetTextWithoutCmd(); await _telegramService.SendTextMessageAsync($"Sedang menghapus {urlFeed}"); var delete = await _rssService.DeleteRssAsync(chatId, urlFeed); var success = delete.ToBool() ? "berhasil." : "gagal. Mungkin RSS tersebut sudah di hapus atau belum di tambahkan"; await _telegramService.EditMessageTextAsync($"Hapus {urlFeed} {success}"); await _rssFeedService.ReRegisterRssFeedByChatId(chatId); }
public async Task <bool> ExecuteAsync() { var chatId = _telegramService.ChatId; var chatTitle = _telegramService.ChatTitle; var messageId = _telegramService.CallBackMessageId; var answerHeader = $"RSS Control for {chatTitle}"; var answerDescription = string.Empty; var part = _telegramService.CallbackQuery.Data?.Split(" "); var rssId = part !.ElementAtOrDefault(2); var page = 0; const int take = 5; if (!await _telegramService.CheckUserPermission()) { await _telegramService.AnswerCallbackQueryAsync("Anda tidak mempunyai akses", true); return(false); } var rssFind = new RssSettingFindDto() { ChatId = chatId }; var updateValue = new Dictionary <string, object>() { { "updated_at", DateTime.UtcNow } }; switch (part.ElementAtOrDefault(1)) { case "stop-all": updateValue.Add("is_enabled", false); answerDescription = $"Semua service berhasil dimatikan"; break; case "start-all": updateValue.Add("is_enabled", true); answerDescription = "Semua service berhasil diaktifkan"; break; case "start": rssFind.Id = rssId.ToInt64(); updateValue.Add("is_enabled", true); answerDescription = "Service berhasil di aktifkan"; break; case "stop": rssFind.Id = rssId.ToInt64(); updateValue.Add("is_enabled", false); answerDescription = "Service berhasil dimatikan"; break; case "attachment-off": rssFind.Id = rssId.ToInt64(); updateValue.Add("include_attachment", false); answerDescription = "Attachment tidak akan ditambahkan"; break; case "attachment-on": rssFind.Id = rssId.ToInt64(); updateValue.Add("include_attachment", true); answerDescription = "Berhasil mengaktifkan attachment"; break; case "delete": await _rssService.DeleteRssAsync( chatId : chatId, columnName : "id", columnValue : rssId ); answerDescription = "Service berhasil dihapus"; break; case "navigate-page": var toPage = part.ElementAtOrDefault(2).ToInt(); page = toPage; answerDescription = "Halaman " + (toPage + 1); break; } await _rssService.UpdateRssSettingAsync(rssFind, updateValue); await _rssFeedService.ReRegisterRssFeedByChatId(chatId); var answerCombined = answerHeader + Environment.NewLine + answerDescription; var btnMarkupCtl = await _rssService.GetButtonMarkup( chatId : chatId, page : page, take : take ); if (answerDescription.IsNotNullOrEmpty()) { await _telegramService.EditMessageCallback(answerCombined, btnMarkupCtl); if (part.ElementAtOrDefault(1)?.Contains("all") ?? false) { await _telegramService.AnswerCallbackQueryAsync(answerCombined, true); } } await _messageHistoryService.UpdateDeleteAtAsync( new MessageHistoryFindDto() { ChatId = chatId, MessageId = messageId }, DateTime.UtcNow.AddMinutes(10) ); return(true); }