2021-09-03 03:38:21 -04:00
using System ;
using System.IO ;
using System.Net ;
namespace Director
{
public class HumanCommunication
{
2021-09-03 07:18:38 -04:00
private static string call_for_humans_discord_webhook { get ; set ; }
2021-09-03 03:38:21 -04:00
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}" ) ;
2021-09-03 04:22:51 -04:00
//if(logLevel >= LogLevel.Warning && false)
2021-09-03 07:18:38 -04:00
if ( false ) //TODO: re-enable
2021-09-03 03:38:21 -04:00
{
2021-09-03 04:22:51 -04:00
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 ( ) ;
2021-09-03 03:38:21 -04:00
}
}
2021-09-03 07:18:38 -04:00
public enum LogLevel
{
Trace , //development
Verbose ,
Info , //archival purposes, status checking, curiosity satisfaciton
Warning ,
Error , //it's going to go up, but look bad. The bar is (currently) low enough that this won't necessarily damage the brand, but for better creators it would.
Showstopper //it's not going to go up
}
2021-09-03 03:38:21 -04:00
}
public class NotInitializedException : Exception
{
public NotInitializedException ( string message ) : base ( message ) { }
}
}