Beispiel #1
0
        public UserViewModel(TwitchNewAPI.Users.UserModel twitchUser)
        {
            this.SetUserData(twitchID: twitchUser.id);

            this.TwitchID          = twitchUser.id;
            this.TwitchUsername    = twitchUser.login;
            this.TwitchDisplayName = (!string.IsNullOrEmpty(twitchUser.display_name)) ? twitchUser.display_name : this.TwitchUsername;
            this.TwitchAvatarLink  = twitchUser.profile_image_url;

            this.SetTwitchRoles();
        }
Beispiel #2
0
        private async Task RefreshTwitchUserDetails()
        {
            TwitchNewAPI.Users.UserModel twitchUser = (!string.IsNullOrEmpty(this.TwitchID)) ? await ChannelSession.TwitchUserConnection.GetNewAPIUserByID(this.TwitchID)
                : await ChannelSession.TwitchUserConnection.GetNewAPIUserByLogin(this.TwitchUsername);

            if (twitchUser != null)
            {
                this.TwitchID          = twitchUser.id;
                this.TwitchUsername    = twitchUser.login;
                this.TwitchDisplayName = (!string.IsNullOrEmpty(twitchUser.display_name)) ? twitchUser.display_name : this.TwitchDisplayName;
                this.TwitchAvatarLink  = twitchUser.profile_image_url;

                if (twitchUser.IsPartner())
                {
                    this.UserRoles.Add(UserRoleEnum.Partner);
                }
                else
                {
                    this.UserRoles.Remove(UserRoleEnum.Partner);
                }
                if (twitchUser.IsAffiliate())
                {
                    this.UserRoles.Add(UserRoleEnum.Affiliate);
                }
                else
                {
                    this.UserRoles.Remove(UserRoleEnum.Affiliate);
                }
                if (twitchUser.IsStaff())
                {
                    this.UserRoles.Add(UserRoleEnum.Staff);
                }
                else
                {
                    this.UserRoles.Remove(UserRoleEnum.Staff);
                }
                if (twitchUser.IsGlobalMod())
                {
                    this.UserRoles.Add(UserRoleEnum.GlobalMod);
                }
                else
                {
                    this.UserRoles.Remove(UserRoleEnum.GlobalMod);
                }

                this.SetTwitchRoles();

                this.Color = null;
                this.RolesDisplayString = null;
            }
        }
Beispiel #3
0
        public static async Task <UserViewModel> Create(TwitchNewAPI.Users.UserModel twitchUser)
        {
            UserViewModel user = await UserViewModel.Create(StreamingPlatformTypeEnum.Twitch, twitchUser.id);

            user.TwitchID          = twitchUser.id;
            user.TwitchUsername    = twitchUser.login;
            user.TwitchDisplayName = (!string.IsNullOrEmpty(twitchUser.display_name)) ? twitchUser.display_name : user.TwitchUsername;
            user.TwitchAvatarLink  = twitchUser.profile_image_url;

            user.SetTwitchRoles();

            ChannelSession.Settings.SetUserData(user.Data);

            return(user);
        }
Beispiel #4
0
 public static bool IsGlobalMod(this TwitchNewAPI.Users.UserModel twitchUser)
 {
     return(twitchUser.type.Equals("global_mod"));
 }
Beispiel #5
0
 public static bool IsStaff(this TwitchNewAPI.Users.UserModel twitchUser)
 {
     return(twitchUser.type.Equals("staff") || twitchUser.type.Equals("admin"));
 }
Beispiel #6
0
 public static bool IsPartner(this TwitchNewAPI.Users.UserModel twitchUser)
 {
     return(twitchUser.broadcaster_type.Equals("partner"));
 }
Beispiel #7
0
 public static bool IsAffiliate(this TwitchNewAPI.Users.UserModel twitchUser)
 {
     return(twitchUser.broadcaster_type.Equals("affiliate"));
 }
Beispiel #8
0
        private async Task ChatterJoinLeaveBackground(CancellationToken cancellationToken)
        {
            List <string> joinsToProcess = new List <string>();

            await this.userJoinLeaveEventsSemaphore.WaitAndRelease(() =>
            {
                for (int i = 0; i < userJoinLeaveEventsTotalToProcess && i < this.userJoinEvents.Count(); i++)
                {
                    string chatUser = this.userJoinEvents.First();
                    joinsToProcess.Add(chatUser);
                    this.userJoinEvents.Remove(chatUser);
                }
                return(Task.FromResult(0));
            });

            if (joinsToProcess.Count > 0)
            {
                List <UserViewModel> processedUsers = new List <UserViewModel>();
                foreach (string chatUser in joinsToProcess)
                {
                    TwitchNewAPI.Users.UserModel twitchUser = await ChannelSession.TwitchUserConnection.GetNewAPIUserByLogin(chatUser);

                    if (twitchUser != null)
                    {
                        UserViewModel user = await ChannelSession.Services.User.AddOrUpdateUser(twitchUser);

                        if (user != null)
                        {
                            processedUsers.Add(user);
                        }
                    }
                }
                this.OnUsersJoinOccurred(this, processedUsers);
            }

            List <string> leavesToProcess = new List <string>();

            await this.userJoinLeaveEventsSemaphore.WaitAndRelease(() =>
            {
                for (int i = 0; i < userJoinLeaveEventsTotalToProcess && i < this.userLeaveEvents.Count(); i++)
                {
                    string chatUser = this.userLeaveEvents.First();
                    leavesToProcess.Add(chatUser);
                    this.userLeaveEvents.Remove(chatUser);
                }
                return(Task.FromResult(0));
            });

            if (leavesToProcess.Count > 0)
            {
                List <UserViewModel> processedUsers = new List <UserViewModel>();
                foreach (string chatUser in leavesToProcess)
                {
                    if (!string.IsNullOrEmpty(chatUser))
                    {
                        UserViewModel user = await ChannelSession.Services.User.RemoveUserByTwitchLogin(chatUser);

                        if (user != null)
                        {
                            processedUsers.Add(user);
                        }
                    }
                }
                this.OnUsersLeaveOccurred(this, processedUsers);
            }
        }