antiantiswearingbot/AntiAntiSwearingBot/Commands/UnlearnCommand.cs
2019-08-14 00:05:56 +03:00

39 lines
1.1 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System.Linq;
using System.Text.RegularExpressions;
using Telegram.Bot.Args;
namespace AntiAntiSwearingBot.Commands
{
public class UnlearnCommand : IChatCommand
{
SearchDictionary Dict { get; }
public UnlearnCommand(SearchDictionary dict)
{
Dict = dict;
}
public string Execute(CommandString cmd, MessageEventArgs args)
{
var word = cmd.Parameters.FirstOrDefault();
if (string.IsNullOrWhiteSpace(word))
return null;
if (!Regex.IsMatch(word, @"[а-яА-Я]+"))
return null;
var res = Dict.Unlearn(word);
switch (res)
{
case SearchDictionary.UnlearnResult.Demoted:
return $"Понизил слово \"{word}\"";
case SearchDictionary.UnlearnResult.Removed:
return $"Удалил слово \"{word}\"";
case SearchDictionary.UnlearnResult.NotFound:
default:
return $"Не нашел слово \"{word}\"";
}
}
}
}