Remove random.org integration

This commit is contained in:
Daan Boerlage 2021-09-17 14:03:35 +02:00
parent 989057a0b0
commit 5c507b026c
Signed by: daan
GPG key ID: FCE070E1E4956606
5 changed files with 5 additions and 38 deletions

View file

@ -12,7 +12,6 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Anemonis.RandomOrg" Version="1.14.0" />
<PackageReference Include="CommandLineParser" Version="2.8.0" />
<PackageReference Include="Discord.Net" Version="2.4.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="6.0.0-preview.2.21154.2" />

View file

@ -1,25 +1,14 @@
using System;
using Anemonis.RandomOrg;
using Geekbot.Core.GlobalSettings;
namespace Geekbot.Core.RandomNumberGenerator
{
public class RandomNumberGenerator : IRandomNumberGenerator
{
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();
var randomOrgApiKey = globalSettings.GetKey("RandomOrgApiKey");
if (!string.IsNullOrEmpty(randomOrgApiKey))
{
_canUseRandomOrg = true;
_randomOrgClient = new RandomOrgClient(randomOrgApiKey);
}
}
public int Next(int minValue, int maxInclusiveValue)
@ -33,31 +22,10 @@ namespace Geekbot.Core.RandomNumberGenerator
{
throw new ArgumentOutOfRangeException("minValue", "must be lower than maxExclusiveValue");
}
if (_canUseRandomOrg)
{
try
{
return GetFromRandomOrg(minValue, maxInclusiveValue);
}
catch
{
// ignore
}
}
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)
{
var maxExclusiveValue = maxInclusiveValue + 1;