-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add available/preferred image type expressions
Added four new filter expressions; - `HasAvailableImageExpression` — Check if a single series or group of series has the image type available. - `HasPreferredImageExpression` — Check if a single series or group of series has an image set as preferred for the image type. - `AvailableImageTypesSelector` — Get a set of the available image types for a single series or group of series (as strings) to use with the string set expressions in case you need to do more advanced checks. - `PreferredImageTypesSelector` — Get a set of the preferred image types for a single series or group of series (as strings) to use with the string set expressions in case you need to do more advanced checks. Closes #1187
- Loading branch information
Showing
10 changed files
with
358 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
using System; | ||
using System.Linq; | ||
using Shoko.Plugin.Abstractions.Enums; | ||
using Shoko.Server.Filters.Interfaces; | ||
using Shoko.Server.Repositories; | ||
|
||
namespace Shoko.Server.Filters.Info; | ||
|
||
public class HasAvailableImageExpression : FilterExpression<bool>, IWithStringParameter | ||
{ | ||
public HasAvailableImageExpression(string parameter) | ||
{ | ||
if (Enum.TryParse<ImageEntityType>(parameter, out var imageEntityType)) | ||
imageEntityType = ImageEntityType.None; | ||
Parameter = imageEntityType; | ||
} | ||
|
||
public HasAvailableImageExpression() { } | ||
|
||
public ImageEntityType Parameter { get; set; } | ||
public override bool TimeDependent => true; | ||
public override bool UserDependent => false; | ||
public override string HelpDescription => "This condition passes if any of the anime has the available image type."; | ||
public override string[] HelpPossibleParameters => RepoFactory.AnimeSeries.GetAllImageTypes().Select(a => a.ToString()).ToArray(); | ||
|
||
string IWithStringParameter.Parameter | ||
{ | ||
get => Parameter.ToString(); | ||
set | ||
{ | ||
if (Enum.TryParse<ImageEntityType>(value, out var imageEntityType)) | ||
imageEntityType = ImageEntityType.None; | ||
Parameter = imageEntityType; | ||
} | ||
} | ||
|
||
public override bool Evaluate(IFilterable filterable, IFilterableUserInfo userInfo) | ||
{ | ||
return filterable.AvailableImageTypes.Contains(Parameter); | ||
} | ||
|
||
protected bool Equals(HasAvailableImageExpression other) | ||
{ | ||
return base.Equals(other) && Parameter == other.Parameter; | ||
} | ||
|
||
public override bool Equals(object obj) | ||
{ | ||
if (ReferenceEquals(null, obj)) | ||
{ | ||
return false; | ||
} | ||
|
||
if (ReferenceEquals(this, obj)) | ||
{ | ||
return true; | ||
} | ||
|
||
if (obj.GetType() != this.GetType()) | ||
{ | ||
return false; | ||
} | ||
|
||
return Equals((HasAvailableImageExpression)obj); | ||
} | ||
|
||
public override int GetHashCode() | ||
{ | ||
return HashCode.Combine(base.GetHashCode(), Parameter); | ||
} | ||
|
||
public static bool operator ==(HasAvailableImageExpression left, HasAvailableImageExpression right) | ||
{ | ||
return Equals(left, right); | ||
} | ||
|
||
public static bool operator !=(HasAvailableImageExpression left, HasAvailableImageExpression right) | ||
{ | ||
return !Equals(left, right); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
using System; | ||
using System.Linq; | ||
using Shoko.Plugin.Abstractions.Enums; | ||
using Shoko.Server.Filters.Interfaces; | ||
using Shoko.Server.Repositories; | ||
|
||
namespace Shoko.Server.Filters.Info; | ||
|
||
public class HasPreferredImageExpression : FilterExpression<bool>, IWithStringParameter | ||
{ | ||
public HasPreferredImageExpression(string parameter) | ||
{ | ||
if (Enum.TryParse<ImageEntityType>(parameter, out var imageEntityType)) | ||
imageEntityType = ImageEntityType.None; | ||
Parameter = imageEntityType; | ||
} | ||
|
||
public HasPreferredImageExpression() { } | ||
|
||
public ImageEntityType Parameter { get; set; } | ||
public override bool TimeDependent => true; | ||
public override bool UserDependent => false; | ||
public override string HelpDescription => "This condition passes if any of the anime has the preferred image type."; | ||
public override string[] HelpPossibleParameters => RepoFactory.AnimeSeries.GetAllImageTypes().Select(a => a.ToString()).ToArray(); | ||
|
||
string IWithStringParameter.Parameter | ||
{ | ||
get => Parameter.ToString(); | ||
set | ||
{ | ||
if (Enum.TryParse<ImageEntityType>(value, out var imageEntityType)) | ||
imageEntityType = ImageEntityType.None; | ||
Parameter = imageEntityType; | ||
} | ||
} | ||
|
||
public override bool Evaluate(IFilterable filterable, IFilterableUserInfo userInfo) | ||
{ | ||
return filterable.PreferredImageTypes.Contains(Parameter); | ||
} | ||
|
||
protected bool Equals(HasPreferredImageExpression other) | ||
{ | ||
return base.Equals(other) && Parameter == other.Parameter; | ||
} | ||
|
||
public override bool Equals(object obj) | ||
{ | ||
if (ReferenceEquals(null, obj)) | ||
{ | ||
return false; | ||
} | ||
|
||
if (ReferenceEquals(this, obj)) | ||
{ | ||
return true; | ||
} | ||
|
||
if (obj.GetType() != this.GetType()) | ||
{ | ||
return false; | ||
} | ||
|
||
return Equals((HasPreferredImageExpression)obj); | ||
} | ||
|
||
public override int GetHashCode() | ||
{ | ||
return HashCode.Combine(base.GetHashCode(), Parameter); | ||
} | ||
|
||
public static bool operator ==(HasPreferredImageExpression left, HasPreferredImageExpression right) | ||
{ | ||
return Equals(left, right); | ||
} | ||
|
||
public static bool operator !=(HasPreferredImageExpression left, HasPreferredImageExpression right) | ||
{ | ||
return !Equals(left, right); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
Shoko.Server/Filters/Selectors/StringSetSelectors/AvailableImageTypesSelector.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using Shoko.Server.Filters.Interfaces; | ||
|
||
namespace Shoko.Server.Filters.Selectors.StringSetSelectors; | ||
|
||
public class AvailableImageTypesSelector : FilterExpression<IReadOnlySet<string>> | ||
{ | ||
public override bool TimeDependent => false; | ||
public override bool UserDependent => false; | ||
public override string HelpDescription => "This returns a set of all the available image types in a filterable."; | ||
public override FilterExpressionGroup Group => FilterExpressionGroup.Selector; | ||
|
||
public override IReadOnlySet<string> Evaluate(IFilterable filterable, IFilterableUserInfo userInfo) | ||
{ | ||
return filterable.AvailableImageTypes.Select(t => t.ToString()).ToHashSet(); | ||
} | ||
|
||
protected bool Equals(AvailableImageTypesSelector other) | ||
{ | ||
return base.Equals(other); | ||
} | ||
|
||
public override bool Equals(object obj) | ||
{ | ||
if (ReferenceEquals(null, obj)) | ||
{ | ||
return false; | ||
} | ||
|
||
if (ReferenceEquals(this, obj)) | ||
{ | ||
return true; | ||
} | ||
|
||
if (obj.GetType() != this.GetType()) | ||
{ | ||
return false; | ||
} | ||
|
||
return Equals((AvailableImageTypesSelector)obj); | ||
} | ||
|
||
public override int GetHashCode() | ||
{ | ||
return GetType().FullName!.GetHashCode(); | ||
} | ||
|
||
public static bool operator ==(AvailableImageTypesSelector left, AvailableImageTypesSelector right) | ||
{ | ||
return Equals(left, right); | ||
} | ||
|
||
public static bool operator !=(AvailableImageTypesSelector left, AvailableImageTypesSelector right) | ||
{ | ||
return !Equals(left, right); | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
Shoko.Server/Filters/Selectors/StringSetSelectors/PreferredImageTypesSelector.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using Shoko.Server.Filters.Interfaces; | ||
|
||
namespace Shoko.Server.Filters.Selectors.StringSetSelectors; | ||
|
||
public class PreferredImageTypesSelector : FilterExpression<IReadOnlySet<string>> | ||
{ | ||
public override bool TimeDependent => false; | ||
public override bool UserDependent => false; | ||
public override string HelpDescription => "This returns a set of all the preferred image types in a filterable."; | ||
public override FilterExpressionGroup Group => FilterExpressionGroup.Selector; | ||
|
||
public override IReadOnlySet<string> Evaluate(IFilterable filterable, IFilterableUserInfo userInfo) | ||
{ | ||
return filterable.PreferredImageTypes.Select(t => t.ToString()).ToHashSet(); | ||
} | ||
|
||
protected bool Equals(PreferredImageTypesSelector other) | ||
{ | ||
return base.Equals(other); | ||
} | ||
|
||
public override bool Equals(object obj) | ||
{ | ||
if (ReferenceEquals(null, obj)) | ||
{ | ||
return false; | ||
} | ||
|
||
if (ReferenceEquals(this, obj)) | ||
{ | ||
return true; | ||
} | ||
|
||
if (obj.GetType() != this.GetType()) | ||
{ | ||
return false; | ||
} | ||
|
||
return Equals((PreferredImageTypesSelector)obj); | ||
} | ||
|
||
public override int GetHashCode() | ||
{ | ||
return GetType().FullName!.GetHashCode(); | ||
} | ||
|
||
public static bool operator ==(PreferredImageTypesSelector left, PreferredImageTypesSelector right) | ||
{ | ||
return Equals(left, right); | ||
} | ||
|
||
public static bool operator !=(PreferredImageTypesSelector left, PreferredImageTypesSelector right) | ||
{ | ||
return !Equals(left, right); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.