Make random more random than the google bot
This commit is contained in:
parent
cabf942362
commit
acc8947782
11 changed files with 20 additions and 43 deletions
|
@ -12,11 +12,9 @@ namespace Geekbot.net.Commands
|
||||||
{
|
{
|
||||||
private readonly IMediaProvider _checkEmImages;
|
private readonly IMediaProvider _checkEmImages;
|
||||||
private readonly IErrorHandler _errorHandler;
|
private readonly IErrorHandler _errorHandler;
|
||||||
private readonly Random _rnd;
|
|
||||||
|
|
||||||
public CheckEm(Random RandomClient, IMediaProvider mediaProvider, IErrorHandler errorHandler)
|
public CheckEm(IMediaProvider mediaProvider, IErrorHandler errorHandler)
|
||||||
{
|
{
|
||||||
_rnd = RandomClient;
|
|
||||||
_checkEmImages = mediaProvider;
|
_checkEmImages = mediaProvider;
|
||||||
_errorHandler = errorHandler;
|
_errorHandler = errorHandler;
|
||||||
}
|
}
|
||||||
|
@ -28,7 +26,7 @@ namespace Geekbot.net.Commands
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var number = _rnd.Next(10000000, 99999999);
|
var number = new Random().Next(10000000, 99999999);
|
||||||
var dubtriqua = "";
|
var dubtriqua = "";
|
||||||
|
|
||||||
var ns = GetIntArray(number);
|
var ns = GetIntArray(number);
|
||||||
|
|
|
@ -8,12 +8,10 @@ namespace Geekbot.net.Commands
|
||||||
public class Choose : ModuleBase
|
public class Choose : ModuleBase
|
||||||
{
|
{
|
||||||
private readonly IErrorHandler _errorHandler;
|
private readonly IErrorHandler _errorHandler;
|
||||||
private readonly Random _rnd;
|
|
||||||
private readonly ITranslationHandler _translation;
|
private readonly ITranslationHandler _translation;
|
||||||
|
|
||||||
public Choose(Random RandomClient, IErrorHandler errorHandler, ITranslationHandler translation)
|
public Choose(IErrorHandler errorHandler, ITranslationHandler translation)
|
||||||
{
|
{
|
||||||
_rnd = RandomClient;
|
|
||||||
_errorHandler = errorHandler;
|
_errorHandler = errorHandler;
|
||||||
_translation = translation;
|
_translation = translation;
|
||||||
}
|
}
|
||||||
|
@ -28,7 +26,7 @@ namespace Geekbot.net.Commands
|
||||||
{
|
{
|
||||||
var transDict = _translation.GetDict(Context);
|
var transDict = _translation.GetDict(Context);
|
||||||
var choicesArray = choices.Split(';');
|
var choicesArray = choices.Split(';');
|
||||||
var choice = _rnd.Next(choicesArray.Length);
|
var choice = new Random().Next(choicesArray.Length);
|
||||||
await ReplyAsync(string.Format(transDict["Choice"], choicesArray[choice]));
|
await ReplyAsync(string.Format(transDict["Choice"], choicesArray[choice]));
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
|
|
|
@ -10,13 +10,6 @@ namespace Geekbot.net.Commands
|
||||||
{
|
{
|
||||||
public class Dice : ModuleBase
|
public class Dice : ModuleBase
|
||||||
{
|
{
|
||||||
private readonly Random _rnd;
|
|
||||||
|
|
||||||
public Dice(Random RandomClient)
|
|
||||||
{
|
|
||||||
_rnd = RandomClient;
|
|
||||||
}
|
|
||||||
|
|
||||||
[Command("dice", RunMode = RunMode.Async)]
|
[Command("dice", RunMode = RunMode.Async)]
|
||||||
[Remarks(CommandCategories.Randomness)]
|
[Remarks(CommandCategories.Randomness)]
|
||||||
[Summary("Roll a dice.")]
|
[Summary("Roll a dice.")]
|
||||||
|
@ -75,7 +68,7 @@ namespace Geekbot.net.Commands
|
||||||
var results = new List<int>();
|
var results = new List<int>();
|
||||||
for (var i = 0; i < dice.times; i++)
|
for (var i = 0; i < dice.times; i++)
|
||||||
{
|
{
|
||||||
var roll = _rnd.Next(1, dice.sides);
|
var roll = new Random().Next(1, dice.sides);
|
||||||
total += roll;
|
total += roll;
|
||||||
results.Add(roll);
|
results.Add(roll);
|
||||||
if (roll == dice.sides) extraText = "**Critical Hit!**";
|
if (roll == dice.sides) extraText = "**Critical Hit!**";
|
||||||
|
|
|
@ -9,11 +9,9 @@ namespace Geekbot.net.Commands
|
||||||
public class EightBall : ModuleBase
|
public class EightBall : ModuleBase
|
||||||
{
|
{
|
||||||
private readonly IErrorHandler _errorHandler;
|
private readonly IErrorHandler _errorHandler;
|
||||||
private readonly Random _rnd;
|
|
||||||
|
|
||||||
public EightBall(Random RandomClient, IErrorHandler errorHandler)
|
public EightBall(IErrorHandler errorHandler)
|
||||||
{
|
{
|
||||||
_rnd = RandomClient;
|
|
||||||
_errorHandler = errorHandler;
|
_errorHandler = errorHandler;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -48,7 +46,7 @@ namespace Geekbot.net.Commands
|
||||||
"Very doubtful"
|
"Very doubtful"
|
||||||
};
|
};
|
||||||
|
|
||||||
var answer = _rnd.Next(replies.Count);
|
var answer = new Random().Next(replies.Count);
|
||||||
await ReplyAsync(replies[answer]);
|
await ReplyAsync(replies[answer]);
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
|
|
|
@ -15,7 +15,7 @@ namespace Geekbot.net.Commands
|
||||||
private readonly IErrorHandler _errorHandler;
|
private readonly IErrorHandler _errorHandler;
|
||||||
private readonly IDatabase _redis;
|
private readonly IDatabase _redis;
|
||||||
|
|
||||||
public Quote(IDatabase redis, IErrorHandler errorHandler, Random random)
|
public Quote(IDatabase redis, IErrorHandler errorHandler)
|
||||||
{
|
{
|
||||||
_redis = redis;
|
_redis = redis;
|
||||||
_errorHandler = errorHandler;
|
_errorHandler = errorHandler;
|
||||||
|
|
|
@ -10,13 +10,11 @@ namespace Geekbot.net.Commands
|
||||||
{
|
{
|
||||||
private readonly IErrorHandler _errorHandler;
|
private readonly IErrorHandler _errorHandler;
|
||||||
private readonly IDatabase _redis;
|
private readonly IDatabase _redis;
|
||||||
private readonly Random _rnd;
|
|
||||||
private readonly ITranslationHandler _translation;
|
private readonly ITranslationHandler _translation;
|
||||||
|
|
||||||
public Roll(IDatabase redis, Random RandomClient, IErrorHandler errorHandler, ITranslationHandler translation)
|
public Roll(IDatabase redis, IErrorHandler errorHandler, ITranslationHandler translation)
|
||||||
{
|
{
|
||||||
_redis = redis;
|
_redis = redis;
|
||||||
_rnd = RandomClient;
|
|
||||||
_translation = translation;
|
_translation = translation;
|
||||||
_errorHandler = errorHandler;
|
_errorHandler = errorHandler;
|
||||||
}
|
}
|
||||||
|
@ -28,7 +26,7 @@ namespace Geekbot.net.Commands
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var number = _rnd.Next(1, 100);
|
var number = new Random().Next(1, 100);
|
||||||
var guess = 1000;
|
var guess = 1000;
|
||||||
int.TryParse(stuff, out guess);
|
int.TryParse(stuff, out guess);
|
||||||
var transDict = _translation.GetDict(Context);
|
var transDict = _translation.GetDict(Context);
|
||||||
|
|
|
@ -11,12 +11,10 @@ namespace Geekbot.net.Commands
|
||||||
{
|
{
|
||||||
private readonly IErrorHandler _errorHandler;
|
private readonly IErrorHandler _errorHandler;
|
||||||
private readonly IDatabase _redis;
|
private readonly IDatabase _redis;
|
||||||
private readonly Random _rnd;
|
|
||||||
|
|
||||||
public Ship(IDatabase redis, Random randomClient, IErrorHandler errorHandler)
|
public Ship(IDatabase redis, IErrorHandler errorHandler)
|
||||||
{
|
{
|
||||||
_redis = redis;
|
_redis = redis;
|
||||||
_rnd = randomClient;
|
|
||||||
_errorHandler = errorHandler;
|
_errorHandler = errorHandler;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,7 +35,7 @@ namespace Geekbot.net.Commands
|
||||||
var shippingRate = 0;
|
var shippingRate = 0;
|
||||||
if (dbval.IsNullOrEmpty)
|
if (dbval.IsNullOrEmpty)
|
||||||
{
|
{
|
||||||
shippingRate = _rnd.Next(1, 100);
|
shippingRate = new Random().Next(1, 100);
|
||||||
_redis.HashSet($"{Context.Guild.Id}:Ships", dbstring, shippingRate);
|
_redis.HashSet($"{Context.Guild.Id}:Ships", dbstring, shippingRate);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
|
@ -11,13 +11,11 @@ namespace Geekbot.net.Commands
|
||||||
public class Slap : ModuleBase
|
public class Slap : ModuleBase
|
||||||
{
|
{
|
||||||
private readonly IErrorHandler _errorHandler;
|
private readonly IErrorHandler _errorHandler;
|
||||||
private readonly Random _random;
|
|
||||||
private readonly IDatabase _redis;
|
private readonly IDatabase _redis;
|
||||||
|
|
||||||
public Slap(IErrorHandler errorHandler, Random random, IDatabase redis)
|
public Slap(IErrorHandler errorHandler, IDatabase redis)
|
||||||
{
|
{
|
||||||
_errorHandler = errorHandler;
|
_errorHandler = errorHandler;
|
||||||
_random = random;
|
|
||||||
_redis = redis;
|
_redis = redis;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -61,7 +59,7 @@ namespace Geekbot.net.Commands
|
||||||
_redis.HashIncrement($"{Context.Guild.Id}:SlapsRecieved", user.Id.ToString());
|
_redis.HashIncrement($"{Context.Guild.Id}:SlapsRecieved", user.Id.ToString());
|
||||||
_redis.HashIncrement($"{Context.Guild.Id}:SlapsGiven", Context.User.Id.ToString());
|
_redis.HashIncrement($"{Context.Guild.Id}:SlapsGiven", Context.User.Id.ToString());
|
||||||
|
|
||||||
await ReplyAsync($"{Context.User.Username} slapped {user.Username} with a {things[_random.Next(things.Count - 1)]}");
|
await ReplyAsync($"{Context.User.Username} slapped {user.Username} with a {things[new Random().Next(things.Count - 1)]}");
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
|
|
|
@ -7,10 +7,9 @@ namespace Geekbot.net.Lib.Media
|
||||||
internal class FortunesProvider : IFortunesProvider
|
internal class FortunesProvider : IFortunesProvider
|
||||||
{
|
{
|
||||||
private readonly string[] fortuneArray;
|
private readonly string[] fortuneArray;
|
||||||
private readonly Random rnd;
|
|
||||||
private readonly int totalFortunes;
|
private readonly int totalFortunes;
|
||||||
|
|
||||||
public FortunesProvider(Random rnd, IGeekbotLogger logger)
|
public FortunesProvider(IGeekbotLogger logger)
|
||||||
{
|
{
|
||||||
var path = Path.GetFullPath("./Storage/fortunes");
|
var path = Path.GetFullPath("./Storage/fortunes");
|
||||||
if (File.Exists(path))
|
if (File.Exists(path))
|
||||||
|
@ -18,7 +17,6 @@ namespace Geekbot.net.Lib.Media
|
||||||
var rawFortunes = File.ReadAllText(path);
|
var rawFortunes = File.ReadAllText(path);
|
||||||
fortuneArray = rawFortunes.Split("%");
|
fortuneArray = rawFortunes.Split("%");
|
||||||
totalFortunes = fortuneArray.Length;
|
totalFortunes = fortuneArray.Length;
|
||||||
this.rnd = rnd;
|
|
||||||
logger.Debug("Geekbot", "Loaded {totalFortunes} Fortunes");
|
logger.Debug("Geekbot", "Loaded {totalFortunes} Fortunes");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -29,7 +27,7 @@ namespace Geekbot.net.Lib.Media
|
||||||
|
|
||||||
public string GetRandomFortune()
|
public string GetRandomFortune()
|
||||||
{
|
{
|
||||||
return fortuneArray[rnd.Next(0, totalFortunes)];
|
return fortuneArray[new Random().Next(0, totalFortunes)];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -17,9 +17,9 @@ namespace Geekbot.net.Lib.Media
|
||||||
private string[] _pumpkinImages;
|
private string[] _pumpkinImages;
|
||||||
private string[] _turtlesImages;
|
private string[] _turtlesImages;
|
||||||
|
|
||||||
public MediaProvider(Random rnd, IGeekbotLogger logger)
|
public MediaProvider(IGeekbotLogger logger)
|
||||||
{
|
{
|
||||||
_random = rnd;
|
_random = new Random();
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
|
|
||||||
logger.Information("Geekbot", "Loading Media Files");
|
logger.Information("Geekbot", "Loading Media Files");
|
||||||
|
|
|
@ -94,9 +94,8 @@ namespace Geekbot.net
|
||||||
services = new ServiceCollection();
|
services = new ServiceCollection();
|
||||||
|
|
||||||
userRepository = new UserRepository(redis, logger);
|
userRepository = new UserRepository(redis, logger);
|
||||||
var randomClient = new Random();
|
var fortunes = new FortunesProvider(logger);
|
||||||
var fortunes = new FortunesProvider(randomClient, logger);
|
var mediaProvider = new MediaProvider(logger);
|
||||||
var mediaProvider = new MediaProvider(randomClient, logger);
|
|
||||||
var malClient = new MalClient(redis, logger);
|
var malClient = new MalClient(redis, logger);
|
||||||
var levelCalc = new LevelCalc();
|
var levelCalc = new LevelCalc();
|
||||||
var emojiConverter = new EmojiConverter();
|
var emojiConverter = new EmojiConverter();
|
||||||
|
@ -108,7 +107,6 @@ namespace Geekbot.net
|
||||||
services.AddSingleton<ILevelCalc>(levelCalc);
|
services.AddSingleton<ILevelCalc>(levelCalc);
|
||||||
services.AddSingleton<IEmojiConverter>(emojiConverter);
|
services.AddSingleton<IEmojiConverter>(emojiConverter);
|
||||||
services.AddSingleton<IAudioUtils>(audioUtils);
|
services.AddSingleton<IAudioUtils>(audioUtils);
|
||||||
services.AddSingleton(randomClient);
|
|
||||||
services.AddSingleton<IFortunesProvider>(fortunes);
|
services.AddSingleton<IFortunesProvider>(fortunes);
|
||||||
services.AddSingleton<IMediaProvider>(mediaProvider);
|
services.AddSingleton<IMediaProvider>(mediaProvider);
|
||||||
services.AddSingleton<IMalClient>(malClient);
|
services.AddSingleton<IMalClient>(malClient);
|
||||||
|
|
Loading…
Reference in a new issue