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
{
private string matchesFile;
private bool matchColors;
private List<RespondRule> respondRules;
private enum MessageType { Public, Private, Other };
@ -19,9 +20,10 @@ namespace MinecraftClient.ChatBots
/// Create a new AutoRespond bot
/// </summary>
/// <param name="matchesFile">INI File to load matches from</param>
public AutoRespond(string matchesFile)
public AutoRespond(string matchesFile, bool matchColors)
{
this.matchesFile = matchesFile;
this.matchColors = matchColors;
}
/// <summary>
@ -262,6 +264,7 @@ namespace MinecraftClient.ChatBots
public override void GetText(string text)
{
//Remove colour codes
if (!this.matchColors)
text = GetVerbatim(text);
//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.ScriptScheduler_Enabled) { BotLoad(new ChatBots.ScriptScheduler(Settings.ExpandVars(Settings.ScriptScheduler_TasksFile))); }
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.AutoFishing_Enabled) { BotLoad(new ChatBots.AutoFishing()); }
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
enabled=false
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]
# Automatically attack hostile mobs around you

View file

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

View file

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

View file

@ -63,5 +63,12 @@ match=hello
action=send hello!
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!
# - ORelio