Ejemplo n.º 1
0
        public async Task SendToChannel(string channel, ChatMessage message)
        {
            var messageText = message.Message;

            // TODO: add rules of what is allowed on channels
            // Filter emojis out of TTS messages
            if (channel == "TTS")
            {
                messageText = Regex.Replace(messageText, @"\p{Cs}", "");

                if (message.Source == ApiSource.Twitch)
                {
                    // TODO: optimize this junk
                    foreach (var emoticon in emoticonService.GetEmoticons().Where(x => x.ApiSource == ApiSource.Twitch))
                    {
                        messageText = Regex.Replace(messageText, emoticon.Regex, "");
                    }
                }

                messageText = messageText.Trim();
                if (string.IsNullOrWhiteSpace(messageText))
                {
                    return;
                }
            }

            // SignalR appears to not like complex objects being passed down, so I changed this to send a dynamic instead of using ChannelMessage
            await chatHubContext.Clients.All.SendAsync("ReceiveChannelMessage", new
            {
                Channel     = channel,
                ChatMessage = new
                {
                    message.Id,
                    message.Date,
                    Message = messageText,
                    message.Source,
                    Author = message.Author.Name,
                    message.Author.SourceAuthorId,
                    message.DisplayDate,
                    message.DisplayTime
                }
            });
        }
Ejemplo n.º 2
0
 public IActionResult GetEmoticons(int maxItems = 10)
 {
     return(Ok(EmoticonService.GetEmoticons()
               .OrderBy(x => x.Regex)
               .Take(maxItems)));
 }