|
|
@ -1,4 +1,5 @@ |
|
|
|
using System.Collections.Immutable; |
|
|
|
using System.Collections.Immutable; |
|
|
|
|
|
|
|
using Exsersewo.Common.Extensions; |
|
|
|
using Exsersewo.Common.Utilities; |
|
|
|
using Exsersewo.Common.Utilities; |
|
|
|
using ImageMagick; |
|
|
|
using ImageMagick; |
|
|
|
using Kynareth.Models; |
|
|
|
using Kynareth.Models; |
|
|
@ -19,6 +20,30 @@ public static partial class ImageManager |
|
|
|
GenerationTemplateBaseFolder = Path.Combine(_appEnvironment.WebRootPath, configuration.GetValue<string>("ShitpostBot:Folder")); |
|
|
|
GenerationTemplateBaseFolder = Path.Combine(_appEnvironment.WebRootPath, configuration.GetValue<string>("ShitpostBot:Folder")); |
|
|
|
GenerationEndpoints = configuration.GetSection("ShitpostBot:Templates").Get<List<ImageGenerationEndpoint>>(); |
|
|
|
GenerationEndpoints = configuration.GetSection("ShitpostBot:Templates").Get<List<ImageGenerationEndpoint>>(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static async Task<Object> GenerateImageAsync(CancellationToken cancellationToken) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
ImageGenerationImage imageTemplate = null; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var endpoint = GenerationEndpoints.Random(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (endpoint is null) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
var ex = new ArgumentException($"Couldn't find endpoint"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return GetResult(StatusCodes.Status404NotFound, EventResult.FromFailureException(ex.Message, ex)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
string variant = null; |
|
|
|
|
|
|
|
if (endpoint.Variants.Any() && TrueRandom.Next(0, 50) > 25) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
variant = endpoint.Variants.Random().Name; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var sources = sourceFiles.GetRandomAmount(endpoint.SourcesRequired) as string[]; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return await GenerateImageAsync(endpoint.Name, variant, sources, cancellationToken); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public static async Task<Object> GenerateImageAsync(string template, string variant, CancellationToken cancellationToken) |
|
|
|
public static async Task<Object> GenerateImageAsync(string template, string variant, CancellationToken cancellationToken) |
|
|
|
{ |
|
|
|
{ |
|
|
|