local image caching to redis done?
This commit is contained in:
		@@ -14,6 +14,7 @@ namespace NadekoBot.Modules.Games.Common
 | 
			
		||||
    public class GirlRating
 | 
			
		||||
    {
 | 
			
		||||
        private static readonly Logger _log = LogManager.GetCurrentClassLogger();
 | 
			
		||||
        private readonly IImageCache _images;
 | 
			
		||||
 | 
			
		||||
        public double Crazy { get; }
 | 
			
		||||
        public double Hot { get; }
 | 
			
		||||
@@ -21,8 +22,9 @@ namespace NadekoBot.Modules.Games.Common
 | 
			
		||||
        public string Advice { get; }
 | 
			
		||||
        public AsyncLazy<string> Url { get; }
 | 
			
		||||
 | 
			
		||||
        public GirlRating(IImagesService _images, double crazy, double hot, int roll, string advice)
 | 
			
		||||
        public GirlRating(IImageCache images, double crazy, double hot, int roll, string advice)
 | 
			
		||||
        {
 | 
			
		||||
            _images = images;
 | 
			
		||||
            Crazy = crazy;
 | 
			
		||||
            Hot = hot;
 | 
			
		||||
            Roll = roll;
 | 
			
		||||
@@ -45,7 +47,7 @@ namespace NadekoBot.Modules.Games.Common
 | 
			
		||||
                        using (var pointMs = new MemoryStream(_images.RategirlDot.ToArray(), false))
 | 
			
		||||
                        using (var pointImg = Image.Load(pointMs))
 | 
			
		||||
                        {
 | 
			
		||||
                            img.DrawImage(pointImg, 100, default(Size), new Point(pointx - 10, pointy - 10));
 | 
			
		||||
                            img.DrawImage(pointImg, 100, default, new Point(pointx - 10, pointy - 10));
 | 
			
		||||
                        }
 | 
			
		||||
 | 
			
		||||
                        string url;
 | 
			
		||||
 
 | 
			
		||||
@@ -19,11 +19,11 @@ namespace NadekoBot.Modules.Games
 | 
			
		||||
    //todo update docs
 | 
			
		||||
    public partial class Games : NadekoTopLevelModule<GamesService>
 | 
			
		||||
    {
 | 
			
		||||
        private readonly IImagesService _images;
 | 
			
		||||
        private readonly IImageCache _images;
 | 
			
		||||
 | 
			
		||||
        public Games(IImagesService images)
 | 
			
		||||
        public Games(IDataCache data)
 | 
			
		||||
        {
 | 
			
		||||
            _images = images;
 | 
			
		||||
            _images = data.LocalImages;
 | 
			
		||||
        }
 | 
			
		||||
//#if GLOBAL_NADEKO
 | 
			
		||||
//        [NadekoCommand, Usage, Description, Aliases]
 | 
			
		||||
 
 | 
			
		||||
@@ -9,6 +9,7 @@ using System.Linq;
 | 
			
		||||
using System.Threading.Tasks;
 | 
			
		||||
using NadekoBot.Common.Attributes;
 | 
			
		||||
using NadekoBot.Modules.Games.Services;
 | 
			
		||||
using System;
 | 
			
		||||
 | 
			
		||||
namespace NadekoBot.Modules.Games
 | 
			
		||||
{
 | 
			
		||||
@@ -88,12 +89,18 @@ namespace NadekoBot.Modules.Games
 | 
			
		||||
                    else
 | 
			
		||||
                        msgToSend += " " + GetText("pick_sn", Prefix);
 | 
			
		||||
 | 
			
		||||
                    using (var toSend = imgData.Data.ToStream())
 | 
			
		||||
                    using (var toSend = imgData.ToStream())
 | 
			
		||||
                    {
 | 
			
		||||
                        msg = await Context.Channel.SendFileAsync(toSend, imgData.Name, msgToSend).ConfigureAwait(false);
 | 
			
		||||
                        msg = await Context.Channel.SendFileAsync(toSend, "plant.png", msgToSend, options: new RequestOptions()
 | 
			
		||||
                        {
 | 
			
		||||
                            RetryMode = RetryMode.AlwaysRetry
 | 
			
		||||
                        }).ConfigureAwait(false);
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
                catch { }
 | 
			
		||||
                catch (Exception ex)
 | 
			
		||||
                {
 | 
			
		||||
                    _log.Warn(ex);
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                var msgs = new IUserMessage[amount];
 | 
			
		||||
                msgs[0] = msg;
 | 
			
		||||
 
 | 
			
		||||
@@ -35,7 +35,7 @@ namespace NadekoBot.Modules.Games.Services
 | 
			
		||||
        private readonly Timer _t;
 | 
			
		||||
        private readonly CommandHandler _cmd;
 | 
			
		||||
        private readonly NadekoStrings _strings;
 | 
			
		||||
        private readonly IImagesService _images;
 | 
			
		||||
        private readonly IImageCache _images;
 | 
			
		||||
        private readonly Logger _log;
 | 
			
		||||
        private readonly NadekoRandom _rng;
 | 
			
		||||
        private readonly CurrencyService _cs;
 | 
			
		||||
@@ -57,13 +57,13 @@ namespace NadekoBot.Modules.Games.Services
 | 
			
		||||
        public ConcurrentDictionary<ulong, Nunchi> NunchiGames { get; } = new ConcurrentDictionary<ulong, Common.Nunchi.Nunchi>();
 | 
			
		||||
 | 
			
		||||
        public GamesService(CommandHandler cmd, IBotConfigProvider bc, NadekoBot bot,
 | 
			
		||||
            NadekoStrings strings, IImagesService images, CommandHandler cmdHandler,
 | 
			
		||||
            NadekoStrings strings, IDataCache data, CommandHandler cmdHandler,
 | 
			
		||||
            CurrencyService cs)
 | 
			
		||||
        {
 | 
			
		||||
            _bc = bc;
 | 
			
		||||
            _cmd = cmd;
 | 
			
		||||
            _strings = strings;
 | 
			
		||||
            _images = images;
 | 
			
		||||
            _images = data.LocalImages;
 | 
			
		||||
            _cmdHandler = cmdHandler;
 | 
			
		||||
            _log = LogManager.GetCurrentClassLogger();
 | 
			
		||||
            _rng = new NadekoRandom();
 | 
			
		||||
@@ -144,10 +144,11 @@ namespace NadekoBot.Modules.Games.Services
 | 
			
		||||
        private ConcurrentDictionary<ulong, object> _locks { get; } = new ConcurrentDictionary<ulong, object>();
 | 
			
		||||
        public ConcurrentHashSet<ulong> HalloweenAwardedUsers { get; } = new ConcurrentHashSet<ulong>();
 | 
			
		||||
 | 
			
		||||
        public (string Name, ImmutableArray<byte> Data) GetRandomCurrencyImage()
 | 
			
		||||
        public byte[] GetRandomCurrencyImage()
 | 
			
		||||
        {
 | 
			
		||||
            var rng = new NadekoRandom();
 | 
			
		||||
            return _images.Currency[rng.Next(0, _images.Currency.Length)];
 | 
			
		||||
            var cur = _images.Currency;
 | 
			
		||||
            return cur[rng.Next(0, cur.Length)];
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private string GetText(ITextChannel ch, string key, params object[] rep)
 | 
			
		||||
@@ -195,11 +196,11 @@ namespace NadekoBot.Modules.Games.Services
 | 
			
		||||
                                : GetText(channel, "curgen_pl", dropAmount, _bc.BotConfig.CurrencySign)
 | 
			
		||||
                                    + " " + GetText(channel, "pick_pl", prefix);
 | 
			
		||||
                            var file = GetRandomCurrencyImage();
 | 
			
		||||
                            using (var fileStream = file.Data.ToStream())
 | 
			
		||||
                            using (var fileStream = file.ToStream())
 | 
			
		||||
                            {
 | 
			
		||||
                                var sent = await channel.SendFileAsync(
 | 
			
		||||
                                    fileStream,
 | 
			
		||||
                                    file.Name,
 | 
			
		||||
                                    "drop.png",
 | 
			
		||||
                                    toSend).ConfigureAwait(false);
 | 
			
		||||
 | 
			
		||||
                                msgs[0] = sent;
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user