diff --git a/Configuration.cs b/Configuration.cs index 13d1e84..ff3b328 100644 --- a/Configuration.cs +++ b/Configuration.cs @@ -10,6 +10,7 @@ namespace ttrss_co_client public string PodcastTitlePrefix { get; set; } public string OnDoneCopy { get; set; } public string WorkingDirectory { get; set; } = "./working/"; + public string ChatScript { get; set; } public IEnumerable feedActions { get; set; } public class FeedAction { diff --git a/Program.cs b/Program.cs index 38dd06f..1315ef7 100644 --- a/Program.cs +++ b/Program.cs @@ -116,6 +116,8 @@ namespace ttrss_co_client phase2TaskConcretions.Add(concretion); } + ChatMessage.ChatScript = conf.ChatScript; + while (remainingWork.Count > 0) { //todo: solve the halting problem @@ -134,6 +136,7 @@ namespace ttrss_co_client if (appropriatePhase2Task != null) { wo.Phase2TaskList.Remove(wo.Phase2TaskList.Keys.Min()); + Console.WriteLine("launching phase 2 task: " + taskName); Phase2Tasks.Add(appropriatePhase2Task.ActOn(wo)); } else @@ -148,18 +151,19 @@ namespace ttrss_co_client foreach (var lingeringTask in Phase2Tasks) { var wo = await lingeringTask; + var wop = Path.Combine(conf.WorkingDirectory, wo.Item2.guid.ToString(), "workorder.json"); + File.WriteAllText(wop, JsonConvert.SerializeObject(wo.Item2)); //if you tell me it's done, or you need to continue now.... I believe you. - //TODO: be smart enough to override? switch (wo.Item1) { case Phase2Task.TaskStatus.Done: + File.Delete(wop); Directory.Delete(Path.Combine(conf.WorkingDirectory, wo.Item2.guid.ToString())); break; case Phase2Task.TaskStatus.ContinueNow: remainingWork.Add(wo.Item2); break; case Phase2Task.TaskStatus.TryLater: - File.WriteAllText(Path.Combine(conf.WorkingDirectory, wo.Item2.guid.ToString(), "workorder.json"), JsonConvert.SerializeObject(wo.Item2)); break; } } diff --git a/sample-appsettings.json b/sample-appsettings.json index c86bab2..ced2ae5 100644 --- a/sample-appsettings.json +++ b/sample-appsettings.json @@ -5,16 +5,17 @@ "podcastTitlePrefix": "[podcast title] - ", "onDoneCopy":"./", "workingDirectory":"working/", - "feedActions": + "chatScript": "miscChat.sh", + "feedActions": [ { "triggerlabelCaption":"dl plz", "command":"dl" - }, + }, { "triggerlabelCaption":"podcastify-yt plz", "command":"podcastifyYT" - }, + }, { "triggerlabelCaption":"podcastify-attachment plz", "command":"podcastifyAttachment" diff --git a/tasks/ChatMessage.cs b/tasks/ChatMessage.cs new file mode 100644 index 0000000..a823a10 --- /dev/null +++ b/tasks/ChatMessage.cs @@ -0,0 +1,22 @@ +namespace ttrss_co_client.tasks; + +using System.Linq; +using System.Diagnostics; +using ttrss_co_client.ttrss; +using ttrss_co_client.ttrss.datastructures; +using System.Threading.Tasks; +using System; + +public class ChatMessage : Phase2Task +{ + public static string ChatScript { get; set; } + public override string TaskName => "chatmessage"; + + public override async Task> ActOn(WorkOrder workOrder) + { + await Process.Start(ChatScript, + workOrder.data["chatmessage"] + (await TtrssClient.GetArticles(workOrder.articleId)).First().feed_title + ).WaitForExitAsync(); + return new Tuple(TaskStatus.Done, workOrder); + } +} \ No newline at end of file diff --git a/tasks/MarkRead.cs b/tasks/MarkRead.cs new file mode 100644 index 0000000..b6ca05d --- /dev/null +++ b/tasks/MarkRead.cs @@ -0,0 +1,19 @@ +namespace ttrss_co_client.tasks; + +using System.Linq; +using System.Diagnostics; +using ttrss_co_client.ttrss; +using ttrss_co_client.ttrss.datastructures; +using System.Threading.Tasks; +using System; + +public class MarkRead : Phase2Task +{ + public override string TaskName => "markread"; + + public override async Task> ActOn(WorkOrder workOrder) + { + await TtrssClient.UpdateArticleField(ApiClient.UPDATEFIELD.unread, ApiClient.UPDATEMODE.SetFalse, workOrder.articleId); + return new Tuple(TaskStatus.ContinueNow, workOrder); + } +} \ No newline at end of file diff --git a/tasks/PodcastifyAttachment.cs b/tasks/PodcastifyAttachment.cs index bc8bfc1..f7ef5c3 100644 --- a/tasks/PodcastifyAttachment.cs +++ b/tasks/PodcastifyAttachment.cs @@ -43,7 +43,7 @@ namespace ttrss_co_client.tasks podcastTitle = titlingLabel.caption.Substring(Conf.PodcastTitlePrefix.Length); } Console.WriteLine($"article {headline.id} - podcastifying; {podcastTitle}"); - + await TtrssClient.UpdateArticleNote($"{headline.note}\n[{DateTime.Now.ToString("o")}] - podcastify attachment (dl): {outputStr}", headline.id); if (!File.Exists(downloadPath)) { @@ -70,6 +70,11 @@ namespace ttrss_co_client.tasks toReturn.data["conversion-target"] = ".mp3"; } + toReturn.Phase2TaskList[2] = "markread"; + + toReturn.Phase2TaskList[3] = "chatmessage"; + toReturn.data["chatmessage"] = "new podcast from "; + return toReturn; } } diff --git a/tasks/PodcastifyYT.cs b/tasks/PodcastifyYT.cs index 6c891dc..7fdcfc7 100644 --- a/tasks/PodcastifyYT.cs +++ b/tasks/PodcastifyYT.cs @@ -11,7 +11,7 @@ namespace ttrss_co_client.tasks public override async Task ActOn(Headline headline, IEnumerable