Exemplo n.º 1
0
        private void OnMessageReceived(object sender, OnMessageReceivedArgs e)
        {
            this.allowDiscordNotification = true;

            var chat     = e.ChatMessage;
            var msg      = chat;
            var emoteSet = msg.EmoteSet;

            var emoteResolver = emoteResolverProvider.Get(emoteSet);

            if (emoteSet != null)
            {
                var words     = msg.Message.Split(' ');
                var emoteUrls = words
                                .Select(x => emoteResolver.Resolve(x, true))
                                .Where(x => x != null)
                                .Select(x => x.ImageUrl);

                var emoteCollection           = new ChatEmoteCollection(msg.Username, emoteUrls);
                var twitchChatEmoteCollection = new TwitchChatEmoteCollection(msg, emoteUrls);
                messageBus.Send(nameof(TwitchChatEmoteCollection), twitchChatEmoteCollection);
                messageBus.Send(nameof(ChatEmoteCollection), emoteCollection);
                connectionProvider.BroadcastAsync(emoteCollection);
            }

            //if (e.ChatMessage.Bits > 0)
            //{
            //    this.messageBus.Send(nameof(BitsCheered), new BitsCheered(e));
            //}

            if ((chat.Username?.Equals("ravenfallofficial", StringComparison.OrdinalIgnoreCase)).GetValueOrDefault() ||
                chat.Message.StartsWith("!", StringComparison.InvariantCultureIgnoreCase))
            {
                return;
            }

            var twitchSender = new TwitchChatSender(chat.DisplayName ?? chat.Username, chat.ColorHex);
            var message      = chatMessageParser.Parse(twitchSender, chat.Message, wordResolver, emoteResolver);

            connectionProvider.BroadcastAsync(message);
        }