poc check for responding agents seems to work, need to test telefranzing them
This commit is contained in:
parent
47de14dca9
commit
ac3b998da9
59
HumanCommunication.cs
Normal file
59
HumanCommunication.cs
Normal file
@ -0,0 +1,59 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
|
||||
namespace Director
|
||||
{
|
||||
public class HumanCommunication
|
||||
{
|
||||
private static string call_for_humans_discord_webhook{get;set;}
|
||||
private static HumanCommunication _instance = null;
|
||||
private static readonly object createLock = new object();
|
||||
public static void Configure(string call_for_humans_discord_webhook)
|
||||
{
|
||||
lock (createLock)
|
||||
{
|
||||
if (_instance == null)
|
||||
{
|
||||
_instance = new HumanCommunication(call_for_humans_discord_webhook);
|
||||
}
|
||||
}
|
||||
}
|
||||
public static HumanCommunication Instance
|
||||
{
|
||||
get
|
||||
{
|
||||
lock (createLock)
|
||||
{
|
||||
if (_instance == null)
|
||||
{
|
||||
throw new NotInitializedException("Configure me first");
|
||||
}
|
||||
}
|
||||
return _instance;
|
||||
}
|
||||
}
|
||||
private HumanCommunication(string discord_webhook)
|
||||
{
|
||||
HumanCommunication.call_for_humans_discord_webhook = discord_webhook;
|
||||
}
|
||||
public void Say(string message, LogLevel logLevel = LogLevel.Info)
|
||||
{
|
||||
Console.WriteLine($"[{DateTime.Now.ToLongTimeString()}] [{logLevel.ToString()}] {message}");
|
||||
|
||||
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();
|
||||
}
|
||||
public enum LogLevel { Trace, Verbose, Info, Warning, Error, Showstopper }
|
||||
}
|
||||
public class NotInitializedException : Exception
|
||||
{
|
||||
public NotInitializedException(string message) : base(message) { }
|
||||
}
|
||||
}
|
20
Log.cs
20
Log.cs
@ -1,20 +0,0 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
|
||||
public class Log
|
||||
{
|
||||
public static string call_for_humans_discord_webhook{get;set;}
|
||||
public static void Panic(string message)
|
||||
{
|
||||
Console.Error.WriteLine(message);
|
||||
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\":\"" + message + "\"}");
|
||||
}
|
||||
httpWebRequest.GetResponse();
|
||||
}
|
||||
}
|
@ -8,6 +8,7 @@ using System.Net.Http;
|
||||
using System.Net.Http.Headers;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Director;
|
||||
using franz;
|
||||
using Newtonsoft.Json;
|
||||
using ShowHandlers;
|
||||
@ -34,7 +35,7 @@ namespace director
|
||||
return;
|
||||
}
|
||||
conf = JsonConvert.DeserializeObject<Config>(File.ReadAllText("appsettings.json"));
|
||||
Log.call_for_humans_discord_webhook = conf.call_for_humans_discord_webhook;
|
||||
HumanCommunication.Configure(conf.call_for_humans_discord_webhook);
|
||||
|
||||
httpClient = new HttpClient();
|
||||
httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", Convert.ToBase64String(
|
||||
@ -94,7 +95,7 @@ namespace director
|
||||
}
|
||||
Console.WriteLine("calendars checked");
|
||||
#if (DEBUG)
|
||||
for (int i = 0; i < 3; i++)
|
||||
for (int i = 0; i < 1; i++)
|
||||
{
|
||||
var psuedo = new Schedulable.Schedulable();
|
||||
psuedo.Showtime = DateTime.Now + TimeSpan.FromSeconds(30);
|
||||
@ -156,6 +157,7 @@ namespace director
|
||||
{
|
||||
Task.WaitAll(Task.Delay(napLength));
|
||||
}
|
||||
Console.WriteLine("places, everyone!");
|
||||
|
||||
try
|
||||
{
|
||||
@ -173,7 +175,7 @@ namespace director
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Log.Panic($"error in show handler! Panicking!\n{JsonConvert.SerializeObject(e)}");
|
||||
HumanCommunication.Instance.Say($"error in show handler! Panicking!\n{JsonConvert.SerializeObject(e)}", HumanCommunication.LogLevel.Showstopper);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@ -12,12 +12,12 @@ namespace Schedulable.Show
|
||||
public class TaskList
|
||||
{
|
||||
public IEnumerable<Checklistable> Manual { get; set; }
|
||||
public IEnumerable<string> Commands { get; set; }
|
||||
public IEnumerable<CommandLine> Commands { get; set; }
|
||||
}
|
||||
public class PreshowTaskList : TaskList
|
||||
{
|
||||
public IEnumerable<string> AgentsNeeded { get; set; }
|
||||
public IEnumerable<string> Checks { get; set; }
|
||||
public IEnumerable<CommandLineCheck> Checks { get; set; }
|
||||
}
|
||||
public class Checklistable
|
||||
{
|
||||
@ -25,9 +25,17 @@ namespace Schedulable.Show
|
||||
public string Label { get; set; }
|
||||
public IEnumerable<Checklistable> Items { get; set; } //if no items, just throw up a checkbox
|
||||
}
|
||||
public class CommandLine
|
||||
{
|
||||
public string cmd { get; set; }
|
||||
public string args { get; set; }
|
||||
}
|
||||
public class CommandLineCheck : CommandLine
|
||||
{
|
||||
public string target { get; set; }
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
|
||||
public class TwitchStream : Show
|
||||
{
|
||||
public string TwitchTitle { get; set; }
|
||||
|
@ -5,6 +5,7 @@ namespace ShowHandlers
|
||||
{
|
||||
public abstract class ShowHandler
|
||||
{
|
||||
protected abstract TimeSpan AgentsRespondingBuffer { get; }
|
||||
public abstract void Handle(iCalHoopJumping.CalendarOccurrence evt);
|
||||
}
|
||||
}
|
@ -5,6 +5,7 @@ namespace ShowHandlers
|
||||
{
|
||||
public class TwitchStreamHandler : ShowHandler
|
||||
{
|
||||
protected override TimeSpan AgentsRespondingBuffer { get { return TimeSpan.FromHours(1); } }
|
||||
public override void Handle(iCalHoopJumping.CalendarOccurrence evt)
|
||||
{
|
||||
Console.WriteLine("I am a twitch stream handler, it falls to me to...");
|
||||
|
@ -1,9 +1,11 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using director;
|
||||
using Director;
|
||||
using franz;
|
||||
using Newtonsoft.Json;
|
||||
using Schedulable.Show;
|
||||
@ -14,45 +16,85 @@ namespace ShowHandlers
|
||||
{
|
||||
private YoutubeRelease config;
|
||||
private List<string> agentsPresent = new List<string>();
|
||||
private bool essentialChecksPassed = false;
|
||||
private bool allChecksPassed = false;
|
||||
private Dictionary<string, bool> checksProgress = new Dictionary<string, bool>();
|
||||
private readonly AutoResetEvent checkSignal = new AutoResetEvent(false);
|
||||
|
||||
protected override TimeSpan AgentsRespondingBuffer { get { return TimeSpan.FromHours(1); } }
|
||||
|
||||
public override void Handle(iCalHoopJumping.CalendarOccurrence evt)
|
||||
{
|
||||
config = JsonConvert.DeserializeObject<YoutubeRelease>(Program.conf.show_template_yt_release);
|
||||
config.PreShow.AgentsNeeded = config.PreShow.AgentsNeeded.Select(s => s.ToLower());
|
||||
Telefranz.Instance.addHandler<silver_messages.global.report>(agentReports);
|
||||
Console.WriteLine($"begin youtube handler. current time {DateTime.Now.ToLongTimeString()}");
|
||||
Console.WriteLine(JsonConvert.SerializeObject(evt));
|
||||
var ytConfig = File.ReadAllText(Program.conf.show_template_yt_release);
|
||||
config = JsonConvert.DeserializeObject<YoutubeRelease>(ytConfig);
|
||||
config.PreShow.AgentsNeeded = config.PreShow.AgentsNeeded.Select(s => s.ToLower()).ToList();
|
||||
Task.Run(() => PreShow(evt));
|
||||
Console.WriteLine("kicked off the pre-show");
|
||||
if (evt.OccurrenceStart > DateTime.Now)
|
||||
{
|
||||
Task.WaitAll(Task.Delay(evt.OccurrenceStart - DateTime.Now));
|
||||
}
|
||||
//youtube releases in particular jump right to post-show
|
||||
PostShow(evt);
|
||||
}
|
||||
~YoutubeHandler()
|
||||
{
|
||||
Telefranz.Instance.removeHandler<silver_messages.global.report>(agentReports);
|
||||
//Telefranz.Instance.removeHandler<silver_messages.global.report>(agentReports);
|
||||
}
|
||||
protected void PreShow(iCalHoopJumping.CalendarOccurrence evt)
|
||||
{
|
||||
Console.WriteLine($"it's the pre-show, showtime at: {evt.OccurrenceStart}");
|
||||
|
||||
preShow_GetAgents(evt);
|
||||
preShow_RunChecks(evt);
|
||||
preShow_RunCommands(evt);
|
||||
}
|
||||
protected void preShow_GetAgents(iCalHoopJumping.CalendarOccurrence evt)
|
||||
{
|
||||
Console.WriteLine($"preshow agents needed: {string.Join(", ", config.PreShow.AgentsNeeded)}");
|
||||
agentsPresent.Clear();
|
||||
essentialChecksPassed = false;
|
||||
allChecksPassed = false;
|
||||
Task.WaitAny(
|
||||
Task.Delay(10)
|
||||
);
|
||||
Telefranz.Instance.ProduceMessage(new silver_messages.global.sound_off());
|
||||
while(agentsPresent.Where(ap => !config.PreShow.AgentsNeeded.Contains(ap))?.Count() > 0)
|
||||
|
||||
//TODO: actual telefranz
|
||||
//Telefranz.Instance.addHandler<silver_messages.global.report>(agentReports);
|
||||
//Telefranz.Instance.ProduceMessage(new silver_messages.global.sound_off());
|
||||
while (config.PreShow.AgentsNeeded.Where(ap => !agentsPresent.Contains(ap))?.Count() > 0)
|
||||
{
|
||||
checkSignal.WaitOne(TimeSpan.FromMinutes(1));
|
||||
if(DateTime.Now > evt.OccurrenceStart - AgentsRespondingBuffer)
|
||||
{
|
||||
var miaAgents = string.Join(", ", config.PreShow.AgentsNeeded.Where(ap => !agentsPresent.Contains(ap)));
|
||||
HumanCommunication.Instance.Say($"Youtube handler getting antsy and going forward. mia agents: {miaAgents}",
|
||||
HumanCommunication.LogLevel.Error);
|
||||
break;
|
||||
}
|
||||
}
|
||||
Console.WriteLine("going forward");
|
||||
}
|
||||
protected void preShow_RunChecks(iCalHoopJumping.CalendarOccurrence evt)
|
||||
{
|
||||
Console.WriteLine("pre show: run checks:");
|
||||
//TODO
|
||||
checksProgress.Clear();
|
||||
var argsList = new List<string>() { JsonConvert.SerializeObject(evt) };
|
||||
//Telefranz.Instance.addHandler()
|
||||
foreach (var c in config.PreShow.Checks)
|
||||
{
|
||||
checksProgress.Add(c.cmd, false);
|
||||
Telefranz.Instance.ProduceMessage(new silver_messages.directorial.execute_check()
|
||||
{
|
||||
check = c.cmd,
|
||||
args = argsList.Append(c.args).ToList()
|
||||
});
|
||||
}
|
||||
while (true)
|
||||
{
|
||||
checkSignal.WaitOne(TimeSpan.FromSeconds(45));
|
||||
|
||||
}
|
||||
// //await sound offs for some timeout
|
||||
// config.PreShow.AgentsNeeded;
|
||||
// //once that's ok, await checks
|
||||
// config.PreShow.Checks;
|
||||
// //once that's ok, await first command, then start running them
|
||||
// config.PreShow.Commands;
|
||||
}
|
||||
protected void preShow_RunCommands(iCalHoopJumping.CalendarOccurrence evt)
|
||||
{
|
||||
Console.WriteLine("pre show: run commands");
|
||||
}
|
||||
protected void agentReports(silver_messages.global.report r)
|
||||
{
|
||||
@ -65,6 +107,18 @@ namespace ShowHandlers
|
||||
}
|
||||
}
|
||||
}
|
||||
protected void checkReports(silver_messages.directorial.check_complete check)
|
||||
{
|
||||
var myCheck = config.PreShow.Checks.FirstOrDefault(psc => psc.cmd == check.check);
|
||||
if (myCheck != null)
|
||||
{
|
||||
lock (checksProgress)
|
||||
{
|
||||
checksProgress[myCheck.cmd] = check.result == myCheck.target;
|
||||
}
|
||||
checkSignal.Set();
|
||||
}
|
||||
}
|
||||
protected void PostShow(iCalHoopJumping.CalendarOccurrence evt)
|
||||
{
|
||||
Console.WriteLine("can't do this bit without understanding when a show ends, sooo.");
|
||||
|
Loading…
Reference in New Issue
Block a user