mirror of
https://github.com/Bubuni-Team/telegram-bot.git
synced 2026-07-31 00:29:24 +03:00
Merge pull request #4 from CrazyHackGUT/feature/whois-member-status
[whois] Add chatmember status to output. Update .gitignore.
This commit is contained in:
@@ -7,3 +7,5 @@ obj/
|
|||||||
.DS_Store
|
.DS_Store
|
||||||
|
|
||||||
appsettings.json
|
appsettings.json
|
||||||
|
*.csproj.user
|
||||||
|
appsettings.Development.json
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
using System;
|
#nullable enable
|
||||||
|
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
@@ -8,7 +10,9 @@ namespace Kruzya.TelegramBot.Core.Service
|
|||||||
{
|
{
|
||||||
public class UserService
|
public class UserService
|
||||||
{
|
{
|
||||||
private List<long> _superUsers;
|
private readonly List<long> _superUsers;
|
||||||
|
|
||||||
|
private readonly Dictionary<long, string> _statusMap;
|
||||||
|
|
||||||
public UserService(IConfiguration configuration)
|
public UserService(IConfiguration configuration)
|
||||||
{
|
{
|
||||||
@@ -16,6 +20,10 @@ namespace Kruzya.TelegramBot.Core.Service
|
|||||||
.GetChildren()
|
.GetChildren()
|
||||||
.Select(q => Convert.ToInt64(q.Value))
|
.Select(q => Convert.ToInt64(q.Value))
|
||||||
.ToList();
|
.ToList();
|
||||||
|
|
||||||
|
_statusMap = configuration.GetSection("CustomMemberStatus")
|
||||||
|
.GetChildren()
|
||||||
|
.ToDictionary(x => Convert.ToInt64(x.Key), x => x.Value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool IsUserSuper(User user)
|
public bool IsUserSuper(User user)
|
||||||
@@ -27,5 +35,10 @@ namespace Kruzya.TelegramBot.Core.Service
|
|||||||
{
|
{
|
||||||
return _superUsers.Contains(userId);
|
return _superUsers.Contains(userId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public string? GetUserCustomStatus(long userId)
|
||||||
|
{
|
||||||
|
return _statusMap.ContainsKey(userId) ? _statusMap[userId] : null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -12,6 +12,7 @@ using Kruzya.TelegramBot.Core.Service;
|
|||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using Telegram.Bot;
|
using Telegram.Bot;
|
||||||
using Telegram.Bot.Types;
|
using Telegram.Bot.Types;
|
||||||
|
using Telegram.Bot.Types.Enums;
|
||||||
|
|
||||||
namespace West.TelegramBot.ChatManagement.Handler
|
namespace West.TelegramBot.ChatManagement.Handler
|
||||||
{
|
{
|
||||||
@@ -58,6 +59,7 @@ namespace West.TelegramBot.ChatManagement.Handler
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
message += $"<code>{await GetChatMemberStatusString(user)}</code>\n";
|
||||||
message += $"<code>Репутация: {await GetUserReputation(user)}\n";
|
message += $"<code>Репутация: {await GetUserReputation(user)}\n";
|
||||||
message += $"Предупреждения: {(await GetWarnOption(user)).GetValue<int>()}</code>";
|
message += $"Предупреждения: {(await GetWarnOption(user)).GetValue<int>()}</code>";
|
||||||
}
|
}
|
||||||
@@ -156,5 +158,23 @@ namespace West.TelegramBot.ChatManagement.Handler
|
|||||||
{
|
{
|
||||||
return await Db.UserValues.FindOrCreateOption(Chat.Id, user.Id, "reputation");
|
return await Db.UserValues.FindOrCreateOption(Chat.Id, user.Id, "reputation");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async Task<string> GetChatMemberStatusString(User user)
|
||||||
|
{
|
||||||
|
var customStatus = _userService.GetUserCustomStatus(user.Id);
|
||||||
|
if (customStatus != null)
|
||||||
|
{
|
||||||
|
return customStatus;
|
||||||
|
}
|
||||||
|
|
||||||
|
var chatMember = await Bot.GetChatMemberAsync(Chat.Id, user.Id);
|
||||||
|
return chatMember.Status switch
|
||||||
|
{
|
||||||
|
ChatMemberStatus.Creator => "Владелец",
|
||||||
|
ChatMemberStatus.Restricted => "Заблокированный",
|
||||||
|
ChatMemberStatus.Administrator => "Администратор",
|
||||||
|
_ => "Пользователь"
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user