Пример #1
0
        public void JoinChannel(Channel channel)
        {
            if (channel == null)
            {
                return;
            }

            // ReSharper disable once AccessToModifiedClosure
            var existing = JoinedChannels.FirstOrDefault(c => c.Id == channel.Id);

            if (existing != null)
            {
                // if we already have this channel loaded, we don't want to make a second one.
                channel = existing;
            }
            else
            {
                var foundSelf = channel.Users.FirstOrDefault(u => u.Id == api.LocalUser.Value.Id);
                if (foundSelf != null)
                {
                    channel.Users.Remove(foundSelf);
                }

                JoinedChannels.Add(channel);

                if (channel.Type == ChannelType.Public && !channel.Joined)
                {
                    var req = new JoinChannelRequest(channel, api.LocalUser);
                    req.Success += () =>
                    {
                        channel.Joined.Value = true;
                        JoinChannel(channel);
                    };
                    req.Failure += ex => LeaveChannel(channel);
                    api.Queue(req);
                    return;
                }
            }

            if (CurrentChannel.Value == null)
            {
                CurrentChannel.Value = channel;
            }

            if (!channel.MessagesLoaded)
            {
                // let's fetch a small number of messages to bring us up-to-date with the backlog.
                fetchInitalMessages(channel);
            }
        }
Пример #2
0
        void OnJoin(string[] args)
        {
            if (!JoinedChannels.ContainsKey(args[0]))
            {
                JoinedChannels.Add(args[0], Channel.Create(args[0]));

                var cancelEventArgs = new CancelEventArgs <TasEventArgs>(new TasEventArgs(args));
                PreviewChannelJoined(this, cancelEventArgs);
                if (!cancelEventArgs.Cancel)
                {
                    ChannelJoined(this, new TasEventArgs(args));
                }
            }
        }
Пример #3
0
 private void queueingJoinCheck()
 {
     if (joinChannelQueue.Count > 0)
     {
         currentlyJoiningChannels = true;
         JoinedChannel channelToJoin = joinChannelQueue.Dequeue();
         log($"Joining channel: {channelToJoin.Channel}");
         _client.Send(Rfc2812.Join($"#{channelToJoin.Channel}"));
         JoinedChannels.Add(new JoinedChannel(channelToJoin.Channel));
     }
     else
     {
         log("Finished channel joining queue.");
     }
 }
Пример #4
0
 private void queueingJoinCheck()
 {
     if (joinChannelQueue.Count > 0)
     {
         currentlyJoiningChannels = true;
         JoinedChannel channelToJoin = joinChannelQueue.Dequeue();
         if (_logging)
         {
             Common.Log($"Joining channel: {channelToJoin.Channel}");
         }
         _client.WriteLine(Rfc2812.Join($"#{channelToJoin.Channel}"));
         JoinedChannels.Add(new JoinedChannel(channelToJoin.Channel));
     }
     else
     {
         if (_logging)
         {
             Common.Log("Finished channel joining queue.");
         }
     }
 }
Пример #5
0
        private void Connected(object sender, EventArgs e)
        {
            // Make sure proper formatting is applied to oauth
            if (!_credentials.TwitchOAuth.Contains(":"))
            {
                _credentials.TwitchOAuth = _credentials.TwitchOAuth.Replace("oauth", "");
                _credentials.TwitchOAuth = $"oauth:{_credentials.TwitchOAuth}";
            }
            _client.WriteLine(Rfc2812.Pass(_credentials.TwitchOAuth), Priority.Critical);
            _client.WriteLine(Rfc2812.Nick(_credentials.TwitchUsername), Priority.Critical);
            _client.WriteLine(Rfc2812.User(_credentials.TwitchUsername, 0, _credentials.TwitchUsername),
                              Priority.Critical);

            _client.WriteLine("CAP REQ twitch.tv/membership");
            _client.WriteLine("CAP REQ twitch.tv/commands");
            _client.WriteLine("CAP REQ twitch.tv/tags");

            if (_autoJoinChannel != null)
            {
                JoinedChannels.Add(new JoinedChannel(_autoJoinChannel));
                _client.WriteLine(Rfc2812.Join($"#{_autoJoinChannel}"));
            }

            if (_listenThread == null || _listenThread.IsCompleted)
            {
                _listenThread = Task.Factory.StartNew(() =>
                {
                    while (_client.IsConnected)
                    {
                        if (_logging)
                        {
                            Common.Log("Starting listen..", false, false, Enums.LogType.Success);
                        }
                        try
                        {
                            _client.Listen();
                        } catch (Exception ex)
                        {
                            if (_logging)
                            {
                                Common.Log("Exception!!", true, true, Enums.LogType.Failure);
                                Common.Log(ex.Message, false, false, Enums.LogType.Failure);
                            }
                            if (!_autoReListenOnException)
                            {
                                throw ex;
                            }
                        }
                        if (_logging)
                        {
                            Common.Log("Stopped listening..", true, true, Enums.LogType.Failure);
                        }
                    }
                });
            }
            else
            {
                if (_logging)
                {
                    Common.Log("Already listening, not starting new thread...");
                }
            }
        }