Moved store providers to geekbot.net.lib.media

This commit is contained in:
Runebaas 2017-09-27 17:18:31 +02:00
parent 0078de8a7f
commit 7308e5257a
No known key found for this signature in database
GPG key ID: 2677AF508D0300D6
9 changed files with 13 additions and 9 deletions

View file

@ -0,0 +1,41 @@
using System;
using System.IO;
using Serilog;
namespace Geekbot.net.Lib.Media
{
public class CheckEmImageProvider : ICheckEmImageProvider
{
private readonly string[] checkEmImageArray;
private readonly Random rnd;
private readonly int totalCheckEmImages;
public CheckEmImageProvider(Random rnd, ILogger logger)
{
var path = Path.GetFullPath("./Storage/checkEmPics");
if (File.Exists(path))
{
var rawCheckEmPics = File.ReadAllText(path);
checkEmImageArray = rawCheckEmPics.Split("\n");
totalCheckEmImages = checkEmImageArray.Length;
this.rnd = rnd;
logger.Information($"[Geekbot] [CheckEm] Loaded {totalCheckEmImages} CheckEm Images");
}
else
{
logger.Error("checkEmPics File not found");
logger.Error($"Path should be {path}");
}
}
public string GetRandomCheckEmPic()
{
return checkEmImageArray[rnd.Next(0, totalCheckEmImages)];
}
}
public interface ICheckEmImageProvider
{
string GetRandomCheckEmPic();
}
}

View file

@ -0,0 +1,41 @@
using System;
using System.IO;
using Serilog;
namespace Geekbot.net.Lib.Media
{
internal class FortunesProvider : IFortunesProvider
{
private readonly string[] fortuneArray;
private readonly Random rnd;
private readonly int totalFortunes;
public FortunesProvider(Random rnd, ILogger logger)
{
var path = Path.GetFullPath("./Storage/fortunes");
if (File.Exists(path))
{
var rawFortunes = File.ReadAllText(path);
fortuneArray = rawFortunes.Split("%");
totalFortunes = fortuneArray.Length;
this.rnd = rnd;
logger.Information($"[Geekbot] [Fortunes] Loaded {totalFortunes} Fortunes");
}
else
{
logger.Error("Fortunes File not found");
logger.Error($"Path should be {path}");
}
}
public string GetRandomFortune()
{
return fortuneArray[rnd.Next(0, totalFortunes)];
}
}
public interface IFortunesProvider
{
string GetRandomFortune();
}
}

View file

@ -0,0 +1,41 @@
using System;
using System.IO;
using Serilog;
namespace Geekbot.net.Lib.Media
{
public class PandaProvider : IPandaProvider
{
private readonly string[] PandaArray;
private readonly Random rnd;
private readonly int totalPandas;
public PandaProvider(Random rnd, ILogger logger)
{
var path = Path.GetFullPath("./Storage/pandas");
if (File.Exists(path))
{
var rawFortunes = File.ReadAllText(path);
PandaArray = rawFortunes.Split("\n");
totalPandas = PandaArray.Length;
this.rnd = rnd;
logger.Information($"[Geekbot] [Pandas] Loaded {totalPandas} Panda Images");
}
else
{
logger.Error("Pandas File not found");
logger.Error($"Path should be {path}");
}
}
public string GetRandomPanda()
{
return PandaArray[rnd.Next(0, totalPandas)];
}
}
public interface IPandaProvider
{
string GetRandomPanda();
}
}