antiantiswearingbot/Jetsparrow.Aasb/Commands/LearnCommand.cs
2023-03-14 00:24:14 +03:00

27 lines
699 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 Jetsparrow.Aasb.Commands;
public class LearnCommand : IChatCommand
{
SearchDictionary Dict { get; }
public LearnCommand(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;
bool newWord = Dict.Learn(word);
return newWord ? $"Принято слово \"{word}\"" : $"Поднял рейтинг слову \"{word}\"";
}
}