mirror of
https://github.com/Jetsparrow/antiantiswearingbot.git
synced 2026-01-21 07:16:08 +03:00
31 lines
819 B
C#
31 lines
819 B
C#
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;
|
||
if (Dict.Unlearn(word))
|
||
return $"Удалил слово \"{word}\"";
|
||
else
|
||
return $"Не нашел слово \"{word}\"";
|
||
}
|
||
}
|
||
}
|