示例#1
0
 /// <summary>
 /// adds a service to the collection
 /// </summary>
 /// <param name="type">type of service</param>
 /// <param name="module">module handling service calls</param>
 public void AddService(string type, IStreamServiceModule module)
 {
     services[type]    = module;
     module.Connected += () => {
         Logger.Info(this, $"{type} connected");
         ServiceConnected?.Invoke(type);
     };
     module.NewFollower += information => {
         Logger.Info(this, $"New follower '{information.Username}' on {type}.");
         if (ValidUser(information.Service, information.Username))
         {
             NewFollower?.Invoke(information);
         }
     };
     module.NewSubscriber += AddSubscriber;
     if (module is IStreamStatsModule)
     {
         ((IStreamStatsModule)module).ViewersChanged += OnViewersChanged;
     }
 }
示例#2
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);
        }