Exemplo n.º 1
0
        public LiveStreamMonitorService(ITwitchAPI api, int secondsBetweenChecks)
        {
            this.api = api;

            //Load the info for streams that have been reported on.
            //string monitoredUsersResult = SaveLoadService.Load(monitoredUsersFilename);
            Dictionary <string, Stream> monitoredChannels = SaveLoadService.Load <Dictionary <string, Stream> >(monitoredUsersFilename);

            if (monitoredChannels == null)
            {
                monitoredChannels = new Dictionary <string, Stream>();
                SaveLoadService.Save(monitoredUsersFilename, monitoredChannels);
            }

            LiveStreams.Clear();
            foreach (var key in monitoredChannels.Keys)
            {
                LiveStreams.TryAdd(key, monitoredChannels[key]);
            }

            // Call the check with the given interval between the calls.
            timer           = new Timer(TimeSpan.FromSeconds(secondsBetweenChecks).TotalMilliseconds);
            timer.AutoReset = true;
            timer.Elapsed  += new ElapsedEventHandler(Tick);
            timer.Start();
        }
Exemplo n.º 2
0
        private void LoadData()
        {
            //Load the info for the guilds and the users they want reported.
            string guildInfoResult = SaveLoadService.Load(twitchGuildInfoFilename);

            if (guildInfoResult != null)
            {
                guilds = JsonConvert.DeserializeObject <List <TwitchGuildDefinition> >(guildInfoResult);
            }

            UpdateMonitoredChannels();
        }
Exemplo n.º 3
0
        public AutoRolesService(DiscordSocketClient client)
        {
            this.client = client;
            autoRoles   = SaveLoadService.Load <List <AutoRolesGuildDefinition> >(monitoredUsersFilename);
            if (autoRoles == null)
            {
                autoRoles = new List <AutoRolesGuildDefinition>();
                SaveLoadService.Save(monitoredUsersFilename, autoRoles);
            }

            client.UserJoined += OnUserJoinedGuild;
        }
Exemplo n.º 4
0
        public TwitchService(DiscordSocketClient client)
        {
            if (!serviceEnabled)
            {
                Console.WriteLine("Twitch service disabled.");
                return;
            }
            this.client = client;
            api         = new TwitchAPI();
            TwitchKeys twitchKeys = SaveLoadService.Load <TwitchKeys>(twitchKeysFilename);

            if (twitchKeys == null)
            {
                twitchKeys = new TwitchKeys();
                SaveLoadService.Save(twitchKeysFilename, twitchKeys);
            }
            api.Settings.AccessToken        = twitchKeys.accessToken;
            api.Settings.ClientId           = twitchKeys.clientID;
            api.Settings.Secret             = twitchKeys.secret;
            monitorService                  = new LiveStreamMonitorService(api, 240);
            monitorService.OnStreamOnline  += OnStreamOnline;
            monitorService.OnStreamOffline += OnStreamOffline;
            LoadData();
        }