Rework the media provider
This commit is contained in:
parent
cc22774729
commit
580a514ce5
6 changed files with 72 additions and 136 deletions
|
@ -2,13 +2,6 @@
|
|||
{
|
||||
public interface IMediaProvider
|
||||
{
|
||||
string GetPanda();
|
||||
string GetCrossant();
|
||||
string GetSquirrel();
|
||||
string GetPumpkin();
|
||||
string GetTurtle();
|
||||
string GetPinguin();
|
||||
string GetFox();
|
||||
string GetDab();
|
||||
string GetMedia(MediaType type);
|
||||
}
|
||||
}
|
|
@ -1,133 +1,62 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
using Geekbot.net.Lib.Logger;
|
||||
using Geekbot.net.Lib.RandomNumberGenerator;
|
||||
|
||||
namespace Geekbot.net.Lib.Media
|
||||
{
|
||||
public class MediaProvider : IMediaProvider
|
||||
{
|
||||
private readonly Random _random;
|
||||
private readonly IRandomNumberGenerator _random;
|
||||
private readonly IGeekbotLogger _logger;
|
||||
private string[] _pandaImages;
|
||||
private string[] _croissantImages;
|
||||
private string[] _squirrelImages;
|
||||
private string[] _pumpkinImages;
|
||||
private string[] _turtlesImages;
|
||||
private string[] _pinguinImages;
|
||||
private string[] _penguinImages;
|
||||
private string[] _foxImages;
|
||||
private string[] _dabImages;
|
||||
|
||||
public MediaProvider(IGeekbotLogger logger)
|
||||
public MediaProvider(IGeekbotLogger logger, IRandomNumberGenerator random)
|
||||
{
|
||||
_random = new Random();
|
||||
_random = random;
|
||||
_logger = logger;
|
||||
|
||||
logger.Information(LogSource.Geekbot, "Loading Media Files");
|
||||
;
|
||||
LoadPandas();
|
||||
BakeCroissants();
|
||||
LoadSquirrels();
|
||||
LoadPumpkins();
|
||||
LoadTurtles();
|
||||
LoadPinguins();
|
||||
LoadFoxes();
|
||||
LoadDab();
|
||||
}
|
||||
|
||||
private void LoadPandas()
|
||||
{
|
||||
var rawLinks = File.ReadAllText(Path.GetFullPath("./Storage/pandas"));
|
||||
_pandaImages = rawLinks.Split("\n");
|
||||
_logger.Trace(LogSource.Geekbot, $"Loaded {_pandaImages.Length} Panda Images");
|
||||
}
|
||||
|
||||
private void BakeCroissants()
|
||||
{
|
||||
var rawLinks = File.ReadAllText(Path.GetFullPath("./Storage/croissant"));
|
||||
_croissantImages = rawLinks.Split("\n");
|
||||
_logger.Trace(LogSource.Geekbot, $"Loaded {_croissantImages.Length} Croissant Images");
|
||||
}
|
||||
|
||||
private void LoadSquirrels()
|
||||
{
|
||||
var rawLinks = File.ReadAllText(Path.GetFullPath("./Storage/squirrel"));
|
||||
_squirrelImages = rawLinks.Split("\n");
|
||||
_logger.Trace(LogSource.Geekbot, $"Loaded {_squirrelImages.Length} Squirrel Images");
|
||||
}
|
||||
|
||||
private void LoadPumpkins()
|
||||
{
|
||||
var rawLinks = File.ReadAllText(Path.GetFullPath("./Storage/pumpkin"));
|
||||
_pumpkinImages = rawLinks.Split("\n");
|
||||
_logger.Trace(LogSource.Geekbot, $"Loaded {_pumpkinImages.Length} Pumpkin Images");
|
||||
}
|
||||
|
||||
private void LoadTurtles()
|
||||
{
|
||||
var rawLinks = File.ReadAllText(Path.GetFullPath("./Storage/turtles"));
|
||||
_turtlesImages = rawLinks.Split("\n");
|
||||
_logger.Trace(LogSource.Geekbot, $"Loaded {_turtlesImages.Length} Turtle Images");
|
||||
}
|
||||
|
||||
private void LoadPinguins()
|
||||
{
|
||||
var rawLinks = File.ReadAllText(Path.GetFullPath("./Storage/pinguins"));
|
||||
_pinguinImages = rawLinks.Split("\n");
|
||||
_logger.Trace(LogSource.Geekbot, $"Loaded {_pinguinImages.Length} Pinguin Images");
|
||||
}
|
||||
|
||||
private void LoadFoxes()
|
||||
{
|
||||
var rawLinks = File.ReadAllText(Path.GetFullPath("./Storage/foxes"));
|
||||
_foxImages = rawLinks.Split("\n");
|
||||
_logger.Trace(LogSource.Geekbot, $"Loaded {_foxImages.Length} Foxes Images");
|
||||
}
|
||||
|
||||
private void LoadDab()
|
||||
{
|
||||
var rawLinks = File.ReadAllText(Path.GetFullPath("./Storage/dab"));
|
||||
_dabImages = rawLinks.Split("\n");
|
||||
_logger.Trace(LogSource.Geekbot, $"Loaded {_dabImages.Length} Dab Images");
|
||||
LoadMedia("./Storage/pandas", ref _pandaImages);
|
||||
LoadMedia("./Storage/croissant", ref _croissantImages);
|
||||
LoadMedia("./Storage/squirrel", ref _squirrelImages);
|
||||
LoadMedia("./Storage/pumpkin", ref _pumpkinImages);
|
||||
LoadMedia("./Storage/turtles", ref _turtlesImages);
|
||||
LoadMedia("./Storage/penguins", ref _penguinImages);
|
||||
LoadMedia("./Storage/foxes", ref _foxImages);
|
||||
LoadMedia("./Storage/dab", ref _dabImages);
|
||||
}
|
||||
|
||||
public string GetPanda()
|
||||
private void LoadMedia(string path, ref string[] storage)
|
||||
{
|
||||
return _pandaImages[_random.Next(0, _pandaImages.Length)];
|
||||
var rawLinks = File.ReadAllText(Path.GetFullPath(path));
|
||||
storage = rawLinks.Split("\n");
|
||||
_logger.Trace(LogSource.Geekbot, $"Loaded {storage.Length} Images from ${path}");
|
||||
}
|
||||
|
||||
public string GetCrossant()
|
||||
|
||||
public string GetMedia(MediaType type)
|
||||
{
|
||||
return _croissantImages[_random.Next(0, _croissantImages.Length)];
|
||||
}
|
||||
|
||||
public string GetSquirrel()
|
||||
{
|
||||
return _squirrelImages[_random.Next(0, _squirrelImages.Length)];
|
||||
}
|
||||
|
||||
public string GetPumpkin()
|
||||
{
|
||||
return _pumpkinImages[_random.Next(0, _pumpkinImages.Length)];
|
||||
}
|
||||
|
||||
public string GetTurtle()
|
||||
{
|
||||
return _turtlesImages[_random.Next(0, _turtlesImages.Length)];
|
||||
}
|
||||
|
||||
public string GetPinguin()
|
||||
{
|
||||
return _pinguinImages[_random.Next(0, _pinguinImages.Length)];
|
||||
}
|
||||
|
||||
public string GetFox()
|
||||
{
|
||||
return _foxImages[_random.Next(0, _foxImages.Length)];
|
||||
}
|
||||
|
||||
public string GetDab()
|
||||
{
|
||||
return _dabImages[_random.Next(0, _dabImages.Length)];
|
||||
var collection = type switch
|
||||
{
|
||||
MediaType.Panda => _pandaImages,
|
||||
MediaType.Croissant => _croissantImages,
|
||||
MediaType.Squirrel => _squirrelImages,
|
||||
MediaType.Pumpkin => _pumpkinImages,
|
||||
MediaType.Turtle => _turtlesImages,
|
||||
MediaType.Penguin => _penguinImages,
|
||||
MediaType.Fox => _foxImages,
|
||||
MediaType.Dab => _dabImages
|
||||
};
|
||||
|
||||
return collection[_random.Next(0, collection.Length)];
|
||||
}
|
||||
}
|
||||
}
|
14
Geekbot.net/Lib/Media/MediaType.cs
Normal file
14
Geekbot.net/Lib/Media/MediaType.cs
Normal file
|
@ -0,0 +1,14 @@
|
|||
namespace Geekbot.net.Lib.Media
|
||||
{
|
||||
public enum MediaType
|
||||
{
|
||||
Panda,
|
||||
Croissant,
|
||||
Squirrel,
|
||||
Pumpkin,
|
||||
Turtle,
|
||||
Penguin,
|
||||
Fox,
|
||||
Dab
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue