2022-01-20 14:28:26 +02:00
|
|
|
#nullable enable
|
|
|
|
|
|
|
|
|
|
using System;
|
2022-01-04 17:45:06 +02:00
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using Microsoft.Extensions.Configuration;
|
2022-01-20 14:28:26 +02:00
|
|
|
using SQLitePCL;
|
2022-01-04 17:45:06 +02:00
|
|
|
using Telegram.Bot.Types;
|
|
|
|
|
|
|
|
|
|
namespace Kruzya.TelegramBot.Core.Service
|
|
|
|
|
{
|
|
|
|
|
public class UserService
|
|
|
|
|
{
|
2022-01-20 14:28:26 +02:00
|
|
|
private readonly List<long> _superUsers;
|
|
|
|
|
|
|
|
|
|
private readonly Dictionary<long, string> _statusMap;
|
|
|
|
|
|
2022-01-04 17:45:06 +02:00
|
|
|
public UserService(IConfiguration configuration)
|
|
|
|
|
{
|
|
|
|
|
_superUsers = configuration.GetSection("SuperUsers")
|
|
|
|
|
.GetChildren()
|
|
|
|
|
.Select(q => Convert.ToInt64(q.Value))
|
|
|
|
|
.ToList();
|
2022-01-20 14:28:26 +02:00
|
|
|
|
|
|
|
|
_statusMap = configuration.GetSection("CustomMemberStatus")
|
|
|
|
|
.GetChildren()
|
|
|
|
|
.ToDictionary(x => Convert.ToInt64(x.Key), x => x.Value);
|
2022-01-04 17:45:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool IsUserSuper(User user)
|
|
|
|
|
{
|
|
|
|
|
return IsUserSuper(user.Id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool IsUserSuper(long userId)
|
|
|
|
|
{
|
|
|
|
|
return _superUsers.Contains(userId);
|
|
|
|
|
}
|
2022-01-20 14:28:26 +02:00
|
|
|
|
|
|
|
|
public string? GetUserCustomStatus(long userId)
|
|
|
|
|
{
|
|
|
|
|
return _statusMap.ContainsKey(userId) ? _statusMap[userId] : null;
|
|
|
|
|
}
|
2022-01-04 17:45:06 +02:00
|
|
|
}
|
|
|
|
|
}
|