mirror of
https://github.com/Bubuni-Team/telegram-bot.git
synced 2026-07-31 00:29:24 +03:00
31 lines
944 B
C#
31 lines
944 B
C#
using System.Text;
|
|
using Telegram.Bot.Types;
|
|
|
|
namespace Kruzya.TelegramBot.Core.Extensions
|
|
{
|
|
public static class UserExtension
|
|
{
|
|
public static string ToHtml(this User user, bool byUsername = false)
|
|
{
|
|
var text = new StringBuilder();
|
|
text.Append($"<a href=\"tg://user?id={user.Id}\">");
|
|
|
|
if (byUsername && !string.IsNullOrWhiteSpace(user.Username))
|
|
{
|
|
text.Append(user.Username);
|
|
}
|
|
else
|
|
{
|
|
text.Append($"{user.FirstName} {user.LastName}".Trim().HtmlEncode());
|
|
}
|
|
return text.Append("</a>").ToString();
|
|
}
|
|
|
|
public static string ToLog(this User user)
|
|
{
|
|
var name = $"{user.FirstName} {user.LastName}".Trim();
|
|
|
|
return $"{name} (ID: {user.Id}, Username: {user.Username ?? "N/A"})";
|
|
}
|
|
}
|
|
} |