feat(entertainment): use CSPRNG in /guess & /roll

This commit is contained in:
Andriy
2023-12-13 00:34:23 +02:00
parent aa0d1c1cc1
commit aa072e246c
2 changed files with 6 additions and 6 deletions
+4 -5
View File
@@ -15,13 +15,13 @@ using Telegram.Bot.Types.Enums;
using Telegram.Bot.Types;
using Kruzya.TelegramBot.Core.Handler;
using System.Collections.Generic;
using System.Security.Cryptography;
namespace West.Entertainment.Handler;
public class Roll : CommonHandler
{
private readonly ILogger<Roll> _logger;
private readonly ThreadSafeRandom _rng;
private readonly IReputation _reputation;
private readonly UserService _userService;
private readonly ConcurrentBag<DeleteRequest> _requests;
@@ -54,7 +54,7 @@ public class Roll : CommonHandler
return;
}
var newRep = _rng.Next(-20, 80);
var newRep = RandomNumberGenerator.GetInt32(-20, 80);
await Reply($"Вы получили {newRep} кармы.");
await _reputation.IncrementReputationAsync(Chat, From, newRep);
@@ -119,7 +119,7 @@ public class Roll : CommonHandler
for (var i = 0; i < 100; i++)
{
var number = _rng.Next(minValue, maxValue);
var number = RandomNumberGenerator.GetInt32(minValue, maxValue);
numbers.Add(number);
if (number > 0)
@@ -151,12 +151,11 @@ public class Roll : CommonHandler
return message;
}
public Roll(CoreContext db, IReputation reputation, UserService userService, ILogger<Roll> logger, ThreadSafeRandom rng, ConcurrentBag<DeleteRequest> requests) : base(db)
public Roll(CoreContext db, IReputation reputation, UserService userService, ILogger<Roll> logger, ConcurrentBag<DeleteRequest> requests) : base(db)
{
_reputation = reputation;
_userService = userService;
_logger = logger;
_rng = rng;
_requests = requests;
}
}