Added an option to match by colors in Auto Respond bot.

This commit is contained in:
Milutinke 2022-09-21 17:56:29 +02:00
parent b5cf315ca1
commit 0d58887b6a
5 changed files with 30 additions and 24 deletions

View file

@ -12,6 +12,7 @@ namespace MinecraftClient.ChatBots
class AutoRespond : ChatBot class AutoRespond : ChatBot
{ {
private string matchesFile; private string matchesFile;
private bool matchColors;
private List<RespondRule> respondRules; private List<RespondRule> respondRules;
private enum MessageType { Public, Private, Other }; private enum MessageType { Public, Private, Other };
@ -19,9 +20,10 @@ namespace MinecraftClient.ChatBots
/// Create a new AutoRespond bot /// Create a new AutoRespond bot
/// </summary> /// </summary>
/// <param name="matchesFile">INI File to load matches from</param> /// <param name="matchesFile">INI File to load matches from</param>
public AutoRespond(string matchesFile) public AutoRespond(string matchesFile, bool matchColors)
{ {
this.matchesFile = matchesFile; this.matchesFile = matchesFile;
this.matchColors = matchColors;
} }
/// <summary> /// <summary>
@ -262,6 +264,7 @@ namespace MinecraftClient.ChatBots
public override void GetText(string text) public override void GetText(string text)
{ {
//Remove colour codes //Remove colour codes
if (!this.matchColors)
text = GetVerbatim(text); text = GetVerbatim(text);
//Get Message type //Get Message type

View file

@ -187,7 +187,7 @@ namespace MinecraftClient
if (Settings.AutoRelog_Enabled) { BotLoad(new ChatBots.AutoRelog(Settings.AutoRelog_Delay_Min, Settings.AutoRelog_Delay_Max, Settings.AutoRelog_Retries)); } if (Settings.AutoRelog_Enabled) { BotLoad(new ChatBots.AutoRelog(Settings.AutoRelog_Delay_Min, Settings.AutoRelog_Delay_Max, Settings.AutoRelog_Retries)); }
if (Settings.ScriptScheduler_Enabled) { BotLoad(new ChatBots.ScriptScheduler(Settings.ExpandVars(Settings.ScriptScheduler_TasksFile))); } if (Settings.ScriptScheduler_Enabled) { BotLoad(new ChatBots.ScriptScheduler(Settings.ExpandVars(Settings.ScriptScheduler_TasksFile))); }
if (Settings.RemoteCtrl_Enabled) { BotLoad(new ChatBots.RemoteControl()); } if (Settings.RemoteCtrl_Enabled) { BotLoad(new ChatBots.RemoteControl()); }
if (Settings.AutoRespond_Enabled) { BotLoad(new ChatBots.AutoRespond(Settings.AutoRespond_Matches)); } if (Settings.AutoRespond_Enabled) { BotLoad(new ChatBots.AutoRespond(Settings.AutoRespond_Matches, Settings.AutoRespond_MatchColors)); }
if (Settings.AutoAttack_Enabled) { BotLoad(new ChatBots.AutoAttack(Settings.AutoAttack_Mode, Settings.AutoAttack_Priority, Settings.AutoAttack_OverrideAttackSpeed, Settings.AutoAttack_CooldownSeconds, Settings.AutoAttack_Interaction)); } if (Settings.AutoAttack_Enabled) { BotLoad(new ChatBots.AutoAttack(Settings.AutoAttack_Mode, Settings.AutoAttack_Priority, Settings.AutoAttack_OverrideAttackSpeed, Settings.AutoAttack_CooldownSeconds, Settings.AutoAttack_Interaction)); }
if (Settings.AutoFishing_Enabled) { BotLoad(new ChatBots.AutoFishing()); } if (Settings.AutoFishing_Enabled) { BotLoad(new ChatBots.AutoFishing()); }
if (Settings.AutoEat_Enabled) { BotLoad(new ChatBots.AutoEat(Settings.AutoEat_hungerThreshold)); } if (Settings.AutoEat_Enabled) { BotLoad(new ChatBots.AutoEat(Settings.AutoEat_hungerThreshold)); }

View file

@ -188,6 +188,7 @@ tpaccepteveryone=false
# /!\ This bot may get spammy depending on your rules, although the global messagecooldown setting can help you avoiding accidental spam # /!\ This bot may get spammy depending on your rules, although the global messagecooldown setting can help you avoiding accidental spam
enabled=false enabled=false
matchesfile=matches.ini matchesfile=matches.ini
matchcolors=false # Do not remove colors from text (Note: Your matches will have to include color codes (ones using the § character) in order to work)
[AutoAttack] [AutoAttack]
# Automatically attack hostile mobs around you # Automatically attack hostile mobs around you

View file

@ -451,14 +451,14 @@ namespace MinecraftClient
/// </summary> /// </summary>
public static string GetVerbatim(string text) public static string GetVerbatim(string text)
{ {
if ( String.IsNullOrEmpty(text) ) if (String.IsNullOrEmpty(text))
return String.Empty; return String.Empty;
int idx = 0; int idx = 0;
var data = new char[text.Length]; var data = new char[text.Length];
for ( int i = 0; i < text.Length; i++ ) for (int i = 0; i < text.Length; i++)
if ( text[i] != '§' ) if (text[i] != '§')
data[idx++] = text[i]; data[idx++] = text[i];
else else
i++; i++;
@ -478,7 +478,7 @@ namespace MinecraftClient
if (!((c >= 'a' && c <= 'z') if (!((c >= 'a' && c <= 'z')
|| (c >= 'A' && c <= 'Z') || (c >= 'A' && c <= 'Z')
|| (c >= '0' && c <= '9') || (c >= '0' && c <= '9')
|| c == '_') ) || c == '_'))
return false; return false;
return true; return true;

View file

@ -191,6 +191,7 @@ namespace MinecraftClient
//Auto Respond //Auto Respond
public static bool AutoRespond_Enabled = false; public static bool AutoRespond_Enabled = false;
public static string AutoRespond_Matches = "matches.ini"; public static string AutoRespond_Matches = "matches.ini";
public static bool AutoRespond_MatchColors = false;
//Auto Attack //Auto Attack
public static bool AutoAttack_Enabled = false; public static bool AutoAttack_Enabled = false;
@ -697,6 +698,7 @@ namespace MinecraftClient
{ {
case "enabled": AutoRespond_Enabled = str2bool(argValue); return true; case "enabled": AutoRespond_Enabled = str2bool(argValue); return true;
case "matchesfile": AutoRespond_Matches = argValue; return true; case "matchesfile": AutoRespond_Matches = argValue; return true;
case "matchcolors": AutoRespond_MatchColors = str2bool(argValue); return true;
} }
break; break;