Exemplo n.º 1
0
        public static void RefreshDBFollowers()
        {
            DatabaseContext context = new DatabaseContext();
            var             follows = TwitchHelpers.GetFollowers();
            int             id;
            string          key;
            ViewerStats     viewer    = new ViewerStats();
            NewViewerConfig newViewer = new NewViewerConfig();

            Console.ForegroundColor = ConsoleColor.Blue;
            Console.WriteLine("This is experimental. Use at your own risk. Continue? Y/N");
            while (true)
            {
                key = Console.ReadLine();
                if (key.Equals("Y", StringComparison.InvariantCultureIgnoreCase))
                {
                    break;
                }
                if (key.Equals("N", StringComparison.InvariantCultureIgnoreCase))
                {
                    Console.WriteLine("Execution cancelled.");
                    Console.ResetColor();
                    return;
                }
                else
                {
                    Console.WriteLine("This is experimental. Use at your own risk. Continue? Y/N");
                }
            }


            for (int i = 0; i < follows.Result.Count - 1; i++)
            {
                id     = Convert.ToInt32(follows.Result[i].User.Id);
                viewer = new ViewerStats();
                viewer = context.ViewerStats.Where(x => x.TwitchID == id).FirstOrDefault();
                if (viewer == null)
                {
                    newViewer = new NewViewerConfig();
                    viewer    = newViewer.initViewer(follows.Result[i].User.Name, follows.Result[i].User.Id, follows.Result[i].CreatedAt.ToString(),
                                                     follows.Result[i].CreatedAt.ToString());

                    context.ViewerStats.Add(viewer);
                }
                else
                {
                    if (viewer.FirstSeen == null)
                    {
                        viewer.FirstSeen = follows.Result[i].CreatedAt.ToString();
                    }

                    viewer.FirstFollowed = follows.Result[i].CreatedAt.ToString();
                }
                Console.WriteLine(string.Format("{0} followed at: {1}", follows.Result[i].User.Name, follows.Result[i].CreatedAt));
            }
            Console.WriteLine("Saving... This may take a while.");
            context.SaveChanges();
            Console.WriteLine("Complete!");
            Console.ResetColor();
        }
Exemplo n.º 2
0
        private void Client_OnUserJoined(object sender, OnUserJoinedArgs e)
        {
            if (!Measurables.allViewers.Contains(e.Username))
            {
                Measurables.allViewers.Add(e.Username);
            }
            Measurables.currentViewers.Add(e.Username);
            Measurables.viewerCount++;
            int Id        = Convert.ToInt32(TwitchHelpers.GetUserId(e.Username));
            var newViewer = Context.ViewerStats.Where(v => v.TwitchID == Id).FirstOrDefault();

            if (newViewer == null)
            {
                NewViewerConfig newViewerConfig = new NewViewerConfig();
                Context.ViewerStats.Add(newViewerConfig.initViewer(e.Username, Id.ToString()));
                Context.SaveChanges();
            }
        }
Exemplo n.º 3
0
        private void PubSub_OnFollow(object sender, TwitchLib.PubSub.Events.OnFollowArgs e)
        {
            Measurables.newFollowers.Add(e.Username);

            int Id          = Convert.ToInt32(e.UserId);
            var newFollower = Context.ViewerStats.Where(v => v.TwitchID == Id).FirstOrDefault();

            if (newFollower == null)
            {
                NewViewerConfig newViewerConfig = new NewViewerConfig();
                Context.ViewerStats.Add(newViewerConfig.initViewer(e.Username, Id.ToString()));
                Context.SaveChanges();
            }
            else
            {
                newFollower.FirstFollowed = DateTime.Now.ToString();
            }
            Context.SaveChanges();

            client.SendMessage(JoinedChannel.Channel, string.Format("Thanks for the follow, {0}!", e.Username));
        }