Files
telegram-bot/Core/Service/UserService.cs
T

45 lines
1.2 KiB
C#

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