diff --git a/Core/Service/EntityFormatter.cs b/Core/Service/EntityFormatter.cs new file mode 100644 index 0000000..91df79a --- /dev/null +++ b/Core/Service/EntityFormatter.cs @@ -0,0 +1,48 @@ +#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 HtmlMap = new() + { + { MessageEntityType.Bold, "{0}" }, + { MessageEntityType.Code, "{0}" }, + { MessageEntityType.Italic, "{0}" }, + { MessageEntityType.TextMention, "{0}" }, + { MessageEntityType.Pre, "
{0}
" }, + { MessageEntityType.Underline, "{0}" } + }; + + private static readonly Dictionary 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; + } +} \ No newline at end of file diff --git a/modules/ChatManagement/Handler/Rules.cs b/modules/ChatManagement/Handler/Rules.cs new file mode 100644 index 0000000..c5f7119 --- /dev/null +++ b/modules/ChatManagement/Handler/Rules.cs @@ -0,0 +1,48 @@ +using System.Threading.Tasks; +using BotFramework.Attributes; +using BotFramework.Enums; +using Kruzya.TelegramBot.Core.Data; +using Kruzya.TelegramBot.Core.Extensions; +using Telegram.Bot; + +namespace West.TelegramBot.ChatManagement.Handler +{ + internal partial class Rules : ManagementHandler + { + [Command(InChat.Public, "setrules", CommandParseMode.Both)] + public async Task HandleSetRules() + { + var replyToMessage = Message?.ReplyToMessage; + var text = replyToMessage?.Text; + if (replyToMessage == null || text == null) + { + return; + } + + //var entities = replyToMessage.Entities; + //if (entities != null) + //{ + // //foreach (var entity in entities) + // //{ + // // var entityText = text.Substring(entity.Offset, entity.Length); + // // text = text + // // .Remove(entity.Offset, entity.Length) + // // .Insert(entity.Offset) + // //} + //} + + + await Bot.SendTextMessageAsync(Chat, "kruzefag@gmail.com"); + } + + [Command(InChat.Public, "rules", CommandParseMode.Both)] + public async Task HandleRules() + { + var opt = Db.UserValues.FindOrCreateOption(Chat.Id, "rules"); + } + + public Rules(CoreContext db) : base(db) + { + } + } +} \ No newline at end of file