feat(store): code cleanup, make some fund with "unlucky" members

This commit is contained in:
Andriy
2023-12-22 21:43:01 +02:00
parent d32b976e1a
commit 7e41fc93fc
10 changed files with 40 additions and 18 deletions
+11 -7
View File
@@ -15,8 +15,9 @@ namespace Kruzya.TelegramBot.Core.Service;
public class UserService
{
private readonly List<long> _superUsers;
private readonly Dictionary<long, string> _statusMap;
private readonly IEnumerable<long> _superUsers;
private readonly IEnumerable<long> _badLuckUsers;
private readonly Dictionary<long, string?> _statusMap;
private readonly ICacheStorage<long, User> _userCache;
private readonly ITelegramBotClient _bot;
private readonly ILogger<UserService> _logger;
@@ -28,15 +29,13 @@ public class UserService
ICacheStorage<long, User> userCache,
ILogger<UserService> logger)
{
_superUsers = configuration.GetSection("SuperUsers")
.GetChildren()
.Select(q => Convert.ToInt64(q.Value))
.ToList();
_superUsers = configuration.GetSection("SuperUsers").Get<List<long>>() ?? new List<long>();
_badLuckUsers = configuration.GetSection("BadLuckUsers").Get<List<long>>() ?? new List<long>();
_statusMap = configuration.GetSection("CustomMemberStatus")
.GetChildren()
.ToDictionary(x => Convert.ToInt64(x.Key), x => x.Value);
_userCache = userCache;
_bot = bot.BotClient;
_logger = logger;
@@ -83,6 +82,11 @@ public class UserService
return _superUsers.Contains(userId);
}
public bool IsUserUnlucky(long userId)
{
return _badLuckUsers.Contains(userId);
}
public string? GetUserCustomStatus(long userId)
{
return _statusMap.ContainsKey(userId) ? _statusMap[userId] : null;