Removed some unused code, no functional change

This commit is contained in:
Toastie 2024-08-06 21:53:28 +12:00
parent 66560bb769
commit d428fc5532
Signed by: toastie_t0ast
GPG key ID: 27F3B6855AFD40A4
7 changed files with 15 additions and 113 deletions

View file

@ -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; }
}
}

View file

@ -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;
}
});
}
}

View file

@ -60,12 +60,6 @@ public sealed class ImageCache : IImageCache, IEService
public Task<byte[]?> GetXpBackgroundImageAsync()
=> GetImageDataAsync(_ic.Data.Xp.Bg);
public Task<byte[]?> GetRategirlBgAsync()
=> GetImageDataAsync(_ic.Data.Rategirl.Matrix);
public Task<byte[]?> GetRategirlDotAsync()
=> GetImageDataAsync(_ic.Data.Rategirl.Dot);
public Task<byte[]?> GetDiceAsync(int num)
=> GetImageDataAsync(_ic.Data.Dice[num]);

View file

@ -8,12 +8,11 @@ namespace EllieBot.Common;
public partial class ImageUrls : ICloneable<ImageUrls>
{
[Comment("DO NOT CHANGE")]
public int Version { get; set; } = 4;
public int Version { get; set; } = 5;
public CoinData Coins { get; set; }
public Uri[] Currency { get; set; }
public Uri[] Dice { get; set; }
public RategirlData Rategirl { get; set; }
public XpData Xp { get; set; }
public SlotData Slots { get; set; }
@ -30,12 +29,6 @@ public partial class ImageUrls : ICloneable<ImageUrls>
public Uri[] Tails { get; set; }
}
public class RategirlData
{
public Uri Matrix { get; set; }
public Uri Dot { get; set; }
}
public class XpData
{
public Uri Bg { get; set; }

View file

@ -6,8 +6,6 @@ public interface IImageCache
Task<byte[]?> GetTailsImageAsync();
Task<byte[]?> GetCurrencyImageAsync();
Task<byte[]?> GetXpBackgroundImageAsync();
Task<byte[]?> GetRategirlBgAsync();
Task<byte[]?> GetRategirlDotAsync();
Task<byte[]?> GetDiceAsync(int num);
Task<byte[]?> GetSlotEmojiAsync(int number);
Task<byte[]?> GetSlotBgAsync();

View file

@ -15,5 +15,17 @@ public sealed class ImagesConfig : ConfigServiceBase<ImageUrls>
public ImagesConfig(IConfigSeria serializer, IPubSub pubSub)
: base(PATH, serializer, pubSub, _changeKey)
{
Migrate();
}
private void Migrate()
{
if (data.Version < 5)
{
ModifyConfig(c =>
{
c.Version = 5;
});
}
}
}

View file

@ -1,5 +1,5 @@
# DO NOT CHANGE
version: 4
version: 5
coins:
heads:
- https://cdn.nadeko.bot/coins/heads3.png
@ -20,9 +20,6 @@ dice:
- https://cdn.nadeko.bot/other/dice/7.png
- https://cdn.nadeko.bot/other/dice/8.png
- https://cdn.nadeko.bot/other/dice/9.png
rategirl:
matrix: https://cdn.nadeko.bot/other/rategirl/matrix.png
dot: https://cdn.nadeko.bot/other/rategirl/dot.png
xp:
bg: https://cdn.nadeko.bot/other/xp/bg_k.png
rip: