diff --git a/.gitignore b/.gitignore index 522f82f..24341c7 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,5 @@ obj/ .DS_Store appsettings.json +Core/Core.csproj.user +Core/appsettings.Development.json diff --git a/Core/Service/UserService.cs b/Core/Service/UserService.cs index 0a8e15b..5afcf65 100644 --- a/Core/Service/UserService.cs +++ b/Core/Service/UserService.cs @@ -1,21 +1,30 @@ -using System; +#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 List _superUsers; - + private readonly List _superUsers; + + private readonly Dictionary _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) @@ -27,5 +36,10 @@ namespace Kruzya.TelegramBot.Core.Service { return _superUsers.Contains(userId); } + + public string? GetUserCustomStatus(long userId) + { + return _statusMap.ContainsKey(userId) ? _statusMap[userId] : null; + } } } \ No newline at end of file diff --git a/modules/ChatManagement/Handler/Reputation.cs b/modules/ChatManagement/Handler/Reputation.cs index 84bbece..8afb613 100644 --- a/modules/ChatManagement/Handler/Reputation.cs +++ b/modules/ChatManagement/Handler/Reputation.cs @@ -12,6 +12,7 @@ using Kruzya.TelegramBot.Core.Service; using Microsoft.Extensions.Logging; using Telegram.Bot; using Telegram.Bot.Types; +using Telegram.Bot.Types.Enums; namespace West.TelegramBot.ChatManagement.Handler { @@ -58,6 +59,7 @@ namespace West.TelegramBot.ChatManagement.Handler } else { + message += $"{await GetChatMemberStatusString(user)}\n"; message += $"Репутация: {await GetUserReputation(user)}\n"; message += $"Предупреждения: {(await GetWarnOption(user)).GetValue()}"; } @@ -156,5 +158,24 @@ namespace West.TelegramBot.ChatManagement.Handler { return await Db.UserValues.FindOrCreateOption(Chat.Id, user.Id, "reputation"); } + + private async Task GetChatMemberStatusString(User user) + { + var chatMember = await Bot.GetChatMemberAsync(Chat.Id, user.Id); + var customStatus = _userService.GetUserCustomStatus(user.Id); + if (customStatus != null) + { + return customStatus; + } + + + return chatMember.Status switch + { + ChatMemberStatus.Creator => "Владелец", + ChatMemberStatus.Restricted => "Заблокированный", + ChatMemberStatus.Administrator => "Администратор", + _ => "Пользователь" + }; + } } } \ No newline at end of file