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")]
|
[Summary("Get a random panda image")]
|
||||||
public async Task Panda()
|
public async Task Panda()
|
||||||
{
|
{
|
||||||
await ReplyAsync("", false, Eb(_mediaProvider.GetPanda()));
|
await ReplyAsync("", false, Eb(_mediaProvider.GetMedia(MediaType.Panda)));
|
||||||
}
|
}
|
||||||
|
|
||||||
[Command("croissant", RunMode = RunMode.Async)]
|
[Command("croissant", RunMode = RunMode.Async)]
|
||||||
|
@ -26,50 +26,50 @@ namespace Geekbot.net.Commands.Randomness
|
||||||
[Summary("Get a random croissant image")]
|
[Summary("Get a random croissant image")]
|
||||||
public async Task Croissant()
|
public async Task Croissant()
|
||||||
{
|
{
|
||||||
await ReplyAsync("", false, Eb(_mediaProvider.GetCrossant()));
|
await ReplyAsync("", false, Eb(_mediaProvider.GetMedia(MediaType.Croissant)));
|
||||||
}
|
}
|
||||||
|
|
||||||
[Command("pumpkin", RunMode = RunMode.Async)]
|
[Command("pumpkin", RunMode = RunMode.Async)]
|
||||||
[Summary("Get a random pumpkin image")]
|
[Summary("Get a random pumpkin image")]
|
||||||
public async Task Pumpkin()
|
public async Task Pumpkin()
|
||||||
{
|
{
|
||||||
await ReplyAsync("", false, Eb(_mediaProvider.GetPumpkin()));
|
await ReplyAsync("", false, Eb(_mediaProvider.GetMedia(MediaType.Pumpkin)));
|
||||||
}
|
}
|
||||||
|
|
||||||
[Command("squirrel", RunMode = RunMode.Async)]
|
[Command("squirrel", RunMode = RunMode.Async)]
|
||||||
[Summary("Get a random squirrel image")]
|
[Summary("Get a random squirrel image")]
|
||||||
public async Task Squirrel()
|
public async Task Squirrel()
|
||||||
{
|
{
|
||||||
await ReplyAsync("", false, Eb(_mediaProvider.GetSquirrel()));
|
await ReplyAsync("", false, Eb(_mediaProvider.GetMedia(MediaType.Squirrel)));
|
||||||
}
|
}
|
||||||
|
|
||||||
[Command("turtle", RunMode = RunMode.Async)]
|
[Command("turtle", RunMode = RunMode.Async)]
|
||||||
[Summary("Get a random turtle image")]
|
[Summary("Get a random turtle image")]
|
||||||
public async Task Turtle()
|
public async Task Turtle()
|
||||||
{
|
{
|
||||||
await ReplyAsync("", false, Eb(_mediaProvider.GetTurtle()));
|
await ReplyAsync("", false, Eb(_mediaProvider.GetMedia(MediaType.Turtle)));
|
||||||
}
|
}
|
||||||
|
|
||||||
[Command("pinguin", RunMode = RunMode.Async)]
|
[Command("penguin", RunMode = RunMode.Async)]
|
||||||
[Alias("pingu")]
|
[Alias("pengu")]
|
||||||
[Summary("Get a random pinguin image")]
|
[Summary("Get a random penguin image")]
|
||||||
public async Task Pinguin()
|
public async Task Penguin()
|
||||||
{
|
{
|
||||||
await ReplyAsync("", false, Eb(_mediaProvider.GetPinguin()));
|
await ReplyAsync("", false, Eb(_mediaProvider.GetMedia(MediaType.Penguin)));
|
||||||
}
|
}
|
||||||
|
|
||||||
[Command("fox", RunMode = RunMode.Async)]
|
[Command("fox", RunMode = RunMode.Async)]
|
||||||
[Summary("Get a random fox image")]
|
[Summary("Get a random fox image")]
|
||||||
public async Task Fox()
|
public async Task Fox()
|
||||||
{
|
{
|
||||||
await ReplyAsync("", false, Eb(_mediaProvider.GetFox()));
|
await ReplyAsync("", false, Eb(_mediaProvider.GetMedia(MediaType.Fox)));
|
||||||
}
|
}
|
||||||
|
|
||||||
[Command("dab", RunMode = RunMode.Async)]
|
[Command("dab", RunMode = RunMode.Async)]
|
||||||
[Summary("Get a random dab image")]
|
[Summary("Get a random dab image")]
|
||||||
public async Task Dab()
|
public async Task Dab()
|
||||||
{
|
{
|
||||||
await ReplyAsync("", false, Eb(_mediaProvider.GetDab()));
|
await ReplyAsync("", false, Eb(_mediaProvider.GetMedia(MediaType.Dab)));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Embed Eb(string image)
|
private static Embed Eb(string image)
|
||||||
|
|
|
@ -2,13 +2,6 @@
|
||||||
{
|
{
|
||||||
public interface IMediaProvider
|
public interface IMediaProvider
|
||||||
{
|
{
|
||||||
string GetPanda();
|
string GetMedia(MediaType type);
|
||||||
string GetCrossant();
|
|
||||||
string GetSquirrel();
|
|
||||||
string GetPumpkin();
|
|
||||||
string GetTurtle();
|
|
||||||
string GetPinguin();
|
|
||||||
string GetFox();
|
|
||||||
string GetDab();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,133 +1,62 @@
|
||||||
using System;
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using Geekbot.net.Lib.Logger;
|
using Geekbot.net.Lib.Logger;
|
||||||
|
using Geekbot.net.Lib.RandomNumberGenerator;
|
||||||
|
|
||||||
namespace Geekbot.net.Lib.Media
|
namespace Geekbot.net.Lib.Media
|
||||||
{
|
{
|
||||||
public class MediaProvider : IMediaProvider
|
public class MediaProvider : IMediaProvider
|
||||||
{
|
{
|
||||||
private readonly Random _random;
|
private readonly IRandomNumberGenerator _random;
|
||||||
private readonly IGeekbotLogger _logger;
|
private readonly IGeekbotLogger _logger;
|
||||||
private string[] _pandaImages;
|
private string[] _pandaImages;
|
||||||
private string[] _croissantImages;
|
private string[] _croissantImages;
|
||||||
private string[] _squirrelImages;
|
private string[] _squirrelImages;
|
||||||
private string[] _pumpkinImages;
|
private string[] _pumpkinImages;
|
||||||
private string[] _turtlesImages;
|
private string[] _turtlesImages;
|
||||||
private string[] _pinguinImages;
|
private string[] _penguinImages;
|
||||||
private string[] _foxImages;
|
private string[] _foxImages;
|
||||||
private string[] _dabImages;
|
private string[] _dabImages;
|
||||||
|
|
||||||
public MediaProvider(IGeekbotLogger logger)
|
public MediaProvider(IGeekbotLogger logger, IRandomNumberGenerator random)
|
||||||
{
|
{
|
||||||
_random = new Random();
|
_random = random;
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
|
|
||||||
logger.Information(LogSource.Geekbot, "Loading Media Files");
|
logger.Information(LogSource.Geekbot, "Loading Media Files");
|
||||||
;
|
;
|
||||||
LoadPandas();
|
LoadMedia("./Storage/pandas", ref _pandaImages);
|
||||||
BakeCroissants();
|
LoadMedia("./Storage/croissant", ref _croissantImages);
|
||||||
LoadSquirrels();
|
LoadMedia("./Storage/squirrel", ref _squirrelImages);
|
||||||
LoadPumpkins();
|
LoadMedia("./Storage/pumpkin", ref _pumpkinImages);
|
||||||
LoadTurtles();
|
LoadMedia("./Storage/turtles", ref _turtlesImages);
|
||||||
LoadPinguins();
|
LoadMedia("./Storage/penguins", ref _penguinImages);
|
||||||
LoadFoxes();
|
LoadMedia("./Storage/foxes", ref _foxImages);
|
||||||
LoadDab();
|
LoadMedia("./Storage/dab", ref _dabImages);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void LoadPandas()
|
private void LoadMedia(string path, ref string[] storage)
|
||||||
{
|
{
|
||||||
var rawLinks = File.ReadAllText(Path.GetFullPath("./Storage/pandas"));
|
var rawLinks = File.ReadAllText(Path.GetFullPath(path));
|
||||||
_pandaImages = rawLinks.Split("\n");
|
storage = rawLinks.Split("\n");
|
||||||
_logger.Trace(LogSource.Geekbot, $"Loaded {_pandaImages.Length} Panda Images");
|
_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"));
|
var collection = type switch
|
||||||
_croissantImages = rawLinks.Split("\n");
|
{
|
||||||
_logger.Trace(LogSource.Geekbot, $"Loaded {_croissantImages.Length} Croissant Images");
|
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()
|
return collection[_random.Next(0, collection.Length)];
|
||||||
{
|
|
||||||
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)];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
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());
|
_reactionListener = new ReactionListener(_databaseInitializer.Initialize());
|
||||||
_guildSettingsManager = new GuildSettingsManager(_databaseInitializer.Initialize());
|
_guildSettingsManager = new GuildSettingsManager(_databaseInitializer.Initialize());
|
||||||
var fortunes = new FortunesProvider(_logger);
|
var fortunes = new FortunesProvider(_logger);
|
||||||
var mediaProvider = new MediaProvider(_logger);
|
|
||||||
var malClient = new MalClient(_globalSettings, _logger);
|
var malClient = new MalClient(_globalSettings, _logger);
|
||||||
var levelCalc = new LevelCalc();
|
var levelCalc = new LevelCalc();
|
||||||
var emojiConverter = new EmojiConverter();
|
var emojiConverter = new EmojiConverter();
|
||||||
var mtgManaConverter = new MtgManaConverter();
|
var mtgManaConverter = new MtgManaConverter();
|
||||||
var wikipediaClient = new WikipediaClient();
|
var wikipediaClient = new WikipediaClient();
|
||||||
var randomNumberGenerator = new RandomNumberGenerator();
|
var randomNumberGenerator = new RandomNumberGenerator();
|
||||||
|
var mediaProvider = new MediaProvider(_logger, randomNumberGenerator);
|
||||||
var kvMemoryStore = new KvInInMemoryStore();
|
var kvMemoryStore = new KvInInMemoryStore();
|
||||||
var translationHandler = new TranslationHandler(_logger, _guildSettingsManager);
|
var translationHandler = new TranslationHandler(_logger, _guildSettingsManager);
|
||||||
var errorHandler = new ErrorHandler(_logger, translationHandler, _runParameters);
|
var errorHandler = new ErrorHandler(_logger, translationHandler, _runParameters);
|
||||||
|
|
Loading…
Reference in a new issue