don't trip over empty lines

This commit is contained in:
Adam R Grey 2022-11-16 13:07:21 -05:00
parent 751ecf2e30
commit 8fa439b232
2 changed files with 8 additions and 1 deletions

View File

@ -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('?'))
{

View File

@ -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();