Ejemplo n.º 1
0
 async void BanWorker(TwitchChannel chan, TwitchUser user)
 {
     while (!chan.Ban(user) && chan.IsJoined)
         await Task.Delay(250);
 }
Ejemplo n.º 2
0
        public TwitchChannel Create(string channel)
        {
            if (string.IsNullOrEmpty(channel) || channel[0] == '#')
                throw new ArgumentException("channel");

            channel = channel.ToLower();

            TwitchChannel twitchChannel;
            lock (m_channels)
            {
                if (!m_channels.TryGetValue(channel, out twitchChannel))
                {
                    twitchChannel = new TwitchChannel(this, channel);
                    m_channels[channel] = twitchChannel;
                }
            }

            return twitchChannel;
        }
Ejemplo n.º 3
0
        private void HandleJtvMessage(TwitchChannel chan, string text, int offset)
        {
            switch (text[offset])
            {
                case 'E':
                    ParseEmoteSet(text, offset);
                    break;

                case 'C':
                    Debug.Assert(chan != null);
                    chan.ParseChatClear(text, offset);
                    break;

                case 'S':
                    ParseSpecialUser(chan, text, offset);
                    break;

                case 'T':
                    Debug.Assert(chan != null);
                    string modMsg = "The moderators of this room are: ";
                    string slowMode = "This room is now in slow mode. You may send messages every ";
                    string slowOff = "This room is no longer in slow mode.";
                    string subMode = "This room is now in subscribers-only mode.";
                    string subModeOff = "This room is no longer in subscribers-only mode.";

                    if (text.StartsWith(modMsg, offset))
                        chan.ParseModerators(text, offset, offset + modMsg.Length);
                    else if (text.StartsWith(slowMode, offset))
                        chan.ParseSlowMode(slowMode, offset + slowMode.Length);
                    else if (text.StartsWith(slowOff, offset))
                        chan.SlowOff();
                    else if (text.StartsWith(subMode, offset))
                        chan.SubMode();
                    else if (text.StartsWith(subModeOff, offset))
                        chan.SubModeOff();
                    else
                        chan.RawJtvMessage(text, offset);
                    break;

                case 'H':
                    Debug.Assert(text.StartsWith("HISTORYEND", offset));
                    break;

                case 'U':
                    ParseUserColor(text, offset);
                    break;

                default:
                    Debug.Assert(chan != null);
                    chan.RawJtvMessage(text, offset);
                    return;
            }
        }
Ejemplo n.º 4
0
 public ChatMessage(TwitchChannel channel, MainWindow controller, TwitchUser user, string message, bool question)
     : base(channel, controller, question ? ItemType.Question : ItemType.Message)
 {
     User = user;
     Message = message;
 }
Ejemplo n.º 5
0
 public ChatAction(TwitchChannel channel, MainWindow controller, TwitchUser user, string message)
     : base(channel, controller, ItemType.Action, user, message)
 {
 }
Ejemplo n.º 6
0
 private static async void TimeoutUserList(int duration, TwitchChannel channel, TwitchUser[] users)
 {
     foreach (var user in users)
     {
         if (duration == -1)
         {
             while (!channel.Ban(user))
                 await Task.Delay(250);
         }
         else
         {
             while (!channel.Timeout(user, duration))
                 await Task.Delay(250);
         }
     }
 }
Ejemplo n.º 7
0
 public ChatItem(TwitchChannel channel, MainWindow controller, ItemType type)
 {
     Channel = channel;
     Controller = controller;
     Type = type;
 }
Ejemplo n.º 8
0
        TwitchConnection LeaveChannel()
        {
            var channel = m_channel;
            if (channel == null)
                return null;

            lock (m_sync)
            {
                if (m_channel == null)
                    return null;

                channel = m_channel;
                m_channel = null;
            }

            channel.Leave();

            channel.ModeratorJoined -= ModJoined;
            channel.UserChatCleared -= UserClearChatHandler;
            channel.MessageReceived -= ChatMessageReceived;
            channel.MessageSent -= ChatMessageReceived;
            channel.StatusMessageReceived -= JtvMessageReceived;
            channel.ActionReceived -= ChatActionReceived;
            channel.UserSubscribed -= SubscribeHandler;
            channel.ChatCleared -= ChatCleared;
            channel.SlowModeBegin -= SlowModeHandler;
            channel.SlowModeEnd -= SlowModeEndHandler;
            channel.SubModeBegin -= SubModeBeginHandler;
            channel.SubModeEnd -= SubModeEndHandler;
            channel.ModListReceived -= ModListReceived;

            return channel.Connection;
        }
Ejemplo n.º 9
0
 private void ChatCleared(TwitchChannel channel)
 {
     Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action<ChatItem>(AddItem), new StatusMessage(null, this, "Chat was cleared by a moderator"));
 }
Ejemplo n.º 10
0
 void ModListReceived(TwitchChannel channel, TwitchUser[] moderators)
 {
     Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action<TwitchChannel>(ModListReceivedWorker), channel);
 }
Ejemplo n.º 11
0
 private void ModListReceivedWorker(TwitchChannel channel)
 {
     // Setting initial state, it's ok we haven't joined the channel yet.
     var currUser = CurrentUser = channel.GetUser(m_options.User);
     if (currUser.IsModerator)
         ModJoined(channel, currUser);
     else
         ModLeft(channel, currUser);
 }
Ejemplo n.º 12
0
 async void ChangeChannel(string newChannel)
 {
     var twitch = LeaveChannel();
     if (twitch == null)
         m_channel = await Connect(newChannel);
     else
         m_channel = JoinChannel(twitch, newChannel);
 }
Ejemplo n.º 13
0
 private async void Reconnect(string channelName)
 {
     Disconnect();
     m_channel = await Connect(channelName);
 }
Ejemplo n.º 14
0
        async void TimeoutWorker(TwitchChannel chan, TwitchUser user, int duration)
        {
            if (duration < 1)
                duration = 1;

            while (!chan.Timeout(user, duration) && chan.IsJoined)
                await Task.Delay(250);
        }
Ejemplo n.º 15
0
 private void ModJoined(TwitchChannel conn, TwitchUser user)
 {
     if (user == CurrentUser)
         ModButtonVisibility = Visibility.Visible;
 }
Ejemplo n.º 16
0
 private void SlowModeEndHandler(TwitchChannel channel)
 {
     Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action<ChatItem>(AddItem), new StatusMessage(null, this, "This room is no longer in subscribers-only mode."));
 }
Ejemplo n.º 17
0
 private void ModLeft(TwitchChannel conn, TwitchUser user)
 {
     if (user == CurrentUser)
         ModButtonVisibility = Visibility.Collapsed;
 }
Ejemplo n.º 18
0
 private void SlowModeHandler(TwitchChannel channel, int time)
 {
     Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action<ChatItem>(AddItem), new StatusMessage(null, this, string.Format("This room is now in slow mode. You may send messages every {0} seconds.", time)));
 }
Ejemplo n.º 19
0
        async void LoadAsyncData()
        {
            var connectTask = Connect(m_channelName);

            string path = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
            m_cache = System.IO.Path.Combine(path, "TwitchChat");

            var task = TwitchApi.GetEmoticonData(m_cache);
            GetChannelData();

            Emoticons = await task;
            m_channel = await connectTask;
        }
Ejemplo n.º 20
0
        private void SubscribeHandler(TwitchChannel sender, TwitchUser user)
        {
            if (PlaySounds)
                m_subSound.Play();

            var sub = new Subscriber(sender, this, user);
            Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action<Subscriber>(DispatcherUserSubscribed), sub);
        }
Ejemplo n.º 21
0
 public Subscriber(TwitchChannel channel, MainWindow controller, TwitchUser user)
     : base(channel, controller, ItemType.Subscriber)
 {
     User = user;
 }
Ejemplo n.º 22
0
        private void ChatActionReceived(TwitchChannel sender, TwitchUser user, string text)
        {
            if (m_options.Ignore.Contains(user.Name))
                return;

            var emotes = Emoticons;
            if (emotes != null)
                emotes.EnsureDownloaded(user.ImageSet);

            Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action<ChatItem>(AddItem), new ChatAction(sender, this, user, text));
        }
Ejemplo n.º 23
0
 public ChatMessage(TwitchChannel channel, MainWindow controller, ItemType type, TwitchUser user, string message)
     : base(channel, controller, type)
 {
     User = user;
     Message = message;
 }
Ejemplo n.º 24
0
        private void JtvMessageReceived(TwitchChannel sender, string text)
        {
            if (text.StartsWith("The moderators of this"))
            {
                if (m_modListRequested)
                    m_modListRequested = false;
                else
                    return;
            }

            WriteStatus(text);
        }
Ejemplo n.º 25
0
 public StatusMessage(TwitchChannel channel, MainWindow controller, string message)
     : base(channel, controller, ItemType.Status)
 {
     Message = message;
 }
Ejemplo n.º 26
0
        private void ChatMessageReceived(TwitchChannel sender, TwitchUser user, string text)
        {
            if (m_options.Ignore.Contains(user.Name))
                return;

            var emotes = Emoticons;
            if (emotes != null)
                emotes.EnsureDownloaded(user.ImageSet);

            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(sender, this, user, text, question));
        }
Ejemplo n.º 27
0
        public TwitchChannel GetChannel(string channel)
        {
            channel = channel.ToLower();

            var twitchChannel = m_lastChannel;
            if (twitchChannel != null && twitchChannel.Name == channel)
                return twitchChannel;

            bool created = false;
            lock (m_channels)
            {
                if (!m_channels.TryGetValue(channel, out twitchChannel))
                {
                    twitchChannel = m_channels[channel] = new TwitchChannel(this, channel);
                    created = true;
                }
            }

            if (created)
            {
                var evt = ChannelCreated;
                if (evt != null)
                    evt(this, twitchChannel);
            }

            m_lastChannel = twitchChannel;
            return twitchChannel;
        }
Ejemplo n.º 28
0
 private void UserClearChatHandler(TwitchChannel sender, TwitchUser user)
 {
     Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action<TwitchUser>(DispatcherClearChat), user);
 }
Ejemplo n.º 29
0
        internal void ParseSpecialUser(TwitchChannel chan, string text, int offset)
        {
            //*  SPECIALUSER username subscriber

            string specialuser = "******";
            if (!text.StartsWith(specialuser, offset))
            {
                Debug.Fail("ParseSpecialUser received unexpected string start.");
                return;
            }

            offset += specialuser.Length;

            int i = text.IndexOf(' ', offset);
            string name = text.Slice(offset, i);

            if (text.EndsWith("subscriber"))
            {
                if (chan == null)
                {
                    Debug.Fail("Subscriber message sent to non-channel.");
                    return;
                }

                var user = chan.GetUser(name);
                user.IsSubscriber = true;
            }
            else if (text.EndsWith("turbo"))
            {
                var user = GetUserData(name);
                user.IsTurbo = true;
            }
            else if (text.EndsWith("admin"))
            {
                var user = GetUserData(name);
                user.IsAdmin = true;
            }
            else if (text.EndsWith("staff"))
            {
                var user = GetUserData(name);
                user.IsStaff = true;
            }
            else
            {
                Debug.Fail(string.Format("Parse SpecialMessage could not parse {0}", text));
            }
        }
Ejemplo n.º 30
0
        static async Task<TwitchChannel[]> ConnectAsync(params string[] channelNames)
        {
            TwitchConnection twitch = new TwitchConnection();

            string[] loginData = File.ReadLines("login.txt").Take(2).ToArray();

            var connectResult = await twitch.ConnectAsync(loginData[0], loginData[1]);
            if (connectResult != ConnectResult.Connected)
            {
                Console.WriteLine("Failed to login.");
                return null;
            }

            //TwitchChannel result = Create(channel);
            //await result.JoinAsync();
            //return result;



            TwitchChannel[] channels = (from channelName in channelNames select twitch.Create(channelName)).ToArray();
            Task[] channelTasks = (from channel in channels select channel.JoinAsync()).ToArray();

            var result = new TwitchChannel[channelTasks.Length];

            for (int i = 0; i < result.Length; ++i)
                await channelTasks[i];

            return channels;
        }