示例#1
0
        void CheckFollowers()
        {
            if (cooldown > 0)
            {
                --cooldown;
                return;
            }

            cooldown = 5;

            UserModule usermodule = context.GetModule <UserModule>();

            try {
                foreach (UserInformation follower in GetFollowers())
                {
                    usermodule.SetInitialized(TwitchConstants.ServiceKey, follower.Username);

                    if (!string.IsNullOrEmpty(follower.Avatar))
                    {
                        User user = usermodule.GetUser(TwitchConstants.ServiceKey, follower.Username);
                        if (user.Avatar != follower.Avatar)
                        {
                            usermodule.UpdateUserAvatar(user, follower.Avatar);
                        }
                    }

                    if (usermodule.GetUserStatus(TwitchConstants.ServiceKey, follower.Username) >= UserStatus.Follower)
                    {
                        continue;
                    }

                    if (usermodule.SetUserStatus(TwitchConstants.ServiceKey, follower.Username, UserStatus.Follower))
                    {
                        NewFollower?.Invoke(follower);
                    }
                }
            }
            catch (WebException e)
            {
                Logger.Warning(this, "Unable to get followers", e.Message);
                return;
            }
            catch (Exception e)
            {
                Logger.Error(this, "Unable to get followers", e);
                return;
            }

            try
            {
                foreach (SubscriberInformation subscriber in GetSubscribers())
                {
                    usermodule.SetInitialized(TwitchConstants.ServiceKey, subscriber.Username);

                    if (!string.IsNullOrEmpty(subscriber.Avatar))
                    {
                        User user = usermodule.GetUser(TwitchConstants.ServiceKey, subscriber.Username);
                        if (user.Avatar != subscriber.Avatar)
                        {
                            usermodule.UpdateUserAvatar(user, subscriber.Avatar);
                        }
                    }

                    if (usermodule.GetUserStatus(TwitchConstants.ServiceKey, subscriber.Username) >= subscriber.Status)
                    {
                        continue;
                    }

                    if (usermodule.SetUserStatus(TwitchConstants.ServiceKey, subscriber.Username, subscriber.Status))
                    {
                        NewSubscriber?.Invoke(subscriber);
                    }
                }
            }
            catch (WebException e) {
                Logger.Warning(this, "Unable to get subscribers", e.Message);
                return;
            }
            catch (Exception e) {
                Logger.Error(this, "Unable to get subscribers", e);
                return;
            }

            context.GetModule <UserModule>().EndInitialization(TwitchConstants.ServiceKey);
        }
示例#2
0
 public void AddSubscriber(SubscriberInformation subscriber)
 {
     Logger.Info(this, $"New subscriber '{subscriber.Username}' with plan {subscriber.PlanName} on {subscriber.Service}.");
     NewSubscriber?.Invoke(subscriber);
 }