Adding Fortunes
This commit is contained in:
parent
40bbef9cd8
commit
35064cf90b
5 changed files with 9838 additions and 5 deletions
48
Geekbot.net/Lib/Fortunes.cs
Normal file
48
Geekbot.net/Lib/Fortunes.cs
Normal file
|
@ -0,0 +1,48 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace Geekbot.net.Lib
|
||||
{
|
||||
class Fortunes : IFortunes
|
||||
{
|
||||
private string[] fortuneArray;
|
||||
private int totalFortunes;
|
||||
private Random rnd;
|
||||
|
||||
public Fortunes()
|
||||
{
|
||||
var path = Path.GetFullPath("./fortunes");
|
||||
if (File.Exists(path))
|
||||
{
|
||||
var rawFortunes= File.ReadAllText(path);
|
||||
fortuneArray = rawFortunes.Split("%");
|
||||
totalFortunes = fortuneArray.Length;
|
||||
rnd = new Random();
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("Fortunes File not found");
|
||||
Console.WriteLine($"Path should be {path}");
|
||||
}
|
||||
}
|
||||
|
||||
public string GetRandomFortune()
|
||||
{
|
||||
return fortuneArray[rnd.Next(0, totalFortunes)];
|
||||
}
|
||||
|
||||
public string GetFortune(int id)
|
||||
{
|
||||
return fortuneArray[id];
|
||||
}
|
||||
}
|
||||
|
||||
public interface IFortunes
|
||||
{
|
||||
string GetRandomFortune();
|
||||
string GetFortune(int id);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue