mirror of
https://github.com/MCCTeam/Minecraft-Console-Client
synced 2025-10-14 21:22:49 +00:00
Allow restricting AutoRespond matches to bot owner
Suggestion by AppleCidar in #184
This commit is contained in:
parent
881e080fd6
commit
a4cc36ce05
4 changed files with 61 additions and 24 deletions
|
|
@ -33,6 +33,7 @@ namespace MinecraftClient.ChatBots
|
||||||
private string actionPublic;
|
private string actionPublic;
|
||||||
private string actionPrivate;
|
private string actionPrivate;
|
||||||
private string actionOther;
|
private string actionOther;
|
||||||
|
private bool ownersOnly;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Create a respond rule from a regex and a reponse message or command
|
/// Create a respond rule from a regex and a reponse message or command
|
||||||
|
|
@ -41,13 +42,15 @@ namespace MinecraftClient.ChatBots
|
||||||
/// <param name="actionPublic">Internal command to run for public messages</param>
|
/// <param name="actionPublic">Internal command to run for public messages</param>
|
||||||
/// <param name="actionPrivate">Internal command to run for private messages</param>
|
/// <param name="actionPrivate">Internal command to run for private messages</param>
|
||||||
/// <param name="actionOther">Internal command to run for any other messages</param>
|
/// <param name="actionOther">Internal command to run for any other messages</param>
|
||||||
public RespondRule(Regex regex, string actionPublic, string actionPrivate, string actionOther)
|
/// <param name="ownersOnly">Only match messages from bot owners</param>
|
||||||
|
public RespondRule(Regex regex, string actionPublic, string actionPrivate, string actionOther, bool ownersOnly)
|
||||||
{
|
{
|
||||||
this.regex = regex;
|
this.regex = regex;
|
||||||
this.match = null;
|
this.match = null;
|
||||||
this.actionPublic = actionPublic;
|
this.actionPublic = actionPublic;
|
||||||
this.actionPrivate = actionPrivate;
|
this.actionPrivate = actionPrivate;
|
||||||
this.actionOther = actionOther;
|
this.actionOther = actionOther;
|
||||||
|
this.ownersOnly = ownersOnly;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
@ -56,13 +59,15 @@ namespace MinecraftClient.ChatBots
|
||||||
/// <param name="match">Match string</param>
|
/// <param name="match">Match string</param>
|
||||||
/// <param name="actionPublic">Internal command to run for public messages</param>
|
/// <param name="actionPublic">Internal command to run for public messages</param>
|
||||||
/// <param name="actionPrivate">Internal command to run for private messages</param>
|
/// <param name="actionPrivate">Internal command to run for private messages</param>
|
||||||
public RespondRule(string match, string actionPublic, string actionPrivate, string actionOther)
|
/// <param name="ownersOnly">Only match messages from bot owners</param>
|
||||||
|
public RespondRule(string match, string actionPublic, string actionPrivate, string actionOther, bool ownersOnly)
|
||||||
{
|
{
|
||||||
this.regex = null;
|
this.regex = null;
|
||||||
this.match = match;
|
this.match = match;
|
||||||
this.actionPublic = actionPublic;
|
this.actionPublic = actionPublic;
|
||||||
this.actionPrivate = actionPrivate;
|
this.actionPrivate = actionPrivate;
|
||||||
this.actionOther = actionOther;
|
this.actionOther = actionOther;
|
||||||
|
this.ownersOnly = ownersOnly;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
@ -76,6 +81,9 @@ namespace MinecraftClient.ChatBots
|
||||||
{
|
{
|
||||||
string toSend = null;
|
string toSend = null;
|
||||||
|
|
||||||
|
if (ownersOnly && (String.IsNullOrEmpty(username) || !Settings.Bots_Owners.Contains(username.ToLower())))
|
||||||
|
return null;
|
||||||
|
|
||||||
switch (msgType)
|
switch (msgType)
|
||||||
{
|
{
|
||||||
case MessageType.Public: toSend = actionPublic; break;
|
case MessageType.Public: toSend = actionPublic; break;
|
||||||
|
|
@ -121,6 +129,7 @@ namespace MinecraftClient.ChatBots
|
||||||
string matchAction = null;
|
string matchAction = null;
|
||||||
string matchActionPrivate = null;
|
string matchActionPrivate = null;
|
||||||
string matchActionOther = null;
|
string matchActionOther = null;
|
||||||
|
bool ownersOnly = false;
|
||||||
respondRules = new List<RespondRule>();
|
respondRules = new List<RespondRule>();
|
||||||
|
|
||||||
foreach (string lineRAW in File.ReadAllLines(matchesFile))
|
foreach (string lineRAW in File.ReadAllLines(matchesFile))
|
||||||
|
|
@ -133,12 +142,13 @@ namespace MinecraftClient.ChatBots
|
||||||
switch (line.Substring(1, line.Length - 2).ToLower())
|
switch (line.Substring(1, line.Length - 2).ToLower())
|
||||||
{
|
{
|
||||||
case "match":
|
case "match":
|
||||||
CheckAddMatch(matchRegex, matchString, matchAction, matchActionPrivate, matchActionOther);
|
CheckAddMatch(matchRegex, matchString, matchAction, matchActionPrivate, matchActionOther, ownersOnly);
|
||||||
matchRegex = null;
|
matchRegex = null;
|
||||||
matchString = null;
|
matchString = null;
|
||||||
matchAction = null;
|
matchAction = null;
|
||||||
matchActionPrivate = null;
|
matchActionPrivate = null;
|
||||||
matchActionOther = null;
|
matchActionOther = null;
|
||||||
|
ownersOnly = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -155,12 +165,13 @@ namespace MinecraftClient.ChatBots
|
||||||
case "action": matchAction = argValue; break;
|
case "action": matchAction = argValue; break;
|
||||||
case "actionprivate": matchActionPrivate = argValue; break;
|
case "actionprivate": matchActionPrivate = argValue; break;
|
||||||
case "actionother": matchActionOther = argValue; break;
|
case "actionother": matchActionOther = argValue; break;
|
||||||
|
case "ownersonly": ownersOnly = Settings.str2bool(argValue); break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
CheckAddMatch(matchRegex, matchString, matchAction, matchActionPrivate, matchActionOther);
|
CheckAddMatch(matchRegex, matchString, matchAction, matchActionPrivate, matchActionOther, ownersOnly);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
@ -176,17 +187,18 @@ namespace MinecraftClient.ChatBots
|
||||||
/// <param name="matchString">Matching string</param>
|
/// <param name="matchString">Matching string</param>
|
||||||
/// <param name="matchAction">Action if the matching message is public</param>
|
/// <param name="matchAction">Action if the matching message is public</param>
|
||||||
/// <param name="matchActionPrivate">Action if the matching message is private</param>
|
/// <param name="matchActionPrivate">Action if the matching message is private</param>
|
||||||
private void CheckAddMatch(Regex matchRegex, string matchString, string matchAction, string matchActionPrivate, string matchActionOther)
|
/// <param name="ownersOnly">Only match messages from bot owners</param>
|
||||||
|
private void CheckAddMatch(Regex matchRegex, string matchString, string matchAction, string matchActionPrivate, string matchActionOther, bool ownersOnly)
|
||||||
{
|
{
|
||||||
if (matchAction != null || matchActionPrivate != null || matchActionOther != null)
|
if (matchAction != null || matchActionPrivate != null || matchActionOther != null)
|
||||||
{
|
{
|
||||||
if (matchRegex != null)
|
if (matchRegex != null)
|
||||||
{
|
{
|
||||||
respondRules.Add(new RespondRule(matchRegex, matchAction, matchActionPrivate, matchActionOther));
|
respondRules.Add(new RespondRule(matchRegex, matchAction, matchActionPrivate, matchActionOther, ownersOnly));
|
||||||
}
|
}
|
||||||
else if (matchString != null)
|
else if (matchString != null)
|
||||||
{
|
{
|
||||||
respondRules.Add(new RespondRule(matchString, matchAction, matchActionPrivate, matchActionOther));
|
respondRules.Add(new RespondRule(matchString, matchAction, matchActionPrivate, matchActionOther, ownersOnly));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -196,7 +196,8 @@ namespace MinecraftClient
|
||||||
case "botowners":
|
case "botowners":
|
||||||
Bots_Owners.Clear();
|
Bots_Owners.Clear();
|
||||||
foreach (string name in argValue.ToLower().Split(','))
|
foreach (string name in argValue.ToLower().Split(','))
|
||||||
Bots_Owners.Add(name.Trim());
|
if (!String.IsNullOrWhiteSpace(name))
|
||||||
|
Bots_Owners.Add(name.Trim());
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "internalcmdchar":
|
case "internalcmdchar":
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,7 @@ If Mono crashes, retry with mono-complete, not mono-runtime. Mono v4.0 to 4.2 is
|
||||||
Using Configuration files & Enabling bots
|
Using Configuration files & Enabling bots
|
||||||
===========================================
|
===========================================
|
||||||
|
|
||||||
Simply open the INI file with a text editor and change the values.
|
Simply open the INI configuration file with a text editor and change the values.
|
||||||
To enable a bot change the "enabled" value in the INI file from "false" to "true".
|
To enable a bot change the "enabled" value in the INI file from "false" to "true".
|
||||||
You will still be able to send and receive chat messages when a bot is loaded.
|
You will still be able to send and receive chat messages when a bot is loaded.
|
||||||
You can remove or comment some lines from the INI file to use the default values instead.
|
You can remove or comment some lines from the INI file to use the default values instead.
|
||||||
|
|
@ -34,6 +34,8 @@ You can have several INI files and drag & drop one of them over MinecraftClient.
|
||||||
|
|
||||||
> MinecraftClient.exe username password server
|
> MinecraftClient.exe username password server
|
||||||
This will automatically connect you to the chosen server.
|
This will automatically connect you to the chosen server.
|
||||||
|
To specify a server and ask password interactively, use "" as password.
|
||||||
|
To specify offline mode with no password, use "-" as password.
|
||||||
|
|
||||||
> MinecraftClient.exe username password server "/mycommand"
|
> MinecraftClient.exe username password server "/mycommand"
|
||||||
This will automatically send "/mycommand" to the server and close.
|
This will automatically send "/mycommand" to the server and close.
|
||||||
|
|
@ -61,6 +63,7 @@ In scripts and remote control, no slash is needed to perform the command.
|
||||||
- send <text> : send a message or a command to the server
|
- send <text> : send a message or a command to the server
|
||||||
- respawn : Use this to respawn if you are dead (like clicking "respawn" ingame)
|
- respawn : Use this to respawn if you are dead (like clicking "respawn" ingame)
|
||||||
- log <text> : display some text in the console (useful for scripts)
|
- log <text> : display some text in the console (useful for scripts)
|
||||||
|
- list : list players logged in to the server (uses tab list info sent by server)
|
||||||
- set varname=value : set a value which can be used as %varname% in further commands
|
- set varname=value : set a value which can be used as %varname% in further commands
|
||||||
- wait <time> : wait X ticks (10 ticks = ~1 second. Only for scripts)
|
- wait <time> : wait X ticks (10 ticks = ~1 second. Only for scripts)
|
||||||
- move : used for moving when terrain and movements feature is enabled
|
- move : used for moving when terrain and movements feature is enabled
|
||||||
|
|
@ -85,18 +88,22 @@ Once you have created your files, fill the 'accountlist' and 'serverlist' fields
|
||||||
======================================
|
======================================
|
||||||
|
|
||||||
By default, Minecraft Console Client cannot interact with the world around you.
|
By default, Minecraft Console Client cannot interact with the world around you.
|
||||||
However for some versions of the game you can enabl the terrainandmovements settings.
|
However for some versions of the game you can enable the terrainandmovements setting.
|
||||||
Please note that this regquires much more RAM, a bit more CPU, and slightly more bandwidth.
|
|
||||||
This will allow you to properly fall on ground, pickup items and move around.
|
This feature will allow you to properly fall on ground, pickup items and move around.
|
||||||
There is a C# API for reading the terrain data and moving from C# scripts.
|
There is a C# API for reading terrain data around the player and moving from C# scripts.
|
||||||
|
|
||||||
|
Please note that this requires much more RAM to store all the terrain data, a bit more CPU
|
||||||
|
to process all of this, and slightly more bandwidth as locations updates are
|
||||||
|
sent back to the server in a spammy way (that's how Minecraft works).
|
||||||
|
|
||||||
============================
|
============================
|
||||||
How to write a script file
|
How to write a script file
|
||||||
============================
|
============================
|
||||||
|
|
||||||
A script can be launched by using /script <filename> in the client
|
A script file can be launched by using /script <filename> in the client's command prompt.
|
||||||
The client will automatically look for your script in the current directory or "scripts" subfolder.
|
The client will automatically look for your script in the current directory or "scripts" subfolder.
|
||||||
If the file extension is .txt, you may omit it and the client will still find the script
|
If the file extension is .txt or .cs, you may omit it and the client will still find the script.
|
||||||
|
|
||||||
Regarding the script file, it is a text file with one instruction per line.
|
Regarding the script file, it is a text file with one instruction per line.
|
||||||
Any line beginning with "#" is ignored and treated as a comment.
|
Any line beginning with "#" is ignored and treated as a comment.
|
||||||
|
|
@ -111,11 +118,11 @@ The following read-only variables can also be used: %username%, %serverip%, %ser
|
||||||
|
|
||||||
If you are experienced with C#, you may also write a C# script.
|
If you are experienced with C#, you may also write a C# script.
|
||||||
That's a bit more involved, but way more powerful than regular scripts.
|
That's a bit more involved, but way more powerful than regular scripts.
|
||||||
You can look to the provided sample C# scripts for getting started.
|
You can look at the provided sample C# scripts for getting started.
|
||||||
|
|
||||||
C# scripts can be used for creating your own ChatBot without recompiling the whole project.
|
C# scripts can be used for creating your own ChatBot without recompiling the whole project.
|
||||||
These bots are embedded in a script file, which is compiled and loaded on the fly.
|
These bots are embedded in a script file, which is compiled and loaded on the fly.
|
||||||
ChatBots can access plugin channels for communicating with your own plugin.
|
ChatBots can access plugin channels for communicating with some server plugins.
|
||||||
|
|
||||||
For knowing everything the API has to offer, you can look at CSharpRunner.cs and ChatBot.cs.
|
For knowing everything the API has to offer, you can look at CSharpRunner.cs and ChatBot.cs.
|
||||||
The latest version for these files can be found on the GitHub repository.
|
The latest version for these files can be found on the GitHub repository.
|
||||||
|
|
@ -126,16 +133,19 @@ The latest version for these files can be found on the GitHub repository.
|
||||||
|
|
||||||
If you are on a restricted network you might want to use some HTTP or SOCKS proxies.
|
If you are on a restricted network you might want to use some HTTP or SOCKS proxies.
|
||||||
To do so, find a proxy, enable proxying in INI file and fill in the relevant settings.
|
To do so, find a proxy, enable proxying in INI file and fill in the relevant settings.
|
||||||
Proxy with username/password authentication are supported but have not been tested.
|
Proxies with username/password authentication are supported but have not been tested.
|
||||||
|
Not every proxy will work for playing Minecraft, because of port 80/443 web browsing restrictions.
|
||||||
|
However you can choose to use a proxy for login only, most proxies should work in this mode.
|
||||||
|
|
||||||
=============================================
|
=============================================
|
||||||
Connecting to servers when ping is disabled
|
Connecting to servers when ping is disabled
|
||||||
=============================================
|
=============================================
|
||||||
|
|
||||||
On some server, the server list ping feature has been disabled, which prevents Minecraft Console Client
|
On some servers, the server list ping feature has been disabled, which prevents Minecraft Console Client
|
||||||
from pinging the server to determine the Minecraft version to use. To connect to this kind of servers,
|
from pinging the server to determine the Minecraft version to use. To connect to this kind of servers,
|
||||||
find out which Minecraft version is running on the server, and fill in the 'mcversion' field in INI file.
|
find out which Minecraft version is running on the server, and fill in the 'mcversion' field in INI file.
|
||||||
This will disable the ping step while connecting, but requires you to manually provide the version to use.
|
This will disable the ping step while connecting, but requires you to manually provide the version to use.
|
||||||
|
Recent versions of Minecraft Console Client may also prompt you for MC version in case of ping failure.
|
||||||
|
|
||||||
=========================
|
=========================
|
||||||
About translation files
|
About translation files
|
||||||
|
|
@ -144,7 +154,7 @@ This will disable the ping step while connecting, but requires you to manually p
|
||||||
When connecting to 1.6+ servers, you will need a translation file to display properly some chat messages.
|
When connecting to 1.6+ servers, you will need a translation file to display properly some chat messages.
|
||||||
These files describe how some messages should be printed depending on your preferred language.
|
These files describe how some messages should be printed depending on your preferred language.
|
||||||
The client will automatically load en_GB.lang from your Minecraft folder if Minecraft is installed on your
|
The client will automatically load en_GB.lang from your Minecraft folder if Minecraft is installed on your
|
||||||
computer, or download it from Mojang's servers. You may choose another language in the config file.
|
computer, or download it from Mojang's servers. You may choose another language in the configuration file.
|
||||||
|
|
||||||
=========================
|
=========================
|
||||||
Detecting chat messages
|
Detecting chat messages
|
||||||
|
|
@ -168,7 +178,7 @@ For example write Yourname in alerts and <Yourname> in alerts-exclude.txt
|
||||||
=========================
|
=========================
|
||||||
|
|
||||||
Write in kickmessages.txt some words, such as "Restarting" for example.
|
Write in kickmessages.txt some words, such as "Restarting" for example.
|
||||||
If the kick message contains one of them, you will be automatically re-connected
|
If the kick message contains one of them, you will automatically be re-connected.
|
||||||
A kick message "Connection has been lost." is generated by the console itself when connection is lost.
|
A kick message "Connection has been lost." is generated by the console itself when connection is lost.
|
||||||
A kick message "Login failed." is generated the same way when it failed to login to the server.
|
A kick message "Login failed." is generated the same way when it failed to login to the server.
|
||||||
A kick message "Failed to ping this IP." is generated when it failed to ping the server.
|
A kick message "Failed to ping this IP." is generated when it failed to ping the server.
|
||||||
|
|
@ -188,7 +198,8 @@ Please read sample-tasks.ini for learning how to make your own task file.
|
||||||
|
|
||||||
Use "/tell <bot username> start" to start the game.
|
Use "/tell <bot username> start" to start the game.
|
||||||
Don't forget to add your username in botowners INI setting if you want it to obey.
|
Don't forget to add your username in botowners INI setting if you want it to obey.
|
||||||
Edit the provided configuration files to customize the words and the owners.
|
Edit the provided configuration files to customize the words and the bot owners.
|
||||||
|
If it doesn't respond to bot owners, read the "Detecting chat messages" section.
|
||||||
|
|
||||||
==========================
|
==========================
|
||||||
Using the Remote Control
|
Using the Remote Control
|
||||||
|
|
@ -196,10 +207,14 @@ Edit the provided configuration files to customize the words and the owners.
|
||||||
|
|
||||||
When the remote control bot is enabled, you can send commands to your bot using whispers.
|
When the remote control bot is enabled, you can send commands to your bot using whispers.
|
||||||
Don't forget to add your username in botowners INI setting if you want it to obey.
|
Don't forget to add your username in botowners INI setting if you want it to obey.
|
||||||
|
If it doesn't respond to bot owners, read the "Detecting chat messages" section.
|
||||||
|
Please note that server admins can read what you type and output from the bot.
|
||||||
|
|
||||||
To perform a command simply do the following: /tell <yourbot> <thecommand>
|
To perform a command simply do the following: /tell <yourbot> <thecommand>
|
||||||
Where <thecommand> is an internal command as described in "Internal commands" section.
|
Where <thecommand> is an internal command as described in "Internal commands" section.
|
||||||
You can remotely send chat messages or commands using /tell <yourbot> send <thetext>
|
You can remotely send chat messages or commands using /tell <yourbot> send <thetext>
|
||||||
Remote control system can auto-accept /tpa and /tpahere requests from the bot owners.
|
|
||||||
|
Remote control system can by default auto-accept /tpa and /tpahere requests from the bot owners.
|
||||||
Auto-accept can be disabled or extended to requests from anyone in remote control configuration.
|
Auto-accept can be disabled or extended to requests from anyone in remote control configuration.
|
||||||
|
|
||||||
===============================
|
===============================
|
||||||
|
|
@ -215,7 +230,7 @@ For more information about how to define match rules, please refer to sample-mat
|
||||||
=========================
|
=========================
|
||||||
|
|
||||||
Even if everything should work, I am not responsible of any damage this app could cause to your computer or your server.
|
Even if everything should work, I am not responsible of any damage this app could cause to your computer or your server.
|
||||||
This app does not steal your password. If you don't trust it, don't use it or check & compile the source code.
|
This app does not steal your password. If you don't trust it, don't use it or check & compile from the source code.
|
||||||
|
|
||||||
Also, remember that when you connect to a server with this program, you will appear where you left the last time.
|
Also, remember that when you connect to a server with this program, you will appear where you left the last time.
|
||||||
This means that you can die if you log in in an unsafe place on a survival server!
|
This means that you can die if you log in in an unsafe place on a survival server!
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@
|
||||||
# You can define an action if the match was in a private message
|
# You can define an action if the match was in a private message
|
||||||
# You can define an action if the match was not sent by a player
|
# You can define an action if the match was not sent by a player
|
||||||
# Regex matches are also supported eg $1, $2, $3.. in actions
|
# Regex matches are also supported eg $1, $2, $3.. in actions
|
||||||
|
# Matches can optionally be restricted to bot owners only
|
||||||
|
|
||||||
# Simple example: Respond to a message containing a keyword
|
# Simple example: Respond to a message containing a keyword
|
||||||
|
|
||||||
|
|
@ -16,6 +17,7 @@ match=hi
|
||||||
action=send hi, $u!
|
action=send hi, $u!
|
||||||
actionprivate=send /tell $u Hello!
|
actionprivate=send /tell $u Hello!
|
||||||
actionother=log detected "hi" message
|
actionother=log detected "hi" message
|
||||||
|
ownersonly=false
|
||||||
|
|
||||||
# You do not need to specify all the "action" fields
|
# You do not need to specify all the "action" fields
|
||||||
# Only one of them is required for each match
|
# Only one of them is required for each match
|
||||||
|
|
@ -40,5 +42,12 @@ action=script test
|
||||||
match=server is restarting
|
match=server is restarting
|
||||||
actionother=script restart
|
actionother=script restart
|
||||||
|
|
||||||
|
# Example of custom remote control command
|
||||||
|
|
||||||
|
[Match]
|
||||||
|
match=gohome
|
||||||
|
actionprivate=send /home
|
||||||
|
ownersonly=true
|
||||||
|
|
||||||
# Enjoy!
|
# Enjoy!
|
||||||
# - ORelio
|
# - ORelio
|
||||||
Loading…
Add table
Add a link
Reference in a new issue