Пример #1
0
 private void ClearChatHandler(TwitchClient sender, TwitchUser user)
 {
     Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action<TwitchUser>(DispatcherClearChat), user);
 }
Пример #2
0
        private void ChatActionReceived(TwitchClient sender, TwitchUser user, string text)
        {
            if (m_options.Ignore.Contains(user.Name))
                return;

            user.EnsureIconsDownloaded();
            Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action<ChatItem>(AddItem), new ChatAction(this, user, text));
        }
Пример #3
0
        private void ChatMessageReceived(TwitchClient sender, TwitchUser user, string text)
        {
            if (m_options.Ignore.Contains(user.Name))
                return;

            user.EnsureIconsDownloaded();
            bool question = false;
            if (HighlightQuestions)
            {
                foreach (var highlight in m_options.Highlights)
                {
                    if (text.ToLower().Contains(highlight))
                    {
                        question = true;
                        break;
                    }
                }
            }

            Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action<ChatItem>(AddItem), new ChatMessage(this, user, text, question));
        }
Пример #4
0
 private void SubscribeHandler(TwitchClient source, TwitchUser user)
 {
     var evt = UserSubscribed;
     if (evt != null)
     {
         m_events.Enqueue(new Tuple<Delegate, object[]>(evt, new object[] { this, user }));
         m_event.Set();
     }
 }
Пример #5
0
 public TimeoutRequest(TwitchClient client, string user, int timeout)
 {
     Created = DateTime.Now;
     m_client = client;
     m_user = user;
     m_time = timeout;
 }
Пример #6
0
        private void SubscribeHandler(TwitchClient sender, TwitchUser user)
        {
            if (PlaySounds)
                m_subSound.Play();

            Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action<TwitchUser>(DispatcherUserSubscribed), user);
        }
Пример #7
0
 private void ClearChatHandler(TwitchClient source, TwitchUser user)
 {
     var evt = ChatClear;
     if (evt != null)
     {
         m_events.Enqueue(new Tuple<Delegate, object[]>(evt, new object[] { this, user }));
         m_event.Set();
     }
 }
Пример #8
0
 private void ClearChatHandler(TwitchClient source, TwitchUser user)
 {
     if (ChatClear != null)
     {
         m_events.Enqueue(new ClearEvent(user));
         m_event.Set();
     }
 }
Пример #9
0
        void Connect()
        {
            if (m_twitch != null)
            {
                m_twitch.InformChatClear -= ClearChatHandler;
                m_twitch.MessageReceived -= ChatMessageReceived;
                m_twitch.ActionReceived -= ChatActionReceived;
                m_twitch.UserSubscribed -= SubscribeHandler;
                m_twitch.InformModerator -= InformModerator;
                m_twitch.StatusUpdate -= IrcStatusHandler;
            }

            m_twitch = new TwitchClient(m_data);
            m_twitch.TimeoutDelay = 250;
            m_twitch.InformChatClear += ClearChatHandler;
            m_twitch.MessageReceived += ChatMessageReceived;
            m_twitch.ActionReceived += ChatActionReceived;
            m_twitch.UserSubscribed += SubscribeHandler;
            m_twitch.InformModerator += InformModerator;
            m_twitch.StatusUpdate += IrcStatusHandler;

            bool first = true;
            ConnectResult result;
            const int sleepTime = 5000;
            do
            {
                if (!NativeMethods.IsConnectedToInternet())
                {
                    WriteDiagnostic(DiagnosticFacility.Network, "Not connected to the internet.");

                    do
                    {
                        Thread.Sleep(sleepTime);
                    } while (!NativeMethods.IsConnectedToInternet());

                    WriteDiagnostic(DiagnosticFacility.Network, "Re-connected to the internet.");
                }

                if (!first)
                    Thread.Sleep(sleepTime);

                first = false;
                result = m_twitch.Connect(m_channel, m_options.Username, m_options.Password);

                if (result == ConnectResult.LoginFailed)
                        throw new TwitchLoginException(m_options.Username);

            } while (result != ConnectResult.Success);

            OnConnected();
        }
Пример #10
0
 private void ChatActionReceived(TwitchClient source, TwitchUser user, string text)
 {
     if (ActionReceived != null)
     {
         m_events.Enqueue(new ActionEvent(user, text));
         m_event.Set();
     }
 }
Пример #11
0
 private void ChatMessageReceived(TwitchClient source, TwitchUser user, string text)
 {
     if (MessageReceived != null)
     {
         m_events.Enqueue(new MessageEvent(user, text));
         m_event.Set();
     }
 }
Пример #12
0
 public FloodPreventer(TwitchClient client)
 {
     m_client = client;
 }
Пример #13
0
 private void IrcStatusHandler(TwitchClient sender, string message)
 {
     WriteDiagnostic(DiagnosticFacility.Irc, message);
 }
Пример #14
0
 public FloodPreventer(TwitchClient client)
 {
     m_client = client;
 }
Пример #15
0
        bool Connect()
        {
            if (m_twitch != null)
            {
                m_twitch.InformChatClear -= ClearChatHandler;
                m_twitch.MessageReceived -= ChatMessageReceived;
                m_twitch.ActionReceived -= ChatActionReceived;
                m_twitch.UserSubscribed -= SubscribeHandler;
                m_twitch.StatusUpdate -= StatusUpdate;
            }

            string channel = m_channel.ToLower();
            m_users = new TwitchUsers(channel);
            m_twitch = new TwitchClient(m_users);
            m_twitch.InformChatClear += ClearChatHandler;
            m_twitch.MessageReceived += ChatMessageReceived;
            m_twitch.ActionReceived += ChatActionReceived;
            m_twitch.UserSubscribed += SubscribeHandler;
            m_twitch.StatusUpdate += StatusUpdate;

            bool first = true;
            ConnectResult result;
            const int sleepTime = 5000;
            do
            {
                if (!NativeMethods.IsConnectedToInternet())
                {
                    WriteStatus("Not connected to the internet.");

                    do
                    {
                        Thread.Sleep(sleepTime);
                    } while (!NativeMethods.IsConnectedToInternet());

                    WriteStatus("Re-connected to the internet.");
                }

                if (!first)
                    Thread.Sleep(sleepTime);

                first = false;
                result = m_twitch.Connect(channel, m_options.User, m_options.Pass);

                if (result == ConnectResult.LoginFailed)
                {
                    WriteStatus("Failed to login, please change options.ini and restart the application.");
                    return false;
                }
                else if (result != ConnectResult.Success)
                {
                    WriteStatus("Failed to connect: {0}", result == ConnectResult.NetworkFailed ? "network failed" : "failed");
                }
            } while (result != ConnectResult.Success);

            WriteStatus("Connected to channel {0}.", channel);
            return true;
        }
Пример #16
0
 void InformModerator(TwitchClient sender, TwitchUser user, bool moderator)
 {
     var evt = moderator ? ModeratorAdded : ModeratorRemoved;
     if (evt != null)
     {
         m_events.Enqueue(new ModEvent(user, moderator));
         m_event.Set();
     }
 }
Пример #17
0
 private void StatusUpdate(TwitchClient sender, string message)
 {
     WriteStatus(message);
 }
Пример #18
0
 private void IrcStatusHandler(TwitchClient sender, string message)
 {
     WriteDiagnostic(DiagnosticFacility.Irc, message);
 }
Пример #19
0
 private void ChatMessageReceived(TwitchClient source, TwitchUser user, string text)
 {
     var evt = MessageReceived;
     if (evt != null)
     {
         m_events.Enqueue(new Tuple<Delegate, object[]>(evt, new object[] { this, user, text }));
         m_event.Set();
     }
 }
Пример #20
0
 private void SubscribeHandler(TwitchClient source, TwitchUser user)
 {
     if (UserSubscribed != null)
     {
         m_events.Enqueue(new SubscribeEvent(user));
         m_event.Set();
     }
 }
Пример #21
0
 void InformModerator(TwitchClient sender, TwitchUser user, bool moderator)
 {
     var evt = moderator ? ModeratorAdded : ModeratorRemoved;
     if (evt != null)
     {
         m_events.Enqueue(new Tuple<Delegate, object[]>(evt, new object[] { this, user }));
         m_event.Set();
     }
 }
Пример #22
0
        public void ThreadProc()
        {
            m_twitch = new TwitchClient();

            if (!Connect())
                return;

            const int pingDelay = 20;
            DateTime lastPing = DateTime.Now;
            while (true)
            {
                Thread.Sleep(1000);

                var lastEvent = m_twitch.LastEvent;
                if (lastEvent.Elapsed().TotalSeconds >= pingDelay && lastPing.Elapsed().TotalSeconds >= pingDelay)
                {
                    m_twitch.Ping();
                    lastPing = DateTime.Now;
                }

                if (lastEvent.Elapsed().TotalMinutes >= 1)
                {
                    WinterBotSource.Log.BeginReconnect();
                    WriteStatus("Disconnected!");

                    m_twitch.Quit(250);

                    if (!Connect())
                        return;

                    WinterBotSource.Log.EndReconnect();
                }
                else if (m_reconnect)
                {
                    m_reconnect = false;
                    if (!Connect())
                        return;
                }
            }
        }
Пример #23
0
        public WinterBot(Options options, string channel, string user, string oauth)
        {
            m_data = new TwitchUsers(this);
            m_options = options;
            m_channel = channel.ToLower();

            Passive = m_options.Passive;

            MessageReceived += TryProcessCommand;
            LastMessageSent = DateTime.Now;

            m_twitch = new TwitchClient(m_data);
            m_twitch.InformChatClear += ClearChatHandler;
            m_twitch.MessageReceived += ChatMessageReceived;
            m_twitch.UserSubscribed += SubscribeHandler;
            m_twitch.InformModerator += InformModerator;

            LoadExtensions();
        }
Пример #24
0
        private void JtvMessageReceived(TwitchClient sender, TwitchUser user, string text)
        {
            if (text.StartsWith("The moderators of this"))
            {
                if (m_modListRequested)
                    m_modListRequested = false;
                else
                    return;
            }

            WriteStatus(text);
        }