From c396d180bddb19f6cbee841c3098e38005bd9c29 Mon Sep 17 00:00:00 2001 From: Sergey Gut Date: Wed, 6 Nov 2024 15:30:35 +0300 Subject: [PATCH] fix(entertainment): replace Random to ThreadSafeRandom --- modules/ContentStore/Service/CapyApiService.cs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/modules/ContentStore/Service/CapyApiService.cs b/modules/ContentStore/Service/CapyApiService.cs index 095e399..c79a39b 100644 --- a/modules/ContentStore/Service/CapyApiService.cs +++ b/modules/ContentStore/Service/CapyApiService.cs @@ -1,4 +1,5 @@ using System.Security.Cryptography; +using Kruzya.TelegramBot.Core; using Kruzya.TelegramBot.Core.Service; using Telegram.Bot.Types; using West.TelegramBot.ContentStore.Model; @@ -9,6 +10,7 @@ public class CapyApiService : IRandomMediaService { private readonly UserService _userService; private const int BeaverCount = 161; + private readonly ThreadSafeRandom _random; public StoreItem StoreItem { get; } = new("capybara", "Капибара", 60, 120); public Task GetRandomMediaAsync(Chat chat, User user) @@ -19,13 +21,14 @@ public class CapyApiService : IRandomMediaService return Task.FromResult(RandomMediaFromUrl($"https://westdev.me/_kurwa/{beaverId}.jpg")); } - return Task.FromResult(RandomMediaFromUrl($"https://api.capy.lol/v1/capybara?{new Random().Next(0, 10000)}")); + return Task.FromResult(RandomMediaFromUrl($"https://api.capy.lol/v1/capybara?{_random.Next(0, 10000)}")); } public RandomMedia RandomMediaFromUrl(string url) => new(new InputFileUrl(url)); - public CapyApiService(UserService userService) + public CapyApiService(UserService userService, ThreadSafeRandom random) { _userService = userService; + _random = random; } } \ No newline at end of file