public void Process(ITwitchChannelConnection connection, TwitchMessageData data)
        {
            if (connection == null)
            {
                throw new ArgumentNullException(nameof(connection));
            }
            if (data == null)
            {
                throw new ArgumentNullException(nameof(data));
            }

            string channel = data.Params.ValueOrDefault(0) ?? connection.Channel;

            if (channel != connection.Channel)
            {
                return;
            }

            // Get formatted user information if possible.
            string name      = data.Tags.ValueOrDefault("display-name") ?? connection.Username;
            string colorText = data.Tags.ValueOrDefault("color") ?? "Black";

            // Try to get user color.
            Color color = Colors.Black;

            try { color = (Color)ColorConverter.ConvertFromString(colorText); }
            catch (FormatException) { }

            var user = new TwitchUser(name, true, color);

            OnAcquireUserState(user);
        }
Exemplo n.º 2
0
        public void Process(ITwitchChannelConnection connection, TwitchMessageData data)
        {
            if (connection == null)
            {
                throw new ArgumentNullException(nameof(connection));
            }
            if (data == null)
            {
                throw new ArgumentNullException(nameof(data));
            }

            // Extract message data.
            string name    = data.Prefix?.Split('!')[0] ?? "Unknown";
            string channel = data.Params.ValueOrDefault(0) ?? connection.Channel;
            string message = data.Params.ValueOrDefault(1);

            if (message == null)
            {
                return;
            }

            // Message coming in on the wrong channel.
            if (channel != connection.Channel)
            {
                return;
            }

            // Get formatted user information if possible.
            string displayName = data.Tags.ValueOrDefault("display-name");

            name = string.IsNullOrEmpty(displayName) ? name.CapitalizeFirst() : displayName;
            string colorText = data.Tags.ValueOrDefault("color") ?? "Black";

            // Action messages "/me <message>"...
            var type  = TwitchChatMessageType.Normal;
            var match = Regex.Match(message, @"^\u0001ACTION ([^\u0001]+)\u0001$");

            if (match.Success)
            {
                message = match.Groups[1].Value;
                type    = TwitchChatMessageType.Self;
            }

            // Try to get the users color or default to black.
            Color color = Colors.Black;

            try { color = (Color)ColorConverter.ConvertFromString(colorText); }
            catch (FormatException) { }

            // Check for moderator status.
            bool moderator = data.Tags.ValueOrDefault("mod") == "1";

            moderator |= data.Tags.ValueOrDefault("badges")?.Contains("broadcaster") ?? false;

            var user = new TwitchUser(name, moderator, color);

            OnMessageReceived(new TwitchChatMessage(type, user, message));
        }
Exemplo n.º 3
0
        public void Process(ITwitchChannelConnection connection, TwitchMessageData data)
        {
            if (connection == null)
            {
                throw new System.ArgumentNullException(nameof(connection));
            }

            connection.Command("PONG");
            connection.Flush();
        }
Exemplo n.º 4
0
        public TwitchClient(ITwitchChannelConnection connection)
        {
            if (connection == null)
            {
                throw new ArgumentNullException(nameof(connection));
            }
            Dispatcher = Dispatcher.CurrentDispatcher;

            Connection = connection;
            InitializeIgnoredCommands();
            InitializeCommandProcessors();
        }
Exemplo n.º 5
0
        public void Process(ITwitchChannelConnection connection, TwitchMessageData data)
        {
            if (connection == null)
            {
                throw new ArgumentNullException(nameof(connection));
            }
            if (data == null)
            {
                throw new ArgumentNullException(nameof(data));
            }

            string channel  = data.Params.ValueOrDefault(0);
            string username = data.Prefix?.Split('!').ValueOrDefault(0);

            if (username == null)
            {
                return;
            }

            OnUserJoined(channel, username.TrimStart(':'));
        }
Exemplo n.º 6
0
 public TwitchChatWriter(ITwitchChannelConnection connection)
 {
     this.connection = connection;
 }