Reviewed-on: #5 Co-authored-by: Sergey Nazarov <insight.appdev@gmail.com> Co-committed-by: Sergey Nazarov <insight.appdev@gmail.com>
47 lines
1.9 KiB
C#
47 lines
1.9 KiB
C#
using FormatWith;
|
|
using Insight.Localizer;
|
|
using Nocr.TextMatcher.Api.Contracts.TextMatches.Dto;
|
|
using Nocr.TextMatcher.Contracts;
|
|
|
|
namespace Nocr.TelegramClient.AppServices.Matches;
|
|
|
|
public static class TextMatchExtensions
|
|
{
|
|
public static string TextView(this TextSubscriptionData textSubscription, ILocalizer localizer)
|
|
{
|
|
var activeText = textSubscription.Active
|
|
? localizer.Get(nameof(TextSubscriptionData), "Active")
|
|
: localizer.Get(nameof(TextSubscriptionData), "Inactive");
|
|
var activeCommandText = textSubscription.Active
|
|
? GetFormattedCommand("Deactivate", textSubscription.Id)
|
|
: GetFormattedCommand("Activate", textSubscription.Id);
|
|
|
|
var deleteCommandText = GetFormattedCommand("Delete", textSubscription.Id);
|
|
return
|
|
$"[{textSubscription.Id}] (@{textSubscription.ChatUsername}) {activeText}: '{textSubscription.Rule.TextView(localizer)}' > '{textSubscription.Template}'\n{activeCommandText}\n{deleteCommandText}";
|
|
|
|
string GetFormattedCommand(string key, long subscriptionId)
|
|
{
|
|
return localizer.Get(nameof(TextSubscriptionData), key)
|
|
.FormatWith(new
|
|
{
|
|
SubscriptionId = subscriptionId
|
|
});
|
|
}
|
|
}
|
|
|
|
public static string TextView(this TextSubscriptionRule rule, ILocalizer localizer)
|
|
{
|
|
switch (rule)
|
|
{
|
|
case TextSubscriptionRule.Full:
|
|
return localizer.Get(nameof(TextSubscriptionRule), nameof(TextSubscriptionRule.Full));
|
|
case TextSubscriptionRule.AllWords:
|
|
return localizer.Get(nameof(TextSubscriptionRule), nameof(TextSubscriptionRule.AllWords));
|
|
case TextSubscriptionRule.AnyWord:
|
|
return localizer.Get(nameof(TextSubscriptionRule), nameof(TextSubscriptionRule.AnyWord));
|
|
default:
|
|
throw new IndexOutOfRangeException(nameof(rule));
|
|
}
|
|
}
|
|
} |