2014-05-31 01:59:03 +02:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
using System.Text;
|
2014-12-16 19:17:06 +01:00
|
|
|
|
using System.IO;
|
2014-05-31 01:59:03 +02:00
|
|
|
|
|
|
|
|
|
|
namespace MinecraftClient.ChatBots
|
|
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// This bot make the console beep on some specified words. Useful to detect when someone is talking to you, for example.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public class Alerts : ChatBot
|
|
|
|
|
|
{
|
|
|
|
|
|
private string[] dictionary = new string[0];
|
|
|
|
|
|
private string[] excludelist = new string[0];
|
|
|
|
|
|
|
2014-12-16 19:17:06 +01:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Intitialize the Alerts bot
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public override void Initialize()
|
|
|
|
|
|
{
|
2015-05-26 19:16:50 +02:00
|
|
|
|
dictionary = LoadDistinctEntriesFromFile(Settings.Alerts_MatchesFile);
|
|
|
|
|
|
excludelist = LoadDistinctEntriesFromFile(Settings.Alerts_ExcludesFile);
|
2014-12-16 19:17:06 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Process text received from the server to display alerts
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="text">Received text</param>
|
2014-05-31 01:59:03 +02:00
|
|
|
|
public override void GetText(string text)
|
|
|
|
|
|
{
|
2014-12-16 19:17:06 +01:00
|
|
|
|
//Remove color codes and convert to lowercase
|
2015-06-20 22:58:18 +02:00
|
|
|
|
text = GetVerbatim(text).ToLower();
|
2014-12-16 19:17:06 +01:00
|
|
|
|
|
|
|
|
|
|
//Proceed only if no exclusions are found in text
|
|
|
|
|
|
if (!excludelist.Any(exclusion => text.Contains(exclusion)))
|
2014-05-31 01:59:03 +02:00
|
|
|
|
{
|
2014-12-16 19:17:06 +01:00
|
|
|
|
//Show an alert for each alert item found in text, if any
|
|
|
|
|
|
foreach (string alert in dictionary.Where(alert => text.Contains(alert)))
|
2014-05-31 01:59:03 +02:00
|
|
|
|
{
|
2014-12-16 19:17:06 +01:00
|
|
|
|
if (Settings.Alerts_Beep_Enabled)
|
|
|
|
|
|
Console.Beep(); //Text found !
|
2014-05-31 01:59:03 +02:00
|
|
|
|
|
2014-12-16 19:17:06 +01:00
|
|
|
|
if (ConsoleIO.basicIO) //Using a GUI? Pass text as is.
|
|
|
|
|
|
ConsoleIO.WriteLine(text.Replace(alert, "§c" + alert + "§r"));
|
2014-05-31 01:59:03 +02:00
|
|
|
|
|
2015-03-25 19:45:50 +01:00
|
|
|
|
else //Using Console Prompt : Print text with alert highlighted
|
2014-05-31 01:59:03 +02:00
|
|
|
|
{
|
2014-12-16 19:17:06 +01:00
|
|
|
|
string[] splitted = text.Split(new string[] { alert }, StringSplitOptions.None);
|
2014-05-31 01:59:03 +02:00
|
|
|
|
|
2015-03-25 19:45:50 +01:00
|
|
|
|
ConsoleColor fore = Console.ForegroundColor;
|
|
|
|
|
|
ConsoleColor back = Console.BackgroundColor;
|
|
|
|
|
|
|
2014-12-16 19:17:06 +01:00
|
|
|
|
if (splitted.Length > 0)
|
2014-05-31 01:59:03 +02:00
|
|
|
|
{
|
|
|
|
|
|
Console.BackgroundColor = ConsoleColor.DarkGray;
|
|
|
|
|
|
Console.ForegroundColor = ConsoleColor.White;
|
2014-12-16 19:17:06 +01:00
|
|
|
|
ConsoleIO.Write(splitted[0]);
|
2014-05-31 01:59:03 +02:00
|
|
|
|
|
2014-12-16 19:17:06 +01:00
|
|
|
|
for (int i = 1; i < splitted.Length; i++)
|
2014-05-31 01:59:03 +02:00
|
|
|
|
{
|
|
|
|
|
|
Console.BackgroundColor = ConsoleColor.Yellow;
|
|
|
|
|
|
Console.ForegroundColor = ConsoleColor.Red;
|
2014-12-16 19:17:06 +01:00
|
|
|
|
ConsoleIO.Write(alert);
|
2014-05-31 01:59:03 +02:00
|
|
|
|
|
|
|
|
|
|
Console.BackgroundColor = ConsoleColor.DarkGray;
|
|
|
|
|
|
Console.ForegroundColor = ConsoleColor.White;
|
2014-12-16 19:17:06 +01:00
|
|
|
|
ConsoleIO.Write(splitted[i]);
|
2014-05-31 01:59:03 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2014-12-16 19:17:06 +01:00
|
|
|
|
|
2015-03-25 19:45:50 +01:00
|
|
|
|
Console.BackgroundColor = back;
|
|
|
|
|
|
Console.ForegroundColor = fore;
|
2014-12-16 19:17:06 +01:00
|
|
|
|
ConsoleIO.Write('\n');
|
2014-05-31 01:59:03 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|