Normalize AutoRespond bot

Move FromFile method from bots to ChatBot class
Rename file and class, removing space and underscore.
This commit is contained in:
ORelio 2015-05-26 19:16:50 +02:00
parent b07091e3dd
commit 53156bdf98
5 changed files with 33 additions and 50 deletions

View file

@ -380,5 +380,29 @@ namespace MinecraftClient
time.Minute.ToString("00"),
time.Second.ToString("00"));
}
/// <summary>
/// Load entries from a file as a string array, removing duplicates and empty lines
/// </summary>
/// <param name="file">File to load</param>
/// <returns>The string array or an empty array if failed to load the file</returns>
protected static string[] LoadDistinctEntriesFromFile(string file)
{
if (File.Exists(file))
{
//Read all lines from file, remove lines with no text, convert to lowercase,
//remove duplicate entries, convert to a string array, and return the result.
return File.ReadAllLines(file)
.Where(line => !String.IsNullOrWhiteSpace(line))
.Select(line => line.ToLower())
.Distinct().ToArray();
}
else
{
LogToConsole("File not found: " + Settings.Alerts_MatchesFile);
return new string[0];
}
}
}
}