internal static string CleanUserMentions(Channel channel, string text, List<User> users = null) { ulong id; text = _userNicknameRegex.Replace(text, new MatchEvaluator(e => { if (e.Value.Substring(3, e.Value.Length - 4).TryToId(out id)) { var user = channel.GetUserFast(id); if (user != null) { if (users != null) users.Add(user); return '@' + user.Nickname; } } return e.Value; //User not found or parse failed })); return _userRegex.Replace(text, new MatchEvaluator(e => { if (e.Value.Substring(2, e.Value.Length - 3).TryToId(out id)) { var user = channel.GetUserFast(id); if (user != null) { if (users != null) users.Add(user); return '@' + user.Name; } } return e.Value; //User not found or parse failed })); }
internal static string CleanUserMentions(Channel channel, string text, List <User> users = null) { ulong id; text = _userNicknameRegex.Replace(text, new MatchEvaluator(e => { if (e.Value.Substring(3, e.Value.Length - 4).TryToId(out id)) { var user = channel.GetUserFast(id); if (user != null) { if (users != null) { users.Add(user); } return('@' + user.Nickname); } } return(e.Value); //User not found or parse failed })); return(_userRegex.Replace(text, new MatchEvaluator(e => { if (e.Value.Substring(2, e.Value.Length - 3).TryToId(out id)) { var user = channel.GetUserFast(id); if (user != null) { if (users != null) { users.Add(user); } return '@' + user.Name; } } return e.Value; //User not found or parse failed }))); }
internal void Update(APIMessage model) { var channel = Channel; var server = channel.Server; if (model.Attachments != null) { Attachments = model.Attachments .Select(x => new Attachment() { Id = x.Id, Url = x.Url, ProxyUrl = x.ProxyUrl, Width = x.Width, Height = x.Height, Size = x.Size, Filename = x.Filename }) .ToArray(); } if (model.Embeds != null) { Embeds = model.Embeds.Select(x => { EmbedLink author = null, provider = null; File thumbnail = null, video = null; if (x.Author != null) { author = new EmbedLink { Url = x.Author.Url, Name = x.Author.Name } } ; if (x.Provider != null) { provider = new EmbedLink { Url = x.Provider.Url, Name = x.Provider.Name } } ; if (x.Thumbnail != null) { thumbnail = new File { Url = x.Thumbnail.Url, ProxyUrl = x.Thumbnail.ProxyUrl, Width = x.Thumbnail.Width, Height = x.Thumbnail.Height } } ; if (x.Video != null) { video = new File { Url = x.Video.Url, ProxyUrl = null, Width = x.Video.Width, Height = x.Video.Height } } ; return(new Embed { Url = x.Url, Type = x.Type, Title = x.Title, Description = x.Description, Author = author, Provider = provider, Thumbnail = thumbnail, Video = video }); }).ToArray(); } if (model.IsTextToSpeech != null) { IsTTS = model.IsTextToSpeech.Value; } if (model.Timestamp != null) { Timestamp = model.Timestamp.Value; } if (model.EditedTimestamp != null) { EditedTimestamp = model.EditedTimestamp; } if (model.Mentions != null) { MentionedUsers = model.Mentions .Select(x => Channel.GetUserFast(x.Id)) .Where(x => x != null) .ToArray(); } if (model.IsMentioningEveryone != null) { if (model.IsMentioningEveryone.Value && User != null && User.GetPermissions(channel).MentionEveryone) { MentionedRoles = new Role[] { Server.EveryoneRole } } ; else { MentionedRoles = new Role[0]; } } if (model.Content != null) { string text = model.Content; RawText = text; //var mentionedUsers = new List<User>(); var mentionedChannels = new List <Channel>(); //var mentionedRoles = new List<Role>(); text = CleanUserMentions(Channel, text /*, mentionedUsers*/); if (server != null) { text = CleanChannelMentions(Channel, text, mentionedChannels); //text = CleanRoleMentions(_client, User, channel, text, mentionedRoles); } Text = text; //MentionedUsers = mentionedUsers; MentionedChannels = mentionedChannels; //MentionedRoles = mentionedRoles; } }