diff --git a/Geekbot.net/Lib/CatClient.cs b/Geekbot.net/Lib/IClients/CatClient.cs similarity index 100% rename from Geekbot.net/Lib/CatClient.cs rename to Geekbot.net/Lib/IClients/CatClient.cs diff --git a/Geekbot.net/Lib/IClients/RandomClient.cs b/Geekbot.net/Lib/IClients/RandomClient.cs new file mode 100644 index 0000000..b6a3a50 --- /dev/null +++ b/Geekbot.net/Lib/IClients/RandomClient.cs @@ -0,0 +1,29 @@ +using System; + +namespace Geekbot.net.Lib.IClients +{ + + public interface IRandomClient + { + Random Client { get; set; } + } + + public sealed class RandomClient : IRandomClient + { + public RandomClient() + { + try + { + Client = new Random(); + } + catch (Exception) + { + Console.WriteLine("Start Redis pls..."); + Environment.Exit(1); + } + } + + public Random Client { get; set; } + } + +} \ No newline at end of file diff --git a/Geekbot.net/Lib/RedisClient.cs b/Geekbot.net/Lib/IClients/RedisClient.cs similarity index 100% rename from Geekbot.net/Lib/RedisClient.cs rename to Geekbot.net/Lib/IClients/RedisClient.cs diff --git a/Geekbot.net/Modules/EightBall.cs b/Geekbot.net/Modules/EightBall.cs index a29e451..d845fc7 100644 --- a/Geekbot.net/Modules/EightBall.cs +++ b/Geekbot.net/Modules/EightBall.cs @@ -2,11 +2,18 @@ using System.Collections.Generic; using System.Threading.Tasks; using Discord.Commands; +using Geekbot.net.Lib.IClients; namespace Geekbot.net.Modules { public class EightBall : ModuleBase { + private readonly IRandomClient rnd; + public EightBall(IRandomClient randomClient) + { + rnd = randomClient; + } + [Command("8ball"), Summary("Ask 8Ball a Question.")] public async Task Ball([Remainder, Summary("The Question")] string echo) { @@ -32,8 +39,7 @@ namespace Geekbot.net.Modules "Outlook not so good", "Very doubtful"}; - var rnd = new Random(); - var answer = rnd.Next(replies.Count); + var answer = rnd.Client.Next(replies.Count); await ReplyAsync(replies[answer]); } } diff --git a/Geekbot.net/Modules/Roll.cs b/Geekbot.net/Modules/Roll.cs index b0d162e..cfc4957 100644 --- a/Geekbot.net/Modules/Roll.cs +++ b/Geekbot.net/Modules/Roll.cs @@ -1,23 +1,24 @@ -using System; -using System.Threading.Tasks; +using System.Threading.Tasks; using Discord.Commands; using Geekbot.net.Lib; +using Geekbot.net.Lib.IClients; namespace Geekbot.net.Modules { public class Roll : ModuleBase { private readonly IRedisClient redis; - public Roll(IRedisClient redisClient) + private readonly IRandomClient rnd; + public Roll(IRedisClient redisClient, IRandomClient randomClient) { redis = redisClient; + rnd = randomClient; } [Command("roll"), Summary("Roll a number between 1 and 100.")] public async Task RollCommand([Remainder, Summary("stuff...")] string stuff = "nothing") { - var rnd = new Random(); - var number = rnd.Next(1, 100); + var number = rnd.Client.Next(1, 100); var guess = 1000; int.TryParse(stuff, out guess); if (guess <= 100 && guess > 0) @@ -40,8 +41,7 @@ namespace Geekbot.net.Modules [Command("dice"), Summary("Roll a dice")] public async Task DiceCommand([Summary("The highest number on the dice")] int max = 6) { - var rnd = new Random(); - var number = rnd.Next(1, max); + var number = rnd.Client.Next(1, max); await ReplyAsync(Context.Message.Author.Mention + ", you rolled " + number); } } diff --git a/Geekbot.net/Program.cs b/Geekbot.net/Program.cs index 5337a79..34833d3 100755 --- a/Geekbot.net/Program.cs +++ b/Geekbot.net/Program.cs @@ -5,6 +5,7 @@ using Discord; using Discord.Commands; using Discord.WebSocket; using Geekbot.net.Lib; +using Geekbot.net.Lib.IClients; using Geekbot.net.Modules; namespace Geekbot.net @@ -51,6 +52,7 @@ namespace Geekbot.net map = new DependencyMap(); map.Add(new CatClient()); map.Add(redis); + map.Add(new RandomClient()); await InstallCommands(); Console.WriteLine("Connecting to Discord...");