Remove random.org integration
This commit is contained in:
parent
989057a0b0
commit
5c507b026c
5 changed files with 5 additions and 38 deletions
|
@ -162,7 +162,7 @@ namespace Geekbot.Bot
|
||||||
var emojiConverter = new EmojiConverter();
|
var emojiConverter = new EmojiConverter();
|
||||||
var mtgManaConverter = new MtgManaConverter();
|
var mtgManaConverter = new MtgManaConverter();
|
||||||
var wikipediaClient = new WikipediaClient();
|
var wikipediaClient = new WikipediaClient();
|
||||||
var randomNumberGenerator = new RandomNumberGenerator(_globalSettings);
|
var randomNumberGenerator = new RandomNumberGenerator();
|
||||||
var mediaProvider = new MediaProvider(_logger, randomNumberGenerator);
|
var mediaProvider = new MediaProvider(_logger, randomNumberGenerator);
|
||||||
var kvMemoryStore = new KvInInMemoryStore();
|
var kvMemoryStore = new KvInInMemoryStore();
|
||||||
var errorHandler = new ErrorHandler(_logger, _runParameters, () => Localization.Internal.SomethingWentWrong);
|
var errorHandler = new ErrorHandler(_logger, _runParameters, () => Localization.Internal.SomethingWentWrong);
|
||||||
|
|
|
@ -12,7 +12,6 @@
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Anemonis.RandomOrg" Version="1.14.0" />
|
|
||||||
<PackageReference Include="CommandLineParser" Version="2.8.0" />
|
<PackageReference Include="CommandLineParser" Version="2.8.0" />
|
||||||
<PackageReference Include="Discord.Net" Version="2.4.0" />
|
<PackageReference Include="Discord.Net" Version="2.4.0" />
|
||||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="6.0.0-preview.2.21154.2" />
|
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="6.0.0-preview.2.21154.2" />
|
||||||
|
|
|
@ -1,25 +1,14 @@
|
||||||
using System;
|
using System;
|
||||||
using Anemonis.RandomOrg;
|
|
||||||
using Geekbot.Core.GlobalSettings;
|
|
||||||
|
|
||||||
namespace Geekbot.Core.RandomNumberGenerator
|
namespace Geekbot.Core.RandomNumberGenerator
|
||||||
{
|
{
|
||||||
public class RandomNumberGenerator : IRandomNumberGenerator
|
public class RandomNumberGenerator : IRandomNumberGenerator
|
||||||
{
|
{
|
||||||
private readonly System.Security.Cryptography.RandomNumberGenerator rng;
|
private readonly System.Security.Cryptography.RandomNumberGenerator rng;
|
||||||
private readonly bool _canUseRandomOrg;
|
|
||||||
private readonly RandomOrgClient _randomOrgClient;
|
|
||||||
|
|
||||||
public RandomNumberGenerator(IGlobalSettings globalSettings)
|
public RandomNumberGenerator()
|
||||||
{
|
{
|
||||||
rng = System.Security.Cryptography.RandomNumberGenerator.Create();
|
rng = System.Security.Cryptography.RandomNumberGenerator.Create();
|
||||||
|
|
||||||
var randomOrgApiKey = globalSettings.GetKey("RandomOrgApiKey");
|
|
||||||
if (!string.IsNullOrEmpty(randomOrgApiKey))
|
|
||||||
{
|
|
||||||
_canUseRandomOrg = true;
|
|
||||||
_randomOrgClient = new RandomOrgClient(randomOrgApiKey);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public int Next(int minValue, int maxInclusiveValue)
|
public int Next(int minValue, int maxInclusiveValue)
|
||||||
|
@ -33,31 +22,10 @@ namespace Geekbot.Core.RandomNumberGenerator
|
||||||
{
|
{
|
||||||
throw new ArgumentOutOfRangeException("minValue", "must be lower than maxExclusiveValue");
|
throw new ArgumentOutOfRangeException("minValue", "must be lower than maxExclusiveValue");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_canUseRandomOrg)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
return GetFromRandomOrg(minValue, maxInclusiveValue);
|
|
||||||
}
|
|
||||||
catch
|
|
||||||
{
|
|
||||||
// ignore
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return GetFromCrypto(minValue, maxInclusiveValue);
|
return GetFromCrypto(minValue, maxInclusiveValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
private int GetFromRandomOrg(int minValue, int maxInclusiveValue)
|
|
||||||
{
|
|
||||||
return _randomOrgClient
|
|
||||||
.GenerateIntegersAsync(1, minValue, maxInclusiveValue, false)
|
|
||||||
.Result
|
|
||||||
.Random
|
|
||||||
.Data[0];
|
|
||||||
}
|
|
||||||
|
|
||||||
private int GetFromCrypto(int minValue, int maxInclusiveValue)
|
private int GetFromCrypto(int minValue, int maxInclusiveValue)
|
||||||
{
|
{
|
||||||
var maxExclusiveValue = maxInclusiveValue + 1;
|
var maxExclusiveValue = maxInclusiveValue + 1;
|
||||||
|
|
|
@ -10,7 +10,7 @@ namespace Tests.Core.DiceParser
|
||||||
{
|
{
|
||||||
public class DiceParserTest
|
public class DiceParserTest
|
||||||
{
|
{
|
||||||
private static readonly RandomNumberGenerator _randomNumberGenerator = new RandomNumberGenerator(new Mock<IGlobalSettings>().Object);
|
private static readonly RandomNumberGenerator _randomNumberGenerator = new RandomNumberGenerator();
|
||||||
|
|
||||||
public struct DiceParserTestDto
|
public struct DiceParserTestDto
|
||||||
{
|
{
|
||||||
|
|
|
@ -45,7 +45,7 @@ namespace Tests.Core.DiceParser
|
||||||
[Theory, MemberData(nameof(SingleDieNameTestData))]
|
[Theory, MemberData(nameof(SingleDieNameTestData))]
|
||||||
public void SingleDieNameTestFunc(string testName, SingleDieNameTestDto testData)
|
public void SingleDieNameTestFunc(string testName, SingleDieNameTestDto testData)
|
||||||
{
|
{
|
||||||
var die = new SingleDie(new RandomNumberGenerator(new Mock<IGlobalSettings>().Object)) {AdvantageType = testData.AdvantageType};
|
var die = new SingleDie(new RandomNumberGenerator()) {AdvantageType = testData.AdvantageType};
|
||||||
Assert.Equal(die.DiceName, testData.Expected);
|
Assert.Equal(die.DiceName, testData.Expected);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -108,7 +108,7 @@ namespace Tests.Core.DiceParser
|
||||||
[Theory, MemberData(nameof(SingleDieValidationTestData))]
|
[Theory, MemberData(nameof(SingleDieValidationTestData))]
|
||||||
public void SingleDieValidationTestFunc(string testName, SingleDieValidationTestDto testData)
|
public void SingleDieValidationTestFunc(string testName, SingleDieValidationTestDto testData)
|
||||||
{
|
{
|
||||||
var die = new SingleDie(new RandomNumberGenerator(new Mock<IGlobalSettings>().Object))
|
var die = new SingleDie(new RandomNumberGenerator())
|
||||||
{
|
{
|
||||||
Amount = testData.Amount,
|
Amount = testData.Amount,
|
||||||
Sides = testData.Sides
|
Sides = testData.Sides
|
||||||
|
|
Loading…
Reference in a new issue