antiantiswearingbot/AntiAntiSwearingBot/Commands/UnlearnCommand.cs
2022-02-27 18:21:35 +03:00

28 lines
708 B
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.Text.RegularExpressions;
using Telegram.Bot.Types;
namespace AntiAntiSwearingBot.Commands;
public class UnlearnCommand : IChatCommand
{
SearchDictionary Dict { get; }
public UnlearnCommand(SearchDictionary dict)
{
Dict = dict;
}
public string Execute(CommandString cmd, Update args)
{
var word = cmd.Parameters.FirstOrDefault();
if (string.IsNullOrWhiteSpace(word))
return null;
if (!Regex.IsMatch(word, @"[а-яА-Я]+"))
return null;
if (Dict.Unlearn(word))
return $"Удалил слово \"{word}\"";
else
return $"Не нашел слово \"{word}\"";
}
}