fixed all warnings included NUGET.

This commit is contained in:
Ruberoid 2025-07-18 18:55:09 +03:00
parent ae14533171
commit 4f00f647d8
6 changed files with 22 additions and 17 deletions

View File

@ -38,7 +38,8 @@ public sealed class NewMessageHandler : INewMessageHandler
m.From?.Peer(_telegramRegistry.Users, _telegramRegistry.Chats),
m.Peer.Peer(_telegramRegistry.Users, _telegramRegistry.Chats),
m.message);
var chatUserName = m.peer_id.Peer(_telegramRegistry.Users, _telegramRegistry.Chats).Split("@").Last();
var chatUserName = m.peer_id.Peer(_telegramRegistry.Users, _telegramRegistry.Chats)?.Split("@").Last();
if (string.IsNullOrWhiteSpace(chatUserName))
{
_logger.LogWarning("Failed to get chat user name for chat {ChatId}", m.peer_id.ID);

View File

@ -6,11 +6,15 @@ public static class TelegramObjectExtensions
{
public static string User(this IDictionary<long, User> dictionary, long id) =>
dictionary.TryGetValue(id, out var user) ? user.ToString() : $"User {id}";
public static string Chat(this IDictionary<long, ChatBase> dictionary, long id) =>
dictionary.TryGetValue(id, out var chat) ? chat.ToString() : $"Chat {id}";
dictionary.TryGetValue(id, out var chat) ? chat.ToString() ?? $"Null chat {id}" : $"Chat {id}";
public static string Peer(this Peer peer, IDictionary<long, User> users, IDictionary<long, ChatBase> chats) => peer is null ? null
: peer is PeerUser user ? users.User(user.user_id)
: peer is PeerChat or PeerChannel ? chats.Chat(peer.ID) : $"Peer {peer.ID}";
public static string? Peer(this Peer? peer, IDictionary<long, User> users, IDictionary<long, ChatBase> chats) => peer switch
{
null => null,
PeerUser user => users.User(user.user_id),
PeerChat or PeerChannel => chats.Chat(peer.ID),
_ => $"Peer {peer.ID}"
};
}

View File

@ -6,7 +6,7 @@ namespace Nocr.TelegramListener.AppServices.UpdateListeners;
public sealed class TelegramRegistry
{
public User My { get; private set; }
public User? My { get; private set; }
public ConcurrentDictionary<long, User> Users = new();
public ConcurrentDictionary<long, ChatBase> Chats = new();

View File

@ -57,9 +57,9 @@ public sealed class UpdateListenerBackgroundService : BackgroundService
_telegramRegistry.SetMy(my);
_logger.LogInformation("Telegram client is logged-in as {Username} (id {Id})",
_telegramRegistry.My.username ??
_telegramRegistry.My.first_name + " " + _telegramRegistry.My.last_name,
_telegramRegistry.My.id);
_telegramRegistry.My?.username ??
_telegramRegistry.My?.first_name + " " + _telegramRegistry.My?.last_name,
_telegramRegistry.My?.id);
}
await _telegramRegistry.Update(client);

View File

@ -5,11 +5,11 @@ namespace Nocr.TelegramListener.AppServices.UpdateListeners;
/// </summary>
public sealed class WTelegramClientOptions
{
public string ApiId { get; set; }
public required string ApiId { get; set; }
public string ApiHash { get; set; }
public required string ApiHash { get; set; }
public string PhoneNumber { get; set; }
public required string PhoneNumber { get; set; }
public string? FirstName { get; set; }

View File

@ -2,11 +2,11 @@ namespace Nocr.TelegramListener.Core.Options;
public sealed class RebusRabbitMqOptions
{
public string ConnectionString { get; set; }
public required string ConnectionString { get; set; }
public string InputQueueName { get; set; }
public required string InputQueueName { get; set; }
public string DirectExchangeName { get; set; }
public required string DirectExchangeName { get; set; }
public string TopicsExchangeName { get; set; }
public required string TopicsExchangeName { get; set; }
}