From d2f384f4d7c6336011491ce20f36e599bf5a4bd2 Mon Sep 17 00:00:00 2001 From: "Adam R. Grey" Date: Fri, 3 Sep 2021 11:33:28 -0400 Subject: [PATCH] youtube run tested, currently gets enqueued twice --- HumanCommunication.cs | 24 ++++++++++++++---------- Program.cs | 5 +++-- director.csproj | 2 +- showHandlers/YoutubeHandler.cs | 9 +++++---- 4 files changed, 23 insertions(+), 17 deletions(-) diff --git a/HumanCommunication.cs b/HumanCommunication.cs index 66dba3e..3ea47a3 100644 --- a/HumanCommunication.cs +++ b/HumanCommunication.cs @@ -1,6 +1,7 @@ using System; using System.IO; using System.Net; +using System.Threading.Tasks; namespace Director { @@ -41,19 +42,22 @@ namespace Director { Console.WriteLine($"[{DateTime.Now.ToLongTimeString()}] [{logLevel.ToString()}] {message}"); - //if(logLevel >= LogLevel.Warning && false) - if (false) //TODO: re-enable + if(logLevel >= LogLevel.Warning) { - var httpWebRequest = (HttpWebRequest)WebRequest.Create(call_for_humans_discord_webhook); - httpWebRequest.ContentType = "application/json"; - httpWebRequest.Method = "POST"; - using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream())) - { - streamWriter.Write($"{{\"content\":\"[{DateTime.Now.ToLongTimeString()}] [{logLevel.ToString()}] {message}\"}}"); - } - httpWebRequest.GetResponse(); + //Task.Run(() => forwardToDiscord(message, logLevel)); } } + public async void forwardToDiscord(string message, LogLevel logLevel) + { + var httpWebRequest = (HttpWebRequest)WebRequest.Create(call_for_humans_discord_webhook); + httpWebRequest.ContentType = "application/json"; + httpWebRequest.Method = "POST"; + using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream())) + { + streamWriter.Write($"{{\"content\":\"[{DateTime.Now.ToLongTimeString()}] [{logLevel.ToString()}] {message}\"}}"); + } + httpWebRequest.GetResponseAsync(); + } public enum LogLevel { Trace, //development diff --git a/Program.cs b/Program.cs index 60c90a0..51f8a1a 100644 --- a/Program.cs +++ b/Program.cs @@ -40,7 +40,8 @@ namespace director httpClient = new HttpClient(); httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", Convert.ToBase64String( System.Text.Encoding.ASCII.GetBytes($"{conf.webdav_username}:{conf.webdav_password}"))); - //tf = new Telefranz("scheduler", conf.kafka_bootstrap); + + Telefranz.Configure("scheduler", conf.kafka_bootstrap); scratch = Scratch.LoadScratch(); @@ -96,7 +97,7 @@ namespace director } Console.WriteLine("calendars checked"); #if (DEBUG) - for (int i = 0; i < 1; i++) + for (int i = 0; i < 0; i++) { var psuedo = new Schedulable.Schedulable(); psuedo.Showtime = DateTime.Now + TimeSpan.FromSeconds(30); diff --git a/director.csproj b/director.csproj index 1414a4e..74bfdf5 100644 --- a/director.csproj +++ b/director.csproj @@ -7,7 +7,7 @@ - + diff --git a/showHandlers/YoutubeHandler.cs b/showHandlers/YoutubeHandler.cs index 1fdd13d..60cf723 100644 --- a/showHandlers/YoutubeHandler.cs +++ b/showHandlers/YoutubeHandler.cs @@ -51,12 +51,12 @@ namespace ShowHandlers Console.WriteLine($"preshow agents needed: {string.Join(", ", AgentsNeeded)}"); agentsPresent.Clear(); - //TODO: actual telefranz - //Telefranz.Instance.addHandler(agentReports); - //Telefranz.Instance.ProduceMessage(new silver_messages.global.sound_off()); + Telefranz.Instance.addHandler(agentReports); +// Telefranz.Instance.ProduceMessage(new silver_messages.global.sound_off()); while (AgentsNeeded.Where(ap => !agentsPresent.Contains(ap))?.Count() > 0) { checkSignal.WaitOne(TimeSpan.FromSeconds(15)); + //Telefranz.Instance.ProduceMessage(new silver_messages.global.sound_off()); if (DateTime.Now > evt.OccurrenceStart - leadNeeded) { var miaAgents = string.Join(", ", AgentsNeeded.Where(ap => !agentsPresent.Contains(ap))); @@ -69,7 +69,7 @@ namespace ShowHandlers protected void preShow_RunChecks(iCalHoopJumping.CalendarOccurrence evt, TimeSpan leadNeeded) { var argsList = new List() { JsonConvert.SerializeObject(evt) }; - //Telefranz.Instance.addHandler(youtubeAgentReports); + Telefranz.Instance.addHandler(youtubeAgentReports); Console.WriteLine($"pre show: run check. It's just going to be \"is the metadata set\"."); Action issueChecks = () => { @@ -91,6 +91,7 @@ namespace ShowHandlers } protected void agentReports(silver_messages.global.report r) { + Console.WriteLine($"agent responding to sound off: {r.name}"); if (AgentsNeeded?.FirstOrDefault(an => an.ToLower() == r.name.ToLower()) != null) { lock (agentsPresent)