Esempio n. 1
0
 protected virtual void OnRawMessageReceived(ITwitchAccount account, TwitchChatMessage tcm)
 {
     RawMessageReceived?.Invoke(this, new ChatConnectionMessageReceivedEventArgs(account, tcm));
 }
Esempio n. 2
0
 public ChatConnectionMessageReceivedEventArgs(ITwitchAccount account, TwitchChatMessage chatmessage) : base(account)
 {
     ChatMessage = chatmessage;
 }
Esempio n. 3
0
 protected virtual void OnRawMessageReceived(TwitchChatMessage msg)
 {
     RawMessageReceived?.Invoke(this, new TwitchChatMessageReceivedEventArgs(_credentials, msg));
 }
 public TwitchChatMessageReceivedEventArgs(TwitchCredentials credentials, TwitchChatMessage chatmessage) : base(credentials)
 {
     ChatMessage = chatmessage;
 }
Esempio n. 5
0
        /// <summary>
        /// Event handler for TcpConnection.MessageReceived
        /// Parsed the received raw message in a TwitchChatMessage
        /// Switches on the received command and executes what is needed
        /// </summary>
        private void _tcpClient_MessageReceived(object sender, IrcTcpMessageEventArgs e)
        {
            // Create a TwitchMessage from the received message
            TwitchChatMessage twitchMsg = new TwitchChatMessage(e.RawMessage);

            OnRawMessageReceived(twitchMsg);

            #if DEBUG
            // Console.WriteLine(twitchMsg.RawMessage);
            #endif

            switch (twitchMsg.Command)
            {
            // PING received
            // Send back a PONG
            case IrcCommand.Ping:
                _tcpClient.EnqueueMessage(twitchMsg.RawMessage.Replace("PING", "PONG"), true);
                break;

            // PONG received
            // Stop TCP pong timer
            case IrcCommand.Pong:
                _tcpClient.PongReceived();
                break;

            // Received PRIVMSG
            // Invoke message received event
            case IrcCommand.PrivMsg:
                OnChatMessageReceived(twitchMsg);
                break;

            // Received Reconnection request
            // Disconnect the connected TCP client with a reqonnect request reason
            case IrcCommand.Reconnect:
                _tcpClient.Disconnect(DisconnectReason.ReconnectRequest);
                break;

            // Received 376, last message of the MOTD after authentication
            // Used to assume successful authentication to the Twitch IRC
            case IrcCommand.RPL_001:
                OnAuthentication(true);
                break;

            // Resubscription notification
            case IrcCommand.UserNotice:
                /* TODO */
                break;

            // Received general IRC Notice
            /* TODO: Expand this https://dev.twitch.tv/docs/v5/guides/irc/#notice */
            case IrcCommand.Notice:
                switch (twitchMsg.NoticeType)
                {
                // Authentication failed
                // Invoke the authentication event with a failed authentication status
                case NoticeMessageType.AuthBadFormat:
                    OnAuthentication(false);
                    break;

                case NoticeMessageType.AuthLoginFailed:
                    OnAuthentication(false);
                    break;
                }
                break;

            // Received MODE
            // Invoke opperator changed event and if its this client adjust TCP RateLimit
            case IrcCommand.Mode:
                if (twitchMsg.Args[1] == "+o")
                {
                    OnOpperatorChange(twitchMsg.Args[2], true);

                    // Change rate limit if bot/caster-account changed opperator status
                    if (_credentials.Username == twitchMsg.Args[2])
                    {
                        _tcpClient.RateLimit = RATELIMIT_MOD;
                    }
                }
                else if (twitchMsg.Args[1] == "-o")
                {
                    OnOpperatorChange(twitchMsg.Args[2], false);

                    // Change rate limit if bot/caster-account changed opperator status
                    if (_credentials.Username == twitchMsg.Args[2])
                    {
                        _tcpClient.RateLimit = RATELIMIT_NOMOD;
                    }
                }

                break;

            /*
             * TODO: Check better way to receive the viewers, as apperantly the JOIN/PART/ROOMLIST
             * do not work if the user has over 1000 chatters, and ROOMLIST is not always triggering
             * usage of API endpoint (undocumented) http://tmi.twitch.tv/group/user/{caster_name}/chatters
             */

            // Chatter joined channel
            case IrcCommand.Join:
                OnChatterJoinPart(twitchMsg.Author, false);
                break;

            // Chatter parted channel
            case IrcCommand.Part:
                OnChatterJoinPart(twitchMsg.Author, true);
                break;

            // Received roomlist
            case IrcCommand.RPL_353:
                OnChatterListReceived(twitchMsg.Message.Split(null));
                break;
            } // End switch on IrcCommand
        }