Ejemplo n.º 1
0
        public static async Task Main()
        {
            var config = JsonSerializer.Deserialize <Config>(await File.ReadAllTextAsync("./config.json"));

            Console.WriteLine("g");
            var discord = new DiscordWebhookClient(config !.WebhookId, config.WebhookToken);

            Console.WriteLine("r");
            var eventClient = new IpcClient(Environment.GetEnvironmentVariable("JAND_PIPE") ??
                                            JanD.Program.DefaultPipeName);
            var client = new IpcClient(Environment.GetEnvironmentVariable("JAND_PIPE") ??
                                       JanD.Program.DefaultPipeName);

            Console.WriteLine("b");
            Console.WriteLine(eventClient.RequestString("subscribe-events", "255"));
            Console.WriteLine("h");
            eventClient.ListenEvents(ev =>
            {
                Console.WriteLine(ev.Event);
                JanD.Program.JanDRuntimeProcess info;
                try
                {
                    info = client.RequestJson <JanD.Program.JanDRuntimeProcess>("get-process-info", ev.Process);
                }
                catch
                {
                    info = null;
                }

#pragma warning disable 4014
                discord.SendMessageAsync(embeds: new List <DiscordEmbed>
#pragma warning restore 4014
                {
                    new()
                    {
                        Title = ev !.Event switch
                        {
                            "procstart" => "Process Started",
                            "procdel" => "Process Deleted",
                            "procadd" => "Process Added",
                            "procstop" => "Process Stopped",
                            "procren" => "Process Renamed",
                            "procprop" => "Process Property Updated",
                            _ => ev.Event
                        },
                        Description = ev.Event switch
                        {
                            "procstart" => $"`{ev.Process}` has started.",
                            "procdel" => $"`{ev.Process}` has been deleted.",
                            "procadd" => @$ "`{ev.Process}` has been added.
        **Command:** `{info.Command}`
        **Directory:** `{info.WorkingDirectory}`",
                            "procstop" => @$ "`{ev.Process}` has stopped.
        **Exit Code:** `{info.ExitCode}`",
                            "procren" => $@"`{ev.Process}` => `{ev.Value}`",
                            "procprop" => $@"`{ev.Process}`
Property `{ev.Value[..ev.Value.IndexOf(':')]}` changed to `{ev.Value[(ev.Value.IndexOf(':') + 1)..]}`",