2017-09-15 12:58:49 +02:00
|
|
|
|
using System;
|
|
|
|
|
using System.IO;
|
2017-09-26 13:02:38 +02:00
|
|
|
|
using Serilog;
|
2017-09-15 12:58:49 +02:00
|
|
|
|
|
2017-09-27 17:18:31 +02:00
|
|
|
|
namespace Geekbot.net.Lib.Media
|
2017-09-15 12:58:49 +02:00
|
|
|
|
{
|
|
|
|
|
public class CheckEmImageProvider : ICheckEmImageProvider
|
|
|
|
|
{
|
2017-09-15 22:56:03 +02:00
|
|
|
|
private readonly string[] checkEmImageArray;
|
|
|
|
|
private readonly Random rnd;
|
|
|
|
|
private readonly int totalCheckEmImages;
|
2017-09-15 12:58:49 +02:00
|
|
|
|
|
2017-09-26 13:02:38 +02:00
|
|
|
|
public CheckEmImageProvider(Random rnd, ILogger logger)
|
2017-09-15 12:58:49 +02:00
|
|
|
|
{
|
|
|
|
|
var path = Path.GetFullPath("./Storage/checkEmPics");
|
|
|
|
|
if (File.Exists(path))
|
|
|
|
|
{
|
|
|
|
|
var rawCheckEmPics = File.ReadAllText(path);
|
|
|
|
|
checkEmImageArray = rawCheckEmPics.Split("\n");
|
|
|
|
|
totalCheckEmImages = checkEmImageArray.Length;
|
2017-09-19 20:39:49 +02:00
|
|
|
|
this.rnd = rnd;
|
2017-09-27 22:48:09 +02:00
|
|
|
|
logger.Verbose($"[Geekbot] [CheckEm] Loaded {totalCheckEmImages} CheckEm Images");
|
2017-09-15 12:58:49 +02:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2017-09-26 13:02:38 +02:00
|
|
|
|
logger.Error("checkEmPics File not found");
|
|
|
|
|
logger.Error($"Path should be {path}");
|
2017-09-15 12:58:49 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string GetRandomCheckEmPic()
|
|
|
|
|
{
|
|
|
|
|
return checkEmImageArray[rnd.Next(0, totalCheckEmImages)];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public interface ICheckEmImageProvider
|
|
|
|
|
{
|
|
|
|
|
string GetRandomCheckEmPic();
|
|
|
|
|
}
|
|
|
|
|
}
|