geekbot/Geekbot.net/Lib/Media/PandaProvider.cs

41 lines
1.1 KiB
C#
Raw Normal View History

2017-09-19 20:39:49 +02:00
using System;
using System.IO;
2017-09-26 13:02:38 +02:00
using Serilog;
2017-09-19 20:39:49 +02:00
namespace Geekbot.net.Lib.Media
2017-09-19 20:39:49 +02:00
{
public class PandaProvider : IPandaProvider
{
private readonly string[] PandaArray;
private readonly Random rnd;
private readonly int totalPandas;
2017-09-26 13:02:38 +02:00
public PandaProvider(Random rnd, ILogger logger)
2017-09-19 20:39:49 +02:00
{
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.Verbose($"[Geekbot] [Pandas] Loaded {totalPandas} Panda Images");
2017-09-19 20:39:49 +02:00
}
else
{
2017-09-26 13:02:38 +02:00
logger.Error("Pandas File not found");
logger.Error($"Path should be {path}");
2017-09-19 20:39:49 +02:00
}
}
public string GetRandomPanda()
{
return PandaArray[rnd.Next(0, totalPandas)];
}
}
2017-09-26 13:02:38 +02:00
2017-09-19 20:39:49 +02:00
public interface IPandaProvider
{
string GetRandomPanda();
}
}