forked from EllieBotDevs/elliebot
Removed some unused code, no functional change
This commit is contained in:
parent
66560bb769
commit
d428fc5532
7 changed files with 15 additions and 113 deletions
src/EllieBot/Modules/Games
|
@ -1,6 +1,5 @@
|
|||
#nullable disable
|
||||
using Microsoft.Extensions.Caching.Memory;
|
||||
using EllieBot.Common.ModuleBehaviors;
|
||||
using EllieBot.Modules.Games.Common;
|
||||
using EllieBot.Modules.Games.Common.Acrophobia;
|
||||
using EllieBot.Modules.Games.Common.Nunchi;
|
||||
|
@ -8,11 +7,10 @@ using Newtonsoft.Json;
|
|||
|
||||
namespace EllieBot.Modules.Games.Services;
|
||||
|
||||
public class GamesService : IEService, IReadyExecutor
|
||||
public class GamesService : IEService
|
||||
{
|
||||
private const string TYPING_ARTICLES_PATH = "data/typing_articles3.json";
|
||||
|
||||
public ConcurrentDictionary<ulong, GirlRating> GirlRatings { get; } = new();
|
||||
|
||||
public IReadOnlyList<string> EightBallResponses
|
||||
=> _gamesConfig.Data.EightBallResponses;
|
||||
|
@ -25,7 +23,6 @@ public class GamesService : IEService, IReadyExecutor
|
|||
public ConcurrentDictionary<ulong, TypingGame> RunningContests { get; } = new();
|
||||
public ConcurrentDictionary<ulong, NunchiGame> NunchiGames { get; } = new();
|
||||
|
||||
public AsyncLazy<RatingTexts> Ratings { get; }
|
||||
private readonly GamesConfigService _gamesConfig;
|
||||
|
||||
private readonly IHttpClientFactory _httpFactory;
|
||||
|
@ -41,7 +38,6 @@ public class GamesService : IEService, IReadyExecutor
|
|||
SizeLimit = 500_000
|
||||
});
|
||||
|
||||
Ratings = new(GetRatingTexts);
|
||||
_rng = new EllieRandom();
|
||||
|
||||
try
|
||||
|
@ -55,22 +51,6 @@ public class GamesService : IEService, IReadyExecutor
|
|||
}
|
||||
}
|
||||
|
||||
public async Task OnReadyAsync()
|
||||
{
|
||||
// reset rating once a day
|
||||
using var timer = new PeriodicTimer(TimeSpan.FromDays(1));
|
||||
while (await timer.WaitForNextTickAsync())
|
||||
GirlRatings.Clear();
|
||||
}
|
||||
|
||||
private async Task<RatingTexts> GetRatingTexts()
|
||||
{
|
||||
using var http = _httpFactory.CreateClient();
|
||||
var text = await http.GetStringAsync(
|
||||
"https://nadeko-pictures.nyc3.digitaloceanspaces.com/other/rategirl/rates.json");
|
||||
return JsonConvert.DeserializeObject<RatingTexts>(text);
|
||||
}
|
||||
|
||||
public void AddTypingArticle(IUser user, string text)
|
||||
{
|
||||
TypingArticles.Add(new()
|
||||
|
@ -104,15 +84,4 @@ public class GamesService : IEService, IReadyExecutor
|
|||
File.WriteAllText(TYPING_ARTICLES_PATH, JsonConvert.SerializeObject(articles));
|
||||
return removed;
|
||||
}
|
||||
|
||||
public class RatingTexts
|
||||
{
|
||||
public string Nog { get; set; }
|
||||
public string Tra { get; set; }
|
||||
public string Fun { get; set; }
|
||||
public string Uni { get; set; }
|
||||
public string Wif { get; set; }
|
||||
public string Dat { get; set; }
|
||||
public string Dan { get; set; }
|
||||
}
|
||||
}
|
|
@ -1,61 +0,0 @@
|
|||
#nullable disable
|
||||
using SixLabors.ImageSharp;
|
||||
using SixLabors.ImageSharp.Processing;
|
||||
using Image = SixLabors.ImageSharp.Image;
|
||||
|
||||
namespace EllieBot.Modules.Games.Common;
|
||||
|
||||
public class GirlRating
|
||||
{
|
||||
public double Crazy { get; }
|
||||
public double Hot { get; }
|
||||
public int Roll { get; }
|
||||
public string Advice { get; }
|
||||
|
||||
public AsyncLazy<Stream> Stream { get; }
|
||||
private readonly IImageCache _images;
|
||||
|
||||
public GirlRating(
|
||||
IImageCache images,
|
||||
double crazy,
|
||||
double hot,
|
||||
int roll,
|
||||
string advice)
|
||||
{
|
||||
_images = images;
|
||||
Crazy = crazy;
|
||||
Hot = hot;
|
||||
Roll = roll;
|
||||
Advice = advice; // convenient to have it here, even though atm there are only few different ones.
|
||||
|
||||
Stream = new(async () =>
|
||||
{
|
||||
try
|
||||
{
|
||||
var bgBytes = await _images.GetRategirlBgAsync();
|
||||
using var img = Image.Load(bgBytes);
|
||||
const int minx = 35;
|
||||
const int miny = 385;
|
||||
const int length = 345;
|
||||
|
||||
var pointx = (int)(minx + (length * (Hot / 10)));
|
||||
var pointy = (int)(miny - (length * ((Crazy - 4) / 6)));
|
||||
|
||||
var dotBytes = await _images.GetRategirlDotAsync();
|
||||
using (var pointImg = Image.Load(dotBytes))
|
||||
{
|
||||
img.Mutate(x => x.DrawImage(pointImg, new(pointx - 10, pointy - 10), new GraphicsOptions()));
|
||||
}
|
||||
|
||||
var imgStream = new MemoryStream();
|
||||
img.SaveAsPng(imgStream);
|
||||
return imgStream;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Warning(ex, "Error getting RateGirl image");
|
||||
return null;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
Reference in a new issue