From d428fc55327605c54253cc794ed5613f5ec71632 Mon Sep 17 00:00:00 2001 From: Toastie Date: Tue, 6 Aug 2024 21:53:28 +1200 Subject: [PATCH] Removed some unused code, no functional change --- src/EllieBot/Modules/Games/GamesService.cs | 33 +--------- src/EllieBot/Modules/Games/GirlRating.cs | 61 ------------------- src/EllieBot/Services/Impl/ImageCache.cs | 6 -- src/EllieBot/_common/ImageUrls.cs | 9 +-- .../_common/Services/Impl/IImageCache.cs | 2 - .../_common/Services/Impl/ImagesConfig.cs | 12 ++++ src/EllieBot/data/images.yml | 5 +- 7 files changed, 15 insertions(+), 113 deletions(-) delete mode 100644 src/EllieBot/Modules/Games/GirlRating.cs diff --git a/src/EllieBot/Modules/Games/GamesService.cs b/src/EllieBot/Modules/Games/GamesService.cs index 9f4f61b..1436285 100644 --- a/src/EllieBot/Modules/Games/GamesService.cs +++ b/src/EllieBot/Modules/Games/GamesService.cs @@ -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 GirlRatings { get; } = new(); public IReadOnlyList EightBallResponses => _gamesConfig.Data.EightBallResponses; @@ -25,7 +23,6 @@ public class GamesService : IEService, IReadyExecutor public ConcurrentDictionary RunningContests { get; } = new(); public ConcurrentDictionary NunchiGames { get; } = new(); - public AsyncLazy 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 GetRatingTexts() - { - using var http = _httpFactory.CreateClient(); - var text = await http.GetStringAsync( - "https://nadeko-pictures.nyc3.digitaloceanspaces.com/other/rategirl/rates.json"); - return JsonConvert.DeserializeObject(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; } - } } \ No newline at end of file diff --git a/src/EllieBot/Modules/Games/GirlRating.cs b/src/EllieBot/Modules/Games/GirlRating.cs deleted file mode 100644 index 4576216..0000000 --- a/src/EllieBot/Modules/Games/GirlRating.cs +++ /dev/null @@ -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 { 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; - } - }); - } -} \ No newline at end of file diff --git a/src/EllieBot/Services/Impl/ImageCache.cs b/src/EllieBot/Services/Impl/ImageCache.cs index 4fc4e72..cf18590 100644 --- a/src/EllieBot/Services/Impl/ImageCache.cs +++ b/src/EllieBot/Services/Impl/ImageCache.cs @@ -60,12 +60,6 @@ public sealed class ImageCache : IImageCache, IEService public Task GetXpBackgroundImageAsync() => GetImageDataAsync(_ic.Data.Xp.Bg); - public Task GetRategirlBgAsync() - => GetImageDataAsync(_ic.Data.Rategirl.Matrix); - - public Task GetRategirlDotAsync() - => GetImageDataAsync(_ic.Data.Rategirl.Dot); - public Task GetDiceAsync(int num) => GetImageDataAsync(_ic.Data.Dice[num]); diff --git a/src/EllieBot/_common/ImageUrls.cs b/src/EllieBot/_common/ImageUrls.cs index 5dc9557..fa253a7 100644 --- a/src/EllieBot/_common/ImageUrls.cs +++ b/src/EllieBot/_common/ImageUrls.cs @@ -8,12 +8,11 @@ namespace EllieBot.Common; public partial class ImageUrls : ICloneable { [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 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; } diff --git a/src/EllieBot/_common/Services/Impl/IImageCache.cs b/src/EllieBot/_common/Services/Impl/IImageCache.cs index 890eeea..5a7e01c 100644 --- a/src/EllieBot/_common/Services/Impl/IImageCache.cs +++ b/src/EllieBot/_common/Services/Impl/IImageCache.cs @@ -6,8 +6,6 @@ public interface IImageCache Task GetTailsImageAsync(); Task GetCurrencyImageAsync(); Task GetXpBackgroundImageAsync(); - Task GetRategirlBgAsync(); - Task GetRategirlDotAsync(); Task GetDiceAsync(int num); Task GetSlotEmojiAsync(int number); Task GetSlotBgAsync(); diff --git a/src/EllieBot/_common/Services/Impl/ImagesConfig.cs b/src/EllieBot/_common/Services/Impl/ImagesConfig.cs index 821d717..a730a94 100644 --- a/src/EllieBot/_common/Services/Impl/ImagesConfig.cs +++ b/src/EllieBot/_common/Services/Impl/ImagesConfig.cs @@ -15,5 +15,17 @@ public sealed class ImagesConfig : ConfigServiceBase public ImagesConfig(IConfigSeria serializer, IPubSub pubSub) : base(PATH, serializer, pubSub, _changeKey) { + Migrate(); + } + + private void Migrate() + { + if (data.Version < 5) + { + ModifyConfig(c => + { + c.Version = 5; + }); + } } } \ No newline at end of file diff --git a/src/EllieBot/data/images.yml b/src/EllieBot/data/images.yml index 73ea5e6..76d8da6 100644 --- a/src/EllieBot/data/images.yml +++ b/src/EllieBot/data/images.yml @@ -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: