2020-03-01 22:46:07 +04:00
|
|
|
using System.Text;
|
|
|
|
|
using Telegram.Bot.Types;
|
|
|
|
|
|
|
|
|
|
namespace Kruzya.TelegramBot.Core.Extensions
|
|
|
|
|
{
|
|
|
|
|
public static class UserExtension
|
|
|
|
|
{
|
2021-12-26 15:40:14 +02:00
|
|
|
public static string ToHtml(this User user, bool byUsername = true)
|
2020-03-01 22:46:07 +04:00
|
|
|
{
|
|
|
|
|
var text = new StringBuilder();
|
2020-03-03 14:11:51 +04:00
|
|
|
text.Append($"<a href=\"tg://user?id={user.Id}\">");
|
2021-12-26 15:40:14 +02:00
|
|
|
|
|
|
|
|
if (byUsername && !string.IsNullOrWhiteSpace(user.Username))
|
|
|
|
|
{
|
2020-03-01 22:46:07 +04:00
|
|
|
text.Append(user.Username);
|
2021-12-26 15:40:14 +02:00
|
|
|
}
|
2020-03-01 22:46:07 +04:00
|
|
|
else
|
2021-12-26 15:40:14 +02:00
|
|
|
{
|
2020-03-01 22:46:07 +04:00
|
|
|
text.Append($"{user.FirstName} {user.LastName}".Trim().HtmlEncode());
|
2021-12-26 15:40:14 +02:00
|
|
|
}
|
|
|
|
|
return text.Append("</a>").ToString();
|
2020-03-01 22:46:07 +04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|