From 8fa439b232abd1b889ce5bed345c99cd1f8a2017 Mon Sep 17 00:00:00 2001 From: Adam R Grey Date: Wed, 16 Nov 2022 13:07:21 -0500 Subject: [PATCH] don't trip over empty lines --- Features.cs | 5 +++++ Program.cs | 4 +++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/Features.cs b/Features.cs index f3ca4a2..9cc269b 100644 --- a/Features.cs +++ b/Features.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.IO; +using System.Linq; using System.Net; using System.Text; using System.Threading; @@ -130,6 +131,10 @@ namespace silverworker_discord public static async void Joke(SocketUserMessage message) { var jokes = File.ReadAllLines("jokes.txt"); + jokes = jokes.Where(l => !string.IsNullOrWhiteSpace(l))?.ToArray(); + if(jokes?.Length == 0){ + await message.Channel.SendMessageAsync("I don't know any. Adam!"); + } var thisJoke = jokes[r.Next(jokes.Length)]; if (thisJoke.Contains("?") && !thisJoke.EndsWith('?')) { diff --git a/Program.cs b/Program.cs index 5fed7f3..8faadf8 100644 --- a/Program.cs +++ b/Program.cs @@ -34,6 +34,7 @@ namespace silverworker_discord } public async Task MainAsync() { + #if !DEBUG Process[] processes = Process.GetProcesses(); Process currentProc = Process.GetCurrentProcess(); Console.WriteLine("Current proccess: {0}", currentProc.ProcessName); @@ -41,10 +42,11 @@ namespace silverworker_discord { if (currentProc.ProcessName == process.ProcessName && currentProc.Id != process.Id) { - Console.Error.WriteLine($"{DateTime.Now} - Another instance of this process is already running: {process.Id}"); + Console.Error.WriteLine($"{DateTime.Now} - Another instance of this process is already running: {process.Id} (I'm {currentProc.Id})"); return; } } + #endif _client = new DiscordSocketClient();