Exemplo n.º 1
0
        private static void JoinHandler(TwitchChannel channel, IrcRawMessageEventArgs args)
        {
            string userNickname = args.Message.Source.Name;

            lock ((channel.Chat as TwitchChat).chatUsersLock)
            {
                if (!(channel.Chat as IChatUserList).ChatUsers.ToList().Any(u => u.NickName.Equals(userNickname)))
                {
                    ObservableCollection <UserBadge> badges;
                    string userGroup = "Users";
                    channel.userBadges.TryGetValue(userNickname, out badges);
                    channel.AddChatUser(userNickname, userGroup, badges);
                }
            }
            Log.WriteInfo("Twitch user joined: {0}", userNickname);
            if (userNickname.Equals(channel.Chat.NickName, StringComparison.InvariantCultureIgnoreCase))
            {
                if (!channel.Chat.IsAnonymous)
                {
                    channel.Chat.Status.IsLoggedIn = true;
                }

                channel.pingTimer.Change(pingInterval, pingInterval);

                if (channel.JoinCallback != null)
                {
                    channel.JoinCallback(channel);
                }
            }
        }
Exemplo n.º 2
0
        private static void UserListHandler(TwitchChannel channel, IrcRawMessageEventArgs args)
        {
            var parameters = args.Message.Parameters;

            if (parameters.Count < 3)
            {
                return;
            }

            string userGroup = "Users";

            var users = parameters[3].Split(' ');

            if (users.Count() <= 0)
            {
                return;
            }

            foreach (var userNickname in users)
            {
                lock ((channel.Chat as TwitchChat).chatUsersLock)
                {
                    channel.AddChatUser(userNickname, userGroup, null);
                }
            }
        }
Exemplo n.º 3
0
        private static void ConnectHandler(TwitchChannel channel, IrcRawMessageEventArgs args)
        {
            if (channel.ircClient.Channels.Count <= 0)
            {
                channel.Chat.Status.IsConnected  = true;
                channel.Chat.Status.IsConnecting = false;
                channel.TryIrc(() => channel.ircClient.Channels.Join(channel.ChannelName));
                channel.TryIrc(() => channel.ircClient.SendRawMessage("TWITCHCLIENT 1"));

                if ((Application.Current as App).AppConfig.IsUserListVisible)
                {
                    Task.Run(() => channel.LoadInitialUserList());
                }
            }

            if (channel.Chat.IsAnonymous)
            {
                channel.pingTimer.Change(pingInterval, pingInterval);

                if (channel.JoinCallback != null)
                {
                    channel.JoinCallback(channel);
                }
            }
        }
Exemplo n.º 4
0
 private static void NoticeHandler(TwitchChannel channel, IrcRawMessageEventArgs args)
 {
     Log.WriteInfo("Twitch notice: {0}", args.RawContent);
     if (args.RawContent.Contains("Login unsuccessful"))
     {
         Thread.Sleep(2000);
         channel.Leave();
     }
 }
Exemplo n.º 5
0
        private static void LeaveHandler(TwitchChannel channel, IrcRawMessageEventArgs args)
        {
            string userNickname = args.Message.Source.Name;

            UI.Dispatch(() => {
                (channel.Chat as IChatUserList).ChatUsers
                .RemoveAll(user => user.NickName.Equals(userNickname, StringComparison.InvariantCultureIgnoreCase));
            });
            Log.WriteInfo("Twitch user left: {0}", args.Message.Source);
        }
Exemplo n.º 6
0
        private static void PrivateMessageHandler(TwitchChannel channel, IrcRawMessageEventArgs args)
        {
            var parameters = args.Message.Parameters;

            if (parameters.Count < 2)
            {
                return;
            }

            if (parameters[1].StartsWith("specialuser", StringComparison.InvariantCultureIgnoreCase))
            {
                var userBadgeParams = parameters[1].Split(' ');
                if (userBadgeParams.Length == 3)
                {
                    channel.SetUserBadge(userBadgeParams[1], userBadgeParams[2]);
                }
            }
            else if (parameters[1].StartsWith("usercolor", StringComparison.InvariantCultureIgnoreCase))
            {
                var userColorParams = parameters[1].Split(' ');

                //ObservableCollection<UserBadge> userbadges = null;
                //channel.userBadges.TryGetValue(userColorParams[1], out userbadges);
                //if (userColorParams.Length == 3)
                //    channel.AddChatUser(userColorParams[1], "user", userbadges);
            }

            if (!parameters[0].Equals(channel.ChannelName, StringComparison.InvariantCultureIgnoreCase))
            {
                return;
            }

            channel.ChannelStats.MessagesCount++;
            channel.Chat.UpdateStats();

            if (channel.ReadMessage != null)
            {
                channel.ReadMessage(new ChatMessage()
                {
                    Channel         = channel.ChannelName,
                    ChatIconURL     = channel.Chat.IconURL,
                    ChatName        = channel.Chat.ChatName,
                    FromUserName    = args.Message.Source.Name,
                    HighlyImportant = false,
                    IsSentByMe      = false,
                    Text            = parameters[1],
                    UserBadges      = channel.userBadges.ContainsKey(args.Message.Source.Name) ? channel.userBadges[args.Message.Source.Name] : null
                });
            }
        }
Exemplo n.º 7
0
        private static void ModeHandler(TwitchChannel channel, IrcRawMessageEventArgs args)
        {
            var parameters = args.Message.Parameters;

            if (parameters.Count < 3)
            {
                return;
            }
            if (!parameters[1].Equals("+o"))
            {
                return;
            }

            var username = parameters[2];

            if (!username.Equals(channel.Chat.NickName, StringComparison.InvariantCultureIgnoreCase))
            {
                channel.SetUserBadge(parameters[2], "mod");
            }
        }