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

Added an option to match by colors in Auto Respond bot.
This commit is contained in:
Anon 2022-09-21 16:03:38 +00:00 committed by GitHub
commit c945a33f8f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 37 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,7 +264,8 @@ namespace MinecraftClient.ChatBots
public override void GetText(string text) public override void GetText(string text)
{ {
//Remove colour codes //Remove colour codes
text = GetVerbatim(text); if (!this.matchColors)
text = GetVerbatim(text);
//Get Message type //Get Message type
string sender = "", message = ""; string sender = "", message = "";

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

@ -145,7 +145,7 @@ namespace MinecraftClient
/// <param name="text">Text from the server</param> /// <param name="text">Text from the server</param>
/// <param name="json">Raw JSON from the server. This parameter will be NULL on MC 1.5 or lower!</param> /// <param name="json">Raw JSON from the server. This parameter will be NULL on MC 1.5 or lower!</param>
public virtual void GetText(string text, string? json) { } public virtual void GetText(string text, string? json) { }
/// <summary> /// <summary>
/// Is called when the client has been disconnected fom the server /// Is called when the client has been disconnected fom the server
/// </summary> /// </summary>
@ -245,7 +245,7 @@ namespace MinecraftClient
/// <param name="uuid">Player UUID</param> /// <param name="uuid">Player UUID</param>
/// <param name="gamemode">New Game Mode (0: Survival, 1: Creative, 2: Adventure, 3: Spectator).</param> /// <param name="gamemode">New Game Mode (0: Survival, 1: Creative, 2: Adventure, 3: Spectator).</param>
public virtual void OnGamemodeUpdate(string playername, Guid uuid, int gamemode) { } public virtual void OnGamemodeUpdate(string playername, Guid uuid, int gamemode) { }
/// <summary> /// <summary>
/// Called when the Latency has been updated for a player /// Called when the Latency has been updated for a player
/// </summary> /// </summary>
@ -253,7 +253,7 @@ namespace MinecraftClient
/// <param name="uuid">Player UUID</param> /// <param name="uuid">Player UUID</param>
/// <param name="latency">Latency.</param> /// <param name="latency">Latency.</param>
public virtual void OnLatencyUpdate(string playername, Guid uuid, int latency) { } public virtual void OnLatencyUpdate(string playername, Guid uuid, int latency) { }
/// <summary> /// <summary>
/// Called when the Latency has been updated for a player /// Called when the Latency has been updated for a player
/// </summary> /// </summary>
@ -262,7 +262,7 @@ namespace MinecraftClient
/// <param name="uuid">Player UUID</param> /// <param name="uuid">Player UUID</param>
/// <param name="latency">Latency.</param> /// <param name="latency">Latency.</param>
public virtual void OnLatencyUpdate(Entity entity, string playername, Guid uuid, int latency) { } public virtual void OnLatencyUpdate(Entity entity, string playername, Guid uuid, int latency) { }
/// <summary> /// <summary>
/// Called when a map was updated /// Called when a map was updated
/// </summary> /// </summary>
@ -319,7 +319,7 @@ namespace MinecraftClient
/// <param name="objectivevalue">Only if mode is 0 or 2. The text to be displayed for the score</param> /// <param name="objectivevalue">Only if mode is 0 or 2. The text to be displayed for the score</param>
/// <param name="type">Only if mode is 0 or 2. 0 = "integer", 1 = "hearts".</param> /// <param name="type">Only if mode is 0 or 2. 0 = "integer", 1 = "hearts".</param>
public virtual void OnScoreboardObjective(string objectivename, byte mode, string objectivevalue, int type, string json) { } public virtual void OnScoreboardObjective(string objectivename, byte mode, string objectivevalue, int type, string json) { }
/// <summary> /// <summary>
/// Called when a scoreboard updated /// Called when a scoreboard updated
/// </summary> /// </summary>
@ -360,12 +360,12 @@ namespace MinecraftClient
/// <param name="uuid">UUID of the player</param> /// <param name="uuid">UUID of the player</param>
/// <param name="name">Name of the player</param> /// <param name="name">Name of the player</param>
public virtual void OnPlayerLeave(Guid uuid, string? name) { } public virtual void OnPlayerLeave(Guid uuid, string? name) { }
/// <summary> /// <summary>
/// Called when the player deaths /// Called when the player deaths
/// </summary> /// </summary>
public virtual void OnDeath() { } public virtual void OnDeath() { }
/// <summary> /// <summary>
/// Called when the player respawns /// Called when the player respawns
/// </summary> /// </summary>
@ -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;
@ -950,7 +950,7 @@ namespace MinecraftClient
return Handler.GetWorld(); return Handler.GetWorld();
return null; return null;
} }
/// <summary> /// <summary>
/// Get all Entities /// Get all Entities
/// </summary> /// </summary>
@ -968,7 +968,7 @@ namespace MinecraftClient
{ {
return Handler.GetPlayersLatency(); return Handler.GetPlayersLatency();
} }
/// <summary> /// <summary>
/// Get the current location of the player (Feet location) /// Get the current location of the player (Feet location)
/// </summary> /// </summary>
@ -1002,7 +1002,7 @@ namespace MinecraftClient
{ {
return Handler.ClientIsMoving(); return Handler.ClientIsMoving();
} }
/// <summary> /// <summary>
/// Look at the specified location /// Look at the specified location
/// </summary> /// </summary>
@ -1086,7 +1086,7 @@ namespace MinecraftClient
{ {
return Handler.GetUsername(); return Handler.GetUsername();
} }
/// <summary> /// <summary>
/// Return the Gamemode of the current account /// Return the Gamemode of the current account
/// </summary> /// </summary>
@ -1361,7 +1361,7 @@ namespace MinecraftClient
{ {
return Handler.GetCurrentSlot(); return Handler.GetCurrentSlot();
} }
/// <summary> /// <summary>
/// Clean all inventory /// Clean all inventory
/// </summary> /// </summary>
@ -1370,7 +1370,7 @@ namespace MinecraftClient
{ {
return Handler.ClearInventories(); return Handler.ClearInventories();
} }
/// <summary> /// <summary>
/// Update sign text /// Update sign text
/// </summary> /// </summary>
@ -1410,7 +1410,7 @@ namespace MinecraftClient
{ {
return Handler.SpectateByUUID(UUID); return Handler.SpectateByUUID(UUID);
} }
/// <summary> /// <summary>
/// Update command block /// Update command block
/// </summary> /// </summary>
@ -1456,7 +1456,7 @@ namespace MinecraftClient
{ {
return Handler.GetMaxChatMessageLength(); return Handler.GetMaxChatMessageLength();
} }
/// <summary> /// <summary>
/// Respawn player /// Respawn player
/// </summary> /// </summary>

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;
@ -206,7 +207,7 @@ namespace MinecraftClient
public static bool AutoFishing_Mainhand = true; public static bool AutoFishing_Mainhand = true;
public static bool AutoFishing_AutoStart = true; public static bool AutoFishing_AutoStart = true;
public static double AutoFishing_CastDelay = 0.4; public static double AutoFishing_CastDelay = 0.4;
public static double AutoFishing_FishingDelay = 3.0; public static double AutoFishing_FishingDelay = 3.0;
public static double AutoFishing_FishingTimeout = 300.0; public static double AutoFishing_FishingTimeout = 300.0;
public static double AutoFishing_DurabilityLimit = 2; public static double AutoFishing_DurabilityLimit = 2;
public static bool AutoFishing_AutoRodSwitch = true; public static bool AutoFishing_AutoRodSwitch = true;
@ -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;
@ -733,7 +735,7 @@ namespace MinecraftClient
case "fishing_delay": AutoFishing_FishingDelay = str2double(argValue); return true; case "fishing_delay": AutoFishing_FishingDelay = str2double(argValue); return true;
case "fishing_timeout": AutoFishing_FishingTimeout = str2double(argValue); return true; case "fishing_timeout": AutoFishing_FishingTimeout = str2double(argValue); return true;
case "durability_limit": AutoFishing_DurabilityLimit = str2int(argValue); return true; case "durability_limit": AutoFishing_DurabilityLimit = str2int(argValue); return true;
case "auto_rod_switch": AutoFishing_AutoRodSwitch = str2bool(argValue); return true; case "auto_rod_switch": AutoFishing_AutoRodSwitch = str2bool(argValue); return true;
case "stationary_threshold": AutoFishing_StationaryThreshold = str2double(argValue); return true; case "stationary_threshold": AutoFishing_StationaryThreshold = str2double(argValue); return true;
case "hook_threshold": AutoFishing_HookThreshold = str2double(argValue); return true; case "hook_threshold": AutoFishing_HookThreshold = str2double(argValue); return true;
case "log_fishing_bobber": AutoFishing_LogFishingBobber = str2bool(argValue); return true; case "log_fishing_bobber": AutoFishing_LogFishingBobber = str2bool(argValue); return true;

View file

@ -63,5 +63,12 @@ match=hello
action=send hello! action=send hello!
cooldown=60 cooldown=60
# Example of matching colored text when "matchcolors" is set to "true"
# §a stands for green text
# List of all color codes: https://minecraft.tools/en/color-code.php
[Match]
match=§ahello
action=send Hello back!
# Enjoy! # Enjoy!
# - ORelio # - ORelio