From 5111471cea28c1ce7da6e323fc549298a3625601 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sun, 4 Jul 2021 17:14:35 -0500 Subject: add options for pushbullet --- src/slskd/Options.cs | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) (limited to 'src/slskd/Options.cs') diff --git a/src/slskd/Options.cs b/src/slskd/Options.cs index f8190fc7..d2f2ddef 100644 --- a/src/slskd/Options.cs +++ b/src/slskd/Options.cs @@ -567,6 +567,12 @@ namespace slskd [Validate] public FTPOptions FTP { get; private set; } = new FTPOptions(); + /// + /// Gets Pushbullet options. + /// + [Validate] + public PushbulletOptions Pushbullet { get; private set; } = new PushbulletOptions(); + /// /// FTP options. /// @@ -676,6 +682,70 @@ namespace slskd return results; } } + + /// + /// Pushbullet options. + /// + public class PushbulletOptions + { + /// + /// Gets a value indicating whether the Pushbullet integration is enabled. + /// + [Argument(default, "pushbullet")] + [EnvironmentVariable("PUSHBULLET_ENABLED")] + [Description("enable Pushbullet integration")] + public bool Enabled { get; private set; } = false; + + /// + /// Gets the Pushbullet API access token. + /// + [Argument(default, "pushbullet-token")] + [EnvironmentVariable("PUSHBULLET_ACCESS_TOKEN")] + [Description("Pushbullet access token")] + public string AccessToken { get; private set; } + + /// + /// Gets the prefix for Pushbullet notification titles. + /// + [Argument(default, "pushbullet-prefix")] + [EnvironmentVariable("PUSHBULLET_NOTIFICATION_PREFIX")] + [Description("prefix for Pushbullet notification titles")] + public string NotificationPrefix { get; private set; } = "From slskd:"; + + /// + /// Gets a value indicating whether a Pushbullet notification should be sent when a private message is received. + /// + [Argument(default, "pushbullet-notify-on-pm")] + [EnvironmentVariable("PUSHBULLET_NOTIFY_ON_PRIVATE_MESSAGE")] + [Description("send Pushbullet notifications when private messages are received")] + public bool NotifyOnPrivateMessage { get; private set; } = true; + + /// + /// Gets a value indicating whether a Pushbullet notification should be sent when the currently logged + /// in user's username is mentioned in a room. + /// + [Argument(default, "pushbullet-notify-on-room-mention")] + [EnvironmentVariable("PUSHBULLET_NOTIFY_ON_ROOM_MENTION")] + [Description("send Pushbullet notifications when your username is mentioned in a room")] + public bool NotifyOnRoomMention { get; private set; } = true; + + /// + /// Gets the number of times failing Pushbullet notifications will be retried. + /// + [Argument(default, "pushbullet-retry-attempts")] + [EnvironmentVariable("PUSHBULLET_RETRY_ATTEMPTS")] + [Description("number of times failing Pushbullet notifications will be retried")] + [Range(0, 5)] + public int RetryAttempts { get; private set; } = 3; + + /// + /// Gets the cooldown time for Pushbullet notifications, in milliseconds. + /// + [Argument(default, "pushbullet-cooldown")] + [EnvironmentVariable("PUSHBULLET_COOLDOWN_TIME")] + [Description("cooldown time for Pushbullet notifications, in milliseconds")] + public int CooldownTime { get; private set; } = 900000; // 15 minutes + } } } } \ No newline at end of file -- cgit v1.2.3 From 98c86cc81271a61d9c0f2f41072c8a0e7da5eb8f Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Mon, 5 Jul 2021 14:19:55 -0500 Subject: validate AccessToken when Enabled --- src/slskd/Options.cs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'src/slskd/Options.cs') diff --git a/src/slskd/Options.cs b/src/slskd/Options.cs index d2f2ddef..7c697b43 100644 --- a/src/slskd/Options.cs +++ b/src/slskd/Options.cs @@ -686,7 +686,7 @@ namespace slskd /// /// Pushbullet options. /// - public class PushbulletOptions + public class PushbulletOptions : IValidatableObject { /// /// Gets a value indicating whether the Pushbullet integration is enabled. @@ -745,6 +745,18 @@ namespace slskd [EnvironmentVariable("PUSHBULLET_COOLDOWN_TIME")] [Description("cooldown time for Pushbullet notifications, in milliseconds")] public int CooldownTime { get; private set; } = 900000; // 15 minutes + + public IEnumerable Validate(ValidationContext validationContext) + { + var results = new List(); + + if (Enabled && string.IsNullOrWhiteSpace(AccessToken)) + { + results.Add(new ValidationResult($"The Enabled field is true, but no AccessToken has been specified.")); + } + + return results; + } } } } -- cgit v1.2.3