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;
|
2022-09-26 00:56:22 +02:00
|
|
|
|
using static System.Net.WebRequestMethods;
|
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];
|
2022-09-26 00:56:22 +02:00
|
|
|
|
private bool logToFile = false;
|
2014-05-31 01:59:03 +02:00
|
|
|
|
|
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);
|
2022-09-26 00:56:22 +02:00
|
|
|
|
logToFile = Settings.Alerts_File_Logging;
|
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
|
|
|
|
|
2022-07-03 22:34:07 +08:00
|
|
|
|
ConsoleIO.WriteLine(text.Replace(alert, "§c" + alert + "§r"));
|
2022-09-26 00:56:22 +02:00
|
|
|
|
|
|
|
|
|
|
if (logToFile && Settings.Alerts_LogFile.Length > 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
DateTime now = DateTime.Now;
|
|
|
|
|
|
string TimeStamp = "[" + now.Year + '/' + now.Month + '/' + now.Day + ' ' + now.Hour + ':' + now.Minute + ']';
|
|
|
|
|
|
System.IO.File.AppendAllText(Settings.Alerts_LogFile, TimeStamp + " " + GetVerbatim(text) + "\n");
|
|
|
|
|
|
}
|
2014-05-31 01:59:03 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|