mirror of
https://github.com/MCCTeam/Minecraft-Console-Client
synced 2025-11-07 17:36:07 +00:00
AutoRespond tests and fixes
- Automatically add [BotName] tags to log lines - Fix case handling and actionPrivate used for public messages - Add a sample file for basic and regex matches
This commit is contained in:
parent
3ce91188c7
commit
a6b3bf0481
6 changed files with 53 additions and 12 deletions
|
|
@ -296,13 +296,13 @@ namespace MinecraftClient
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Writes some text in the console. Nothing will be sent to the server.
|
/// Write some text in the console. Nothing will be sent to the server.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="text">Log text to write</param>
|
/// <param name="text">Log text to write</param>
|
||||||
|
|
||||||
public static void LogToConsole(object text)
|
public void LogToConsole(object text)
|
||||||
{
|
{
|
||||||
ConsoleIO.WriteLineFormatted("§8[BOT] " + text);
|
ConsoleIO.WriteLogLine(String.Format("[{0}] {1}", this.GetType().Name, text));
|
||||||
string logfile = Settings.ExpandVars(Settings.chatbotLogFile);
|
string logfile = Settings.ExpandVars(Settings.chatbotLogFile);
|
||||||
|
|
||||||
if (!String.IsNullOrEmpty(logfile))
|
if (!String.IsNullOrEmpty(logfile))
|
||||||
|
|
@ -393,7 +393,7 @@ namespace MinecraftClient
|
||||||
/// <param name="file">File to load</param>
|
/// <param name="file">File to load</param>
|
||||||
/// <returns>The string array or an empty array if failed to load the file</returns>
|
/// <returns>The string array or an empty array if failed to load the file</returns>
|
||||||
|
|
||||||
protected static string[] LoadDistinctEntriesFromFile(string file)
|
protected string[] LoadDistinctEntriesFromFile(string file)
|
||||||
{
|
{
|
||||||
if (File.Exists(file))
|
if (File.Exists(file))
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,6 @@ namespace MinecraftClient.ChatBots
|
||||||
{
|
{
|
||||||
private string matchesFile;
|
private string matchesFile;
|
||||||
private List<RespondRule> respondRules;
|
private List<RespondRule> respondRules;
|
||||||
private static string header = "[AutoRespond] ";
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Create a new AutoRespond bot
|
/// Create a new AutoRespond bot
|
||||||
|
|
@ -84,7 +83,7 @@ namespace MinecraftClient.ChatBots
|
||||||
}
|
}
|
||||||
else if (!String.IsNullOrEmpty(match))
|
else if (!String.IsNullOrEmpty(match))
|
||||||
{
|
{
|
||||||
if (message.Contains(match))
|
if (message.ToLower().Contains(match.ToLower()))
|
||||||
{
|
{
|
||||||
return (privateMsg
|
return (privateMsg
|
||||||
? actionPrivate
|
? actionPrivate
|
||||||
|
|
@ -137,7 +136,7 @@ namespace MinecraftClient.ChatBots
|
||||||
case "regex": matchRegex = new Regex(argValue); break;
|
case "regex": matchRegex = new Regex(argValue); break;
|
||||||
case "match": matchString = argValue; break;
|
case "match": matchString = argValue; break;
|
||||||
case "action": matchAction = argValue; break;
|
case "action": matchAction = argValue; break;
|
||||||
case "actionprivate": matchAction = argValue; break;
|
case "actionprivate": matchActionPrivate = argValue; break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -182,7 +181,7 @@ namespace MinecraftClient.ChatBots
|
||||||
public override void GetText(string text)
|
public override void GetText(string text)
|
||||||
{
|
{
|
||||||
//Remove colour codes
|
//Remove colour codes
|
||||||
text = GetVerbatim(text).ToLower();
|
text = GetVerbatim(text);
|
||||||
|
|
||||||
//Check if this is a valid message
|
//Check if this is a valid message
|
||||||
string sender = "", message = "";
|
string sender = "", message = "";
|
||||||
|
|
@ -200,10 +199,10 @@ namespace MinecraftClient.ChatBots
|
||||||
if (toPerform != null)
|
if (toPerform != null)
|
||||||
{
|
{
|
||||||
string response = null;
|
string response = null;
|
||||||
LogToConsole(header + toPerform);
|
LogToConsole(toPerform);
|
||||||
PerformInternalCommand(toPerform, ref response);
|
PerformInternalCommand(toPerform, ref response);
|
||||||
if (!String.IsNullOrEmpty(response))
|
if (!String.IsNullOrEmpty(response))
|
||||||
LogToConsole(header + response);
|
LogToConsole(response);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@ namespace MinecraftClient.Commands
|
||||||
{
|
{
|
||||||
if (hasArg(command))
|
if (hasArg(command))
|
||||||
{
|
{
|
||||||
ChatBot.LogToConsole(getArg(command));
|
ConsoleIO.WriteLogLine(getArg(command));
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
else return CMDDesc;
|
else return CMDDesc;
|
||||||
|
|
|
||||||
|
|
@ -326,6 +326,16 @@ namespace MinecraftClient
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Write a Minecraft Console Client Log line
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="text">Text of the log line</param>
|
||||||
|
|
||||||
|
public static void WriteLogLine(string text)
|
||||||
|
{
|
||||||
|
WriteLineFormatted("§8[MCC] " + text);
|
||||||
|
}
|
||||||
|
|
||||||
#region Subfunctions
|
#region Subfunctions
|
||||||
private static void ClearLineAndBuffer()
|
private static void ClearLineAndBuffer()
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -163,7 +163,7 @@ namespace MinecraftClient
|
||||||
{
|
{
|
||||||
if (AttemptsLeft > 0)
|
if (AttemptsLeft > 0)
|
||||||
{
|
{
|
||||||
ChatBot.LogToConsole("Waiting 5 seconds (" + AttemptsLeft + " attempts left)...");
|
ConsoleIO.WriteLogLine("Waiting 5 seconds (" + AttemptsLeft + " attempts left)...");
|
||||||
Thread.Sleep(5000); AttemptsLeft--; Program.Restart();
|
Thread.Sleep(5000); AttemptsLeft--; Program.Restart();
|
||||||
}
|
}
|
||||||
else if (!singlecommand && Settings.interactiveMode)
|
else if (!singlecommand && Settings.interactiveMode)
|
||||||
|
|
|
||||||
32
MinecraftClient/config/sample-matches.ini
Normal file
32
MinecraftClient/config/sample-matches.ini
Normal file
|
|
@ -0,0 +1,32 @@
|
||||||
|
# Minecraft Console Client
|
||||||
|
# AutoRespond matches
|
||||||
|
# Example config file
|
||||||
|
|
||||||
|
# Structure of a match: [Match] Followed by the match and action
|
||||||
|
# The match can be a simple match or an advanced regular expression
|
||||||
|
# You can define a different action if the match was in a private message
|
||||||
|
# You can use $u for username of the player triggering the match
|
||||||
|
# Regex matches are also supported eg $1, $2, $3.. in actions
|
||||||
|
|
||||||
|
# Simple example: Respond to a message containing a keyword
|
||||||
|
|
||||||
|
[Match]
|
||||||
|
match=hi
|
||||||
|
action=send hi, $u!
|
||||||
|
actionprivate=send /tell $u Hello!
|
||||||
|
|
||||||
|
# Advanced example: Use a regular expression
|
||||||
|
|
||||||
|
[Match]
|
||||||
|
regex=^.*hello ([a-zA-Z0-9_]+).*$
|
||||||
|
action=send hello too, $1!
|
||||||
|
|
||||||
|
# You can also use any other internal command
|
||||||
|
# Private action is optional
|
||||||
|
|
||||||
|
[Match]
|
||||||
|
match=dotest
|
||||||
|
action=script test
|
||||||
|
|
||||||
|
# Enjoy!
|
||||||
|
# - ORelio
|
||||||
Loading…
Add table
Add a link
Reference in a new issue