Skip to content

Commit

Permalink
New: Tags field for Discord
Browse files Browse the repository at this point in the history
  • Loading branch information
mynameisbogdan committed Dec 31, 2023
1 parent 3a7b27f commit 3ff8e51
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 7 deletions.
22 changes: 21 additions & 1 deletion src/NzbDrone.Core/Notifications/Discord/Discord.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,20 @@
using NzbDrone.Core.MediaFiles.MediaInfo;
using NzbDrone.Core.Movies;
using NzbDrone.Core.Notifications.Discord.Payloads;
using NzbDrone.Core.Tags;
using NzbDrone.Core.Validation;

namespace NzbDrone.Core.Notifications.Discord
{
public class Discord : NotificationBase<DiscordSettings>
{
private readonly IDiscordProxy _proxy;
private readonly ITagRepository _tagRepository;

public Discord(IDiscordProxy proxy)
public Discord(IDiscordProxy proxy, ITagRepository tagRepository)
{
_proxy = proxy;
_tagRepository = tagRepository;
}

public override string Name => "Discord";
Expand Down Expand Up @@ -110,6 +113,10 @@ public override void OnGrab(GrabMessage message)
discordField.Name = "Indexer";
discordField.Value = message.RemoteMovie.Release.Indexer;
break;
case DiscordGrabFieldType.Tags:
discordField.Name = "Tags";
discordField.Value = GetTagLabels(message.Movie)?.Join(", ") ?? string.Empty;
break;
}

if (discordField.Name.IsNotNullOrWhiteSpace() && discordField.Value.IsNotNullOrWhiteSpace())
Expand Down Expand Up @@ -214,6 +221,10 @@ public override void OnDownload(DownloadMessage message)
discordField.Name = "Links";
discordField.Value = GetLinksString(message.Movie);
break;
case DiscordImportFieldType.Tags:
discordField.Name = "Tags";
discordField.Value = GetTagLabels(message.Movie)?.Join(", ") ?? string.Empty;
break;
}

if (discordField.Name.IsNotNullOrWhiteSpace() && discordField.Value.IsNotNullOrWhiteSpace())
Expand Down Expand Up @@ -499,6 +510,10 @@ public override void OnManualInteractionRequired(ManualInteractionRequiredMessag
discordField.Name = "Links";
discordField.Value = GetLinksString(message.Movie);
break;
case DiscordManualInteractionFieldType.Tags:
discordField.Name = "Tags";
discordField.Value = GetTagLabels(message.Movie)?.Join(", ") ?? string.Empty;
break;
}

if (discordField.Name.IsNotNullOrWhiteSpace() && discordField.Value.IsNotNullOrWhiteSpace())
Expand Down Expand Up @@ -604,5 +619,10 @@ private string GetTitle(Movie movie)

return title.Length > 256 ? $"{title.AsSpan(0, 253)}..." : title;
}

private IEnumerable<string> GetTagLabels(Movie movie)
{
return movie.Tags?.Select(t => _tagRepository.Get(t)?.Label).Take(5).OrderBy(t => t);
}
}
}
9 changes: 6 additions & 3 deletions src/NzbDrone.Core/Notifications/Discord/DiscordFieldType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ public enum DiscordGrabFieldType
Fanart,
Indexer,
CustomFormats,
CustomFormatScore
CustomFormatScore,
Tags
}

public enum DiscordImportFieldType
Expand All @@ -31,7 +32,8 @@ public enum DiscordImportFieldType
Links,
Release,
Poster,
Fanart
Fanart,
Tags
}

public enum DiscordManualInteractionFieldType
Expand All @@ -45,6 +47,7 @@ public enum DiscordManualInteractionFieldType
Links,
DownloadTitle,
Poster,
Fanart
Fanart,
Tags
}
}
9 changes: 6 additions & 3 deletions src/NzbDrone.Core/Notifications/Discord/DiscordSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ public DiscordSettings()
(int)DiscordGrabFieldType.Fanart,
(int)DiscordGrabFieldType.Indexer,
(int)DiscordGrabFieldType.CustomFormats,
(int)DiscordGrabFieldType.CustomFormatScore
(int)DiscordGrabFieldType.CustomFormatScore,
(int)DiscordGrabFieldType.Tags
};
ImportFields = new[]
{
Expand All @@ -49,7 +50,8 @@ public DiscordSettings()
(int)DiscordImportFieldType.Links,
(int)DiscordImportFieldType.Release,
(int)DiscordImportFieldType.Poster,
(int)DiscordImportFieldType.Fanart
(int)DiscordImportFieldType.Fanart,
(int)DiscordImportFieldType.Tags
};
ManualInteractionFields = new[]
{
Expand All @@ -62,7 +64,8 @@ public DiscordSettings()
(int)DiscordManualInteractionFieldType.Links,
(int)DiscordManualInteractionFieldType.DownloadTitle,
(int)DiscordManualInteractionFieldType.Poster,
(int)DiscordManualInteractionFieldType.Fanart
(int)DiscordManualInteractionFieldType.Fanart,
(int)DiscordManualInteractionFieldType.Tags
};
}

Expand Down

0 comments on commit 3ff8e51

Please sign in to comment.