diff --git a/MinecraftClient/ChatBot.cs b/MinecraftClient/ChatBot.cs
index a3ae5ebb..579430cc 100644
--- a/MinecraftClient/ChatBot.cs
+++ b/MinecraftClient/ChatBot.cs
@@ -380,5 +380,29 @@ namespace MinecraftClient
time.Minute.ToString("00"),
time.Second.ToString("00"));
}
+
+ ///
+ /// Load entries from a file as a string array, removing duplicates and empty lines
+ ///
+ /// File to load
+ /// The string array or an empty array if failed to load the file
+
+ 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];
+ }
+ }
}
}
diff --git a/MinecraftClient/ChatBots/Alerts.cs b/MinecraftClient/ChatBots/Alerts.cs
index 5cdff088..cd21bae4 100644
--- a/MinecraftClient/ChatBots/Alerts.cs
+++ b/MinecraftClient/ChatBots/Alerts.cs
@@ -14,36 +14,13 @@ namespace MinecraftClient.ChatBots
private string[] dictionary = new string[0];
private string[] excludelist = new string[0];
- ///
- /// Import alerts from the specified file
- ///
- ///
- ///
- private static string[] FromFile(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];
- }
- }
-
///
/// Intitialize the Alerts bot
///
public override void Initialize()
{
- dictionary = FromFile(Settings.Alerts_MatchesFile);
- excludelist = FromFile(Settings.Alerts_ExcludesFile);
+ dictionary = LoadDistinctEntriesFromFile(Settings.Alerts_MatchesFile);
+ excludelist = LoadDistinctEntriesFromFile(Settings.Alerts_ExcludesFile);
}
///
diff --git a/MinecraftClient/ChatBots/Auto Respond.cs b/MinecraftClient/ChatBots/AutoRespond.cs
similarity index 50%
rename from MinecraftClient/ChatBots/Auto Respond.cs
rename to MinecraftClient/ChatBots/AutoRespond.cs
index c861241e..3a0d6575 100644
--- a/MinecraftClient/ChatBots/Auto Respond.cs
+++ b/MinecraftClient/ChatBots/AutoRespond.cs
@@ -6,34 +6,16 @@ using System.IO;
namespace MinecraftClient.ChatBots
{
- class Auto_Respond : ChatBot
+ class AutoRespond : ChatBot
{
- private String[] respondon = new String[0];
- private String[] torespond = new String[0];
-
- private static string[] FromFile(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: " + file);
- return new string[0];
- }
- }
+ private string[] respondon = new string[0];
+ private string[] torespond = new string[0];
//Initalize the bot
public override void Initialize()
{
- respondon = FromFile(Settings.Respond_MatchesFile);
- torespond = FromFile(Settings.Respond_RespondFile);
+ respondon = LoadDistinctEntriesFromFile(Settings.Respond_MatchesFile);
+ torespond = LoadDistinctEntriesFromFile(Settings.Respond_RespondFile);
ConsoleIO.WriteLine("Auto Respond Bot Sucessfully loaded!");
}
diff --git a/MinecraftClient/McTcpClient.cs b/MinecraftClient/McTcpClient.cs
index 6a991d96..3f152002 100644
--- a/MinecraftClient/McTcpClient.cs
+++ b/MinecraftClient/McTcpClient.cs
@@ -106,7 +106,7 @@ namespace MinecraftClient
if (Settings.AutoRelog_Enabled) { BotLoad(new ChatBots.AutoRelog(Settings.AutoRelog_Delay, Settings.AutoRelog_Retries)); }
if (Settings.ScriptScheduler_Enabled) { BotLoad(new ChatBots.ScriptScheduler(Settings.expandVars(Settings.ScriptScheduler_TasksFile))); }
if (Settings.RemoteCtrl_Enabled) { BotLoad(new ChatBots.RemoteControl()); }
- if (Settings.Respond_Enabled) { BotLoad(new ChatBots.Auto_Respond()); }
+ if (Settings.Respond_Enabled) { BotLoad(new ChatBots.AutoRespond()); }
}
try
diff --git a/MinecraftClient/MinecraftClient.csproj b/MinecraftClient/MinecraftClient.csproj
index 9ae1ccdc..8129d2ec 100644
--- a/MinecraftClient/MinecraftClient.csproj
+++ b/MinecraftClient/MinecraftClient.csproj
@@ -74,7 +74,7 @@
-
+