Пример #1
0
        public Task ResetAsync([Remainder][Summary("The text to echo")] string userName)
        {
            Context.Message.AddReactionAsync(new Discord.Emoji("👍"));

            lock (Data.Streamers){
                foreach (var si in Data.Streamers)
                {
                    if (si.Key == userName)
                    {
                        TwitchUser user = Twitch.GetUserByID(si.Value.id);
                        if (user == null)
                        {
                            return(ReplyAsync("I couldn't find that Twitch streamer. Sorry!"));
                        }

                        DateTime?lastStreamTime = si.Value.lastStream;

                        Data.Streamers.Remove(userName);
                        Data.Streamers.Add(user.displayName, new StreamerInfo(user.id, lastStreamTime));
                        Data.Save();

                        return(ReplyAsync("Success - data for **" + Utility.SanitizeForMarkdown(user.displayName) + "** has been reset."));
                    }
                }
            }

            return(ReplyAsync("No users with that ID are currently in the list."));
        }
Пример #2
0
        public Task AddAsync([Remainder][Summary("Name of the Twitch streamer you want to add or remove from the list")] string streamerName)
        {
            Context.Message.AddReactionAsync(new Discord.Emoji("👍"));             //Thumbs up to acknowledge that the command was received

            bool containsKey  = false;
            int  numStreamers = 0;

            lock (Data.Streamers){
                numStreamers = Data.Streamers.Count;
                foreach (var s in Data.Streamers)
                {
                    if (streamerName.Equals(s.Key, System.StringComparison.OrdinalIgnoreCase))
                    {
                        containsKey  = true;
                        streamerName = s.Key;
                        break;
                    }
                }

                if (containsKey)
                {
                    Data.Streamers.Remove(streamerName);
                }
            }

            if (containsKey)
            {
                Data.Save();
                return(ReplyAsync("Success - **" + Utility.SanitizeForMarkdown(streamerName) + "** will no longer be announced. There are now " + (numStreamers - 1) + " streamers in the list."));
            }

            TwitchUser user = Twitch.GetUserByName(streamerName);

            if (user == null)
            {
                return(ReplyAsync("I couldn't find any Twitch streamers with that name. Sorry!"));
            }

            lock (Data.Streamers){
                foreach (var s in Data.Streamers)
                {
                    if (s.Value.id == user.id)
                    {
                        return(ReplyAsync("User is currently in list with an older username (**" + Utility.SanitizeForMarkdown(s.Key) + ")"));
                    }
                }

                Data.Streamers.Add(user.displayName, new StreamerInfo(user.id));
            }

            Data.Save();
            return(ReplyAsync("Success - **" + Utility.SanitizeForMarkdown(user.displayName) + "** will now be announced. There are now " + (numStreamers + 1) + " streamers in the list."));
        }
Пример #3
0
        private async void CheckStreams()
        {
            List <string> loggedStreams = new List <string>();
            Dictionary <string, string> currentLiveStreams;

            int iterations = 0;

            while (true)
            {
                currentLiveStreams = new Dictionary <string, string>();

                if (iterations > 0)
                {
                    System.Threading.Thread.Sleep((int)(1000.0f * 60.0f * Data.UpdateFrequency));                     //Every [updateFrequency] minutes
                }

                if (checkingStreams)
                {
                    continue;                     //Prevent it from checking for streams twice at the same time
                }
                checkingStreams = true;

                Debug.Log("Checking for new streams to announce...", Debug.Verbosity.Verbose);
                List <TwitchStream> streams = Twitch.GetCurrentStreams();
                if (streams == null)
                {
                    Debug.Log("An error has occured while attempting to get streams, restarting process...", Debug.Verbosity.Error);
                    System.Threading.Thread.Sleep(1000 * 30);                     //Wait 30 seconds before starting over
                    checkingStreams = false;
                    continue;
                }

                int streamsAnnounced = 0;
                foreach (TwitchStream ts in streams)
                {
                    string gameName;
                    if (Data.IsCached(ts.id))
                    {
                        gameName = Data.GetCachedGame(ts.id);
                    }
                    else
                    {
                        gameName = Data.CacheGame(ts.id, Twitch.GetGameName(ts.gameID));
                    }

                    if (ts.title.ToLower().Contains("[nosrl]"))
                    {
                        currentLiveStreams.Add(ts.user, gameName + " [nosrl]");
                    }
                    else
                    {
                        currentLiveStreams.Add(ts.user, gameName);
                    }

                    lock (Data.AnnouncedStreams){
                        if (Data.AnnouncedStreams.Contains(ts.id))
                        {
                            if (Twitch.gameIDs.ContainsValue(ts.gameID) && !ts.title.ToLower().Contains("[nosrl]"))
                            {
                                streamsAnnounced++;                                 //Only count towards the total if it's still a Batman speedrunning stream
                            }

                            continue;                             //We've already announced this stream
                        }
                    }

                    if (Twitch.gameIDs.ContainsValue(ts.gameID) && !ts.title.ToLower().Contains("[nosrl]"))
                    {
                        streamsAnnounced++;
                        await AnnounceStream(ts);
                    }
                    else
                    {
                        if (!loggedStreams.Contains(ts.id))
                        {
                            if (ts.title.ToLower().Contains("[nosrl]"))
                            {
                                Debug.Log(ts.user + " is streaming non-speedrunning content, ignoring...");
                            }
                            else
                            {
                                Debug.Log(ts.user + " is streaming a non-Batman game (" + gameName + "), ignoring...");
                            }

                            loggedStreams.Add(ts.id);
                        }
                    }
                }

                if (streamsAnnounced == 0)
                {
                    await _client.SetGameAsync("for new Batman streams", null, ActivityType.Watching);
                }
                else if (streamsAnnounced == 1)
                {
                    await _client.SetGameAsync("a Batman stream", null, ActivityType.Watching);
                }
                else if (streamsAnnounced > 1)
                {
                    await _client.SetGameAsync(streamsAnnounced + " Batman streams", null, ActivityType.Watching);
                }

                iterations++;
                Debug.Log(streamsAnnounced + " previously-announced stream(s) are still live with Batman content", Debug.Verbosity.Verbose);
                Debug.Log("Check " + iterations + " complete. Program is now idle.", Debug.Verbosity.Verbose);

                lock (Data.CurrentlyLive){ Data.CurrentlyLive = currentLiveStreams; }
                Data.Save();

                checkingStreams = false;
            }
        }