I think I mostly have an idea of how I want most of this to go
This commit is contained in:
parent
4fc8ef9a29
commit
c8a641f340
@ -1,3 +1,4 @@
|
|||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
|
||||||
namespace director
|
namespace director
|
||||||
@ -12,6 +13,7 @@ namespace director
|
|||||||
public string calendar_youtube { get; set; }
|
public string calendar_youtube { get; set; }
|
||||||
public string calendar_twitch { get; set; }
|
public string calendar_twitch { get; set; }
|
||||||
public string calendar_other { get; set; }
|
public string calendar_other { get; set; }
|
||||||
|
public TimeSpan preshowBufferTime { get; set; }
|
||||||
public Dictionary<string, string> phase_handlers { get; set; }
|
public Dictionary<string, string> phase_handlers { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
20
Log.cs
Normal file
20
Log.cs
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
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();
|
||||||
|
}
|
||||||
|
}
|
61
Program.cs
61
Program.cs
@ -1,9 +1,12 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Concurrent;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Net;
|
||||||
using System.Net.Http;
|
using System.Net.Http;
|
||||||
using System.Net.Http.Headers;
|
using System.Net.Http.Headers;
|
||||||
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using franz;
|
using franz;
|
||||||
using Ical.Net;
|
using Ical.Net;
|
||||||
@ -11,6 +14,7 @@ using Ical.Net.CalendarComponents;
|
|||||||
using Ical.Net.DataTypes;
|
using Ical.Net.DataTypes;
|
||||||
using Ical.Net.Serialization;
|
using Ical.Net.Serialization;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
|
using ShowHandlers;
|
||||||
|
|
||||||
namespace director
|
namespace director
|
||||||
{
|
{
|
||||||
@ -25,14 +29,21 @@ namespace director
|
|||||||
private static DateTime searchEnd = DateTime.Now.AddDays(7);
|
private static DateTime searchEnd = DateTime.Now.AddDays(7);
|
||||||
//I don't understand why the entire .net ecosystem insists on ignoring ToString(). Is it really that much fun writing a serializer factory? ...java programmers.
|
//I don't understand why the entire .net ecosystem insists on ignoring ToString(). Is it really that much fun writing a serializer factory? ...java programmers.
|
||||||
private static EventSerializer ser = new EventSerializer();
|
private static EventSerializer ser = new EventSerializer();
|
||||||
|
private static readonly ConcurrentQueue<Schedulable.Schedulable> workQueue = new ConcurrentQueue<Schedulable.Schedulable>();
|
||||||
|
private static readonly AutoResetEvent _signal = new AutoResetEvent(false);
|
||||||
|
private const int concurrentWorkers = 2;
|
||||||
static void Main(string[] args)
|
static void Main(string[] args)
|
||||||
{
|
{
|
||||||
if (!File.Exists("appsettings.json"))
|
if (!File.Exists("appsettings.json"))
|
||||||
{
|
{
|
||||||
Console.Error.WriteLine("appsettings.json was not found!");
|
Console.Error.WriteLine("appsettings.json was not found!");
|
||||||
|
conf = new Config();
|
||||||
|
File.WriteAllText("appsettings.json", JsonConvert.SerializeObject(conf, Formatting.Indented));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
conf = JsonConvert.DeserializeObject<Config>(File.ReadAllText("appsettings.json"));
|
conf = JsonConvert.DeserializeObject<Config>(File.ReadAllText("appsettings.json"));
|
||||||
|
Log.call_for_humans_discord_webhook = conf.call_for_humans_discord_webhook;
|
||||||
|
|
||||||
httpClient = new HttpClient();
|
httpClient = new HttpClient();
|
||||||
httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", Convert.ToBase64String(
|
httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", Convert.ToBase64String(
|
||||||
System.Text.Encoding.ASCII.GetBytes($"{conf.webdav_username}:{conf.webdav_password}")));
|
System.Text.Encoding.ASCII.GetBytes($"{conf.webdav_username}:{conf.webdav_password}")));
|
||||||
@ -40,16 +51,19 @@ namespace director
|
|||||||
|
|
||||||
scratch = Scratch.LoadScratch();
|
scratch = Scratch.LoadScratch();
|
||||||
|
|
||||||
|
for (var i = 0; i < concurrentWorkers; i++)
|
||||||
|
{
|
||||||
|
Task.Run(threadwork);
|
||||||
|
}
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
Task.WaitAll(
|
Task.WaitAll(
|
||||||
//await and do next calendar task,
|
checkCalendars(),
|
||||||
calendarCheck(),
|
|
||||||
Task.Delay(calendarNaptime)
|
Task.Delay(calendarNaptime)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private static async Task calendarCheck()
|
private static async Task checkCalendars()
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@ -80,10 +94,11 @@ namespace director
|
|||||||
|
|
||||||
foreach (var s in scratch.agenda)
|
foreach (var s in scratch.agenda)
|
||||||
{
|
{
|
||||||
if (s.Showtime - DateTime.Now <= calendarNaptime)
|
if ((s.Showtime - conf.preshowBufferTime) - DateTime.Now <= calendarNaptime)
|
||||||
{
|
{
|
||||||
Console.WriteLine("I'm an item on the agenda and showtime is near!");
|
var copy = JsonConvert.DeserializeObject<Schedulable.Schedulable>(JsonConvert.SerializeObject(s));
|
||||||
Console.WriteLine(s.Event);
|
workQueue.Enqueue(copy);
|
||||||
|
_signal.Set();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -115,5 +130,39 @@ namespace director
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
private static void threadwork()
|
||||||
|
{
|
||||||
|
Schedulable.Schedulable todo = null;
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
_signal.WaitOne(calendarNaptime);
|
||||||
|
|
||||||
|
if (!workQueue.TryDequeue(out todo)) { continue; }
|
||||||
|
|
||||||
|
Console.WriteLine("threadwork consumes!");
|
||||||
|
Task.Delay(todo.Showtime - conf.preshowBufferTime - DateTime.Now);
|
||||||
|
Console.WriteLine("time to prep!");
|
||||||
|
|
||||||
|
switch (todo.ScedulableType)
|
||||||
|
{
|
||||||
|
case Schedulable.ScedulableType.TwitchStream:
|
||||||
|
try
|
||||||
|
{
|
||||||
|
// var handler = new TwitchStreamHandler();
|
||||||
|
// handler.Handle();
|
||||||
|
}
|
||||||
|
catch(Exception e)
|
||||||
|
{
|
||||||
|
Log.Panic($"error in twitch stream handler! Panicking!\n{JsonConvert.SerializeObject(e)}");
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
// case Schedulable.ScedulableType.YTRelease:
|
||||||
|
// break;
|
||||||
|
default:
|
||||||
|
Log.Panic($"unknown schedulable type! abandoning!");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,5 +6,6 @@
|
|||||||
"webdav_password": "sw0rdf1sh",
|
"webdav_password": "sw0rdf1sh",
|
||||||
"calendar_youtube": "calendars/1wingedangle/youtube-channel_shared_by_adam",
|
"calendar_youtube": "calendars/1wingedangle/youtube-channel_shared_by_adam",
|
||||||
"calendar_twitch": "calendars/1wingedangle/twitch-channel_shared_by_adam",
|
"calendar_twitch": "calendars/1wingedangle/twitch-channel_shared_by_adam",
|
||||||
"calendar_other": "calendars/1wingedangle/other_shared_by_adam"
|
"calendar_other": "calendars/1wingedangle/other_shared_by_adam",
|
||||||
|
"preshowBufferTime": "04:00:00"
|
||||||
}
|
}
|
18
showHandlers/TwitchStreamHandler.cs
Normal file
18
showHandlers/TwitchStreamHandler.cs
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
using Ical.Net.CalendarComponents;
|
||||||
|
|
||||||
|
namespace ShowHandlers
|
||||||
|
{
|
||||||
|
public class TwitchStreamHandler
|
||||||
|
{
|
||||||
|
public TwitchStreamHandler(CalendarEvent evt)
|
||||||
|
{
|
||||||
|
Event = evt;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CalendarEvent Event { get; }
|
||||||
|
|
||||||
|
public void Handle()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user