2020-10-17 03:27:01 +00:00
|
|
|
using FluentValidation;
|
2016-09-24 19:22:57 +00:00
|
|
|
using NzbDrone.Core.Annotations;
|
|
|
|
using NzbDrone.Core.ThingiProvider;
|
|
|
|
using NzbDrone.Core.Validation;
|
|
|
|
|
|
|
|
namespace NzbDrone.Core.Notifications.Telegram
|
|
|
|
{
|
|
|
|
public class TelegramSettingsValidator : AbstractValidator<TelegramSettings>
|
|
|
|
{
|
|
|
|
public TelegramSettingsValidator()
|
|
|
|
{
|
|
|
|
RuleFor(c => c.BotToken).NotEmpty();
|
|
|
|
RuleFor(c => c.ChatId).NotEmpty();
|
2023-04-14 23:47:06 +00:00
|
|
|
RuleFor(c => c.TopicId).Must(topicId => !topicId.HasValue || topicId > 1)
|
|
|
|
.WithMessage("Topic ID must be greater than 1 or empty");
|
2016-09-24 19:22:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public class TelegramSettings : IProviderConfig
|
|
|
|
{
|
|
|
|
private static readonly TelegramSettingsValidator Validator = new TelegramSettingsValidator();
|
|
|
|
|
2024-01-03 20:41:16 +00:00
|
|
|
[FieldDefinition(0, Label = "NotificationsTelegramSettingsBotToken", Privacy = PrivacyLevel.ApiKey, HelpLink = "https://core.telegram.org/bots")]
|
2016-09-24 19:22:57 +00:00
|
|
|
public string BotToken { get; set; }
|
|
|
|
|
2024-01-03 20:41:16 +00:00
|
|
|
[FieldDefinition(1, Label = "NotificationsTelegramSettingsChatId", HelpLink = "http://stackoverflow.com/a/37396871/882971", HelpText = "NotificationsTelegramSettingsChatIdHelpText")]
|
2016-09-24 19:22:57 +00:00
|
|
|
public string ChatId { get; set; }
|
|
|
|
|
2024-01-03 20:41:16 +00:00
|
|
|
[FieldDefinition(2, Label = "NotificationsTelegramSettingsTopicId", HelpLink = "https://stackoverflow.com/a/75178418", HelpText = "NotificationsTelegramSettingsTopicIdHelpText")]
|
2023-04-14 23:47:06 +00:00
|
|
|
public int? TopicId { get; set; }
|
|
|
|
|
2024-01-03 20:41:16 +00:00
|
|
|
[FieldDefinition(3, Label = "NotificationsTelegramSettingsSendSilently", Type = FieldType.Checkbox, HelpText = "NotificationsTelegramSettingsSendSilentlyHelpText")]
|
2020-08-16 17:42:14 +00:00
|
|
|
public bool SendSilently { get; set; }
|
2016-09-24 19:22:57 +00:00
|
|
|
|
|
|
|
public NzbDroneValidationResult Validate()
|
|
|
|
{
|
|
|
|
return new NzbDroneValidationResult(Validator.Validate(this));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|