mirror of
https://github.com/MCCTeam/Minecraft-Console-Client
synced 2025-10-14 21:22:49 +00:00
Auto Respond Bot
This bot allows users to add a bot that can detect and respond to certain text. The bot can be enabled/disabled via the ini file. (disabled by default) The bot uses 2 files to let the user set what to pickup and what to respond.
This commit is contained in:
parent
834e446a74
commit
43fa3fb4b4
4 changed files with 93 additions and 10 deletions
59
MinecraftClient/ChatBots/Auto Respond.cs
Normal file
59
MinecraftClient/ChatBots/Auto Respond.cs
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.IO;
|
||||
|
||||
namespace MinecraftClient.ChatBots
|
||||
{
|
||||
class Auto_Respond : ChatBot
|
||||
{
|
||||
private String[] respondon = new String[0];
|
||||
private String[] torespond = new String[0];
|
||||
|
||||
private static string[] FromFile(string file)
|
||||
{
|
||||
if (File.Exists(file))
|
||||
{
|
||||
//Read all lines from file, remove lines with no text, convert to lowercase,
|
||||
//remove duplicate entries, convert to a string array, and return the result.
|
||||
return File.ReadAllLines(file)
|
||||
.Where(line => !String.IsNullOrWhiteSpace(line))
|
||||
.Select(line => line.ToLower())
|
||||
.Distinct().ToArray();
|
||||
}
|
||||
else
|
||||
{
|
||||
LogToConsole("File not found: " + file);
|
||||
return new string[0];
|
||||
}
|
||||
}
|
||||
|
||||
//Initalize the bot
|
||||
public override void Initialize()
|
||||
{
|
||||
respondon = FromFile(Settings.Respond_MatchesFile);
|
||||
torespond = FromFile(Settings.Respond_RespondFile);
|
||||
ConsoleIO.WriteLine("Auto Respond Bot Sucessfully loaded!");
|
||||
}
|
||||
|
||||
public override void GetText(string text)
|
||||
{
|
||||
//Remove colour codes
|
||||
text = getVerbatim(text).ToLower();
|
||||
//Check text to see if bot should respond
|
||||
foreach (string alert in respondon.Where(alert => text.Contains(alert)))
|
||||
{
|
||||
//Find what to respond with
|
||||
for (int x = 0; x < respondon.Length; x++)
|
||||
{
|
||||
if (respondon[x].ToString().Contains(alert))
|
||||
{
|
||||
//Respond
|
||||
SendText(torespond[x].ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue