Rework the media provider
This commit is contained in:
parent
cc22774729
commit
580a514ce5
6 changed files with 72 additions and 136 deletions
|
@ -18,7 +18,7 @@ namespace Geekbot.net.Commands.Randomness
|
|||
[Summary("Get a random panda image")]
|
||||
public async Task Panda()
|
||||
{
|
||||
await ReplyAsync("", false, Eb(_mediaProvider.GetPanda()));
|
||||
await ReplyAsync("", false, Eb(_mediaProvider.GetMedia(MediaType.Panda)));
|
||||
}
|
||||
|
||||
[Command("croissant", RunMode = RunMode.Async)]
|
||||
|
@ -26,50 +26,50 @@ namespace Geekbot.net.Commands.Randomness
|
|||
[Summary("Get a random croissant image")]
|
||||
public async Task Croissant()
|
||||
{
|
||||
await ReplyAsync("", false, Eb(_mediaProvider.GetCrossant()));
|
||||
await ReplyAsync("", false, Eb(_mediaProvider.GetMedia(MediaType.Croissant)));
|
||||
}
|
||||
|
||||
[Command("pumpkin", RunMode = RunMode.Async)]
|
||||
[Summary("Get a random pumpkin image")]
|
||||
public async Task Pumpkin()
|
||||
{
|
||||
await ReplyAsync("", false, Eb(_mediaProvider.GetPumpkin()));
|
||||
await ReplyAsync("", false, Eb(_mediaProvider.GetMedia(MediaType.Pumpkin)));
|
||||
}
|
||||
|
||||
[Command("squirrel", RunMode = RunMode.Async)]
|
||||
[Summary("Get a random squirrel image")]
|
||||
public async Task Squirrel()
|
||||
{
|
||||
await ReplyAsync("", false, Eb(_mediaProvider.GetSquirrel()));
|
||||
await ReplyAsync("", false, Eb(_mediaProvider.GetMedia(MediaType.Squirrel)));
|
||||
}
|
||||
|
||||
[Command("turtle", RunMode = RunMode.Async)]
|
||||
[Summary("Get a random turtle image")]
|
||||
public async Task Turtle()
|
||||
{
|
||||
await ReplyAsync("", false, Eb(_mediaProvider.GetTurtle()));
|
||||
await ReplyAsync("", false, Eb(_mediaProvider.GetMedia(MediaType.Turtle)));
|
||||
}
|
||||
|
||||
[Command("pinguin", RunMode = RunMode.Async)]
|
||||
[Alias("pingu")]
|
||||
[Summary("Get a random pinguin image")]
|
||||
public async Task Pinguin()
|
||||
[Command("penguin", RunMode = RunMode.Async)]
|
||||
[Alias("pengu")]
|
||||
[Summary("Get a random penguin image")]
|
||||
public async Task Penguin()
|
||||
{
|
||||
await ReplyAsync("", false, Eb(_mediaProvider.GetPinguin()));
|
||||
await ReplyAsync("", false, Eb(_mediaProvider.GetMedia(MediaType.Penguin)));
|
||||
}
|
||||
|
||||
[Command("fox", RunMode = RunMode.Async)]
|
||||
[Summary("Get a random fox image")]
|
||||
public async Task Fox()
|
||||
{
|
||||
await ReplyAsync("", false, Eb(_mediaProvider.GetFox()));
|
||||
await ReplyAsync("", false, Eb(_mediaProvider.GetMedia(MediaType.Fox)));
|
||||
}
|
||||
|
||||
[Command("dab", RunMode = RunMode.Async)]
|
||||
[Summary("Get a random dab image")]
|
||||
public async Task Dab()
|
||||
{
|
||||
await ReplyAsync("", false, Eb(_mediaProvider.GetDab()));
|
||||
await ReplyAsync("", false, Eb(_mediaProvider.GetMedia(MediaType.Dab)));
|
||||
}
|
||||
|
||||
private static Embed Eb(string image)
|
||||
|
|
|
@ -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();
|
||||
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);
|
||||
}
|
||||
|
||||
private void LoadPandas()
|
||||
private void LoadMedia(string path, ref string[] storage)
|
||||
{
|
||||
var rawLinks = File.ReadAllText(Path.GetFullPath("./Storage/pandas"));
|
||||
_pandaImages = rawLinks.Split("\n");
|
||||
_logger.Trace(LogSource.Geekbot, $"Loaded {_pandaImages.Length} Panda Images");
|
||||
var rawLinks = File.ReadAllText(Path.GetFullPath(path));
|
||||
storage = rawLinks.Split("\n");
|
||||
_logger.Trace(LogSource.Geekbot, $"Loaded {storage.Length} Images from ${path}");
|
||||
}
|
||||
|
||||
private void BakeCroissants()
|
||||
public string GetMedia(MediaType type)
|
||||
{
|
||||
var rawLinks = File.ReadAllText(Path.GetFullPath("./Storage/croissant"));
|
||||
_croissantImages = rawLinks.Split("\n");
|
||||
_logger.Trace(LogSource.Geekbot, $"Loaded {_croissantImages.Length} Croissant Images");
|
||||
}
|
||||
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
|
||||
};
|
||||
|
||||
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");
|
||||
}
|
||||
|
||||
public string GetPanda()
|
||||
{
|
||||
return _pandaImages[_random.Next(0, _pandaImages.Length)];
|
||||
}
|
||||
|
||||
public string GetCrossant()
|
||||
{
|
||||
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)];
|
||||
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
|
||||
}
|
||||
}
|
|
@ -160,13 +160,13 @@ namespace Geekbot.net
|
|||
_reactionListener = new ReactionListener(_databaseInitializer.Initialize());
|
||||
_guildSettingsManager = new GuildSettingsManager(_databaseInitializer.Initialize());
|
||||
var fortunes = new FortunesProvider(_logger);
|
||||
var mediaProvider = new MediaProvider(_logger);
|
||||
var malClient = new MalClient(_globalSettings, _logger);
|
||||
var levelCalc = new LevelCalc();
|
||||
var emojiConverter = new EmojiConverter();
|
||||
var mtgManaConverter = new MtgManaConverter();
|
||||
var wikipediaClient = new WikipediaClient();
|
||||
var randomNumberGenerator = new RandomNumberGenerator();
|
||||
var mediaProvider = new MediaProvider(_logger, randomNumberGenerator);
|
||||
var kvMemoryStore = new KvInInMemoryStore();
|
||||
var translationHandler = new TranslationHandler(_logger, _guildSettingsManager);
|
||||
var errorHandler = new ErrorHandler(_logger, translationHandler, _runParameters);
|
||||
|
|
Loading…
Reference in a new issue