Random is now even more random
This commit is contained in:
parent
5dd7d343ee
commit
341de410f1
6 changed files with 46 additions and 9 deletions
29
Geekbot.net/Lib/IClients/RandomClient.cs
Normal file
29
Geekbot.net/Lib/IClients/RandomClient.cs
Normal file
|
@ -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; }
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -2,11 +2,18 @@
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Discord.Commands;
|
using Discord.Commands;
|
||||||
|
using Geekbot.net.Lib.IClients;
|
||||||
|
|
||||||
namespace Geekbot.net.Modules
|
namespace Geekbot.net.Modules
|
||||||
{
|
{
|
||||||
public class EightBall : ModuleBase
|
public class EightBall : ModuleBase
|
||||||
{
|
{
|
||||||
|
private readonly IRandomClient rnd;
|
||||||
|
public EightBall(IRandomClient randomClient)
|
||||||
|
{
|
||||||
|
rnd = randomClient;
|
||||||
|
}
|
||||||
|
|
||||||
[Command("8ball"), Summary("Ask 8Ball a Question.")]
|
[Command("8ball"), Summary("Ask 8Ball a Question.")]
|
||||||
public async Task Ball([Remainder, Summary("The Question")] string echo)
|
public async Task Ball([Remainder, Summary("The Question")] string echo)
|
||||||
{
|
{
|
||||||
|
@ -32,8 +39,7 @@ namespace Geekbot.net.Modules
|
||||||
"Outlook not so good",
|
"Outlook not so good",
|
||||||
"Very doubtful"};
|
"Very doubtful"};
|
||||||
|
|
||||||
var rnd = new Random();
|
var answer = rnd.Client.Next(replies.Count);
|
||||||
var answer = rnd.Next(replies.Count);
|
|
||||||
await ReplyAsync(replies[answer]);
|
await ReplyAsync(replies[answer]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,23 +1,24 @@
|
||||||
using System;
|
using System.Threading.Tasks;
|
||||||
using System.Threading.Tasks;
|
|
||||||
using Discord.Commands;
|
using Discord.Commands;
|
||||||
using Geekbot.net.Lib;
|
using Geekbot.net.Lib;
|
||||||
|
using Geekbot.net.Lib.IClients;
|
||||||
|
|
||||||
namespace Geekbot.net.Modules
|
namespace Geekbot.net.Modules
|
||||||
{
|
{
|
||||||
public class Roll : ModuleBase
|
public class Roll : ModuleBase
|
||||||
{
|
{
|
||||||
private readonly IRedisClient redis;
|
private readonly IRedisClient redis;
|
||||||
public Roll(IRedisClient redisClient)
|
private readonly IRandomClient rnd;
|
||||||
|
public Roll(IRedisClient redisClient, IRandomClient randomClient)
|
||||||
{
|
{
|
||||||
redis = redisClient;
|
redis = redisClient;
|
||||||
|
rnd = randomClient;
|
||||||
}
|
}
|
||||||
|
|
||||||
[Command("roll"), Summary("Roll a number between 1 and 100.")]
|
[Command("roll"), Summary("Roll a number between 1 and 100.")]
|
||||||
public async Task RollCommand([Remainder, Summary("stuff...")] string stuff = "nothing")
|
public async Task RollCommand([Remainder, Summary("stuff...")] string stuff = "nothing")
|
||||||
{
|
{
|
||||||
var rnd = new Random();
|
var number = rnd.Client.Next(1, 100);
|
||||||
var number = rnd.Next(1, 100);
|
|
||||||
var guess = 1000;
|
var guess = 1000;
|
||||||
int.TryParse(stuff, out guess);
|
int.TryParse(stuff, out guess);
|
||||||
if (guess <= 100 && guess > 0)
|
if (guess <= 100 && guess > 0)
|
||||||
|
@ -40,8 +41,7 @@ namespace Geekbot.net.Modules
|
||||||
[Command("dice"), Summary("Roll a dice")]
|
[Command("dice"), Summary("Roll a dice")]
|
||||||
public async Task DiceCommand([Summary("The highest number on the dice")] int max = 6)
|
public async Task DiceCommand([Summary("The highest number on the dice")] int max = 6)
|
||||||
{
|
{
|
||||||
var rnd = new Random();
|
var number = rnd.Client.Next(1, max);
|
||||||
var number = rnd.Next(1, max);
|
|
||||||
await ReplyAsync(Context.Message.Author.Mention + ", you rolled " + number);
|
await ReplyAsync(Context.Message.Author.Mention + ", you rolled " + number);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,7 @@ using Discord;
|
||||||
using Discord.Commands;
|
using Discord.Commands;
|
||||||
using Discord.WebSocket;
|
using Discord.WebSocket;
|
||||||
using Geekbot.net.Lib;
|
using Geekbot.net.Lib;
|
||||||
|
using Geekbot.net.Lib.IClients;
|
||||||
using Geekbot.net.Modules;
|
using Geekbot.net.Modules;
|
||||||
|
|
||||||
namespace Geekbot.net
|
namespace Geekbot.net
|
||||||
|
@ -51,6 +52,7 @@ namespace Geekbot.net
|
||||||
map = new DependencyMap();
|
map = new DependencyMap();
|
||||||
map.Add<ICatClient>(new CatClient());
|
map.Add<ICatClient>(new CatClient());
|
||||||
map.Add(redis);
|
map.Add(redis);
|
||||||
|
map.Add<IRandomClient>(new RandomClient());
|
||||||
|
|
||||||
await InstallCommands();
|
await InstallCommands();
|
||||||
Console.WriteLine("Connecting to Discord...");
|
Console.WriteLine("Connecting to Discord...");
|
||||||
|
|
Loading…
Reference in a new issue