mirror of
https://github.com/Bubuni-Team/telegram-bot.git
synced 2026-07-31 00:29:24 +03:00
Remove entity formatter.
This commit is contained in:
@@ -1,48 +0,0 @@
|
||||
#nullable enable
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Telegram.Bot.Types;
|
||||
using Telegram.Bot.Types.Enums;
|
||||
|
||||
namespace Kruzya.TelegramBot.Core.Service;
|
||||
|
||||
internal class EntityFormatter
|
||||
{
|
||||
private static readonly Dictionary<MessageEntityType, string> HtmlMap = new()
|
||||
{
|
||||
{ MessageEntityType.Bold, "<b>{0}</b>" },
|
||||
{ MessageEntityType.Code, "<code>{0}</code>" },
|
||||
{ MessageEntityType.Italic, "<i>{0}</i>" },
|
||||
{ MessageEntityType.TextMention, "<a href=\"tg://user?id={1}\">{0}</a>" },
|
||||
{ MessageEntityType.Pre, "<pre>{0}</pre>" },
|
||||
{ MessageEntityType.Underline, "<u>{0}</u>" }
|
||||
};
|
||||
|
||||
private static readonly Dictionary<MessageEntityType, string> MarkdownMap = new()
|
||||
{
|
||||
{ MessageEntityType.Bold, "*{0}*" },
|
||||
{ MessageEntityType.Code, "```{0}```" },
|
||||
{ MessageEntityType.Italic, "_{0}_" },
|
||||
{ MessageEntityType.TextMention, "[{0}](tg://user?id={1})" },
|
||||
{ MessageEntityType.Pre, "```{0}```" },
|
||||
{ MessageEntityType.Underline, "__{0}__" }
|
||||
};
|
||||
|
||||
public string? FormatMessage(Message msg)
|
||||
{
|
||||
var text = msg.Text;
|
||||
var entities = msg.Entities;
|
||||
|
||||
if (entities == null || text == null) return text;
|
||||
|
||||
foreach (var entity in entities.Reverse())
|
||||
{
|
||||
var entityText = text.Substring(entity.Offset, entity.Length);
|
||||
text = text
|
||||
.Remove(entity.Offset, entity.Length);
|
||||
}
|
||||
|
||||
return text;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user