示例#1
0
        public void AddGraphValue(int value)
        {
            double dateValue = OxyPlot.Axes.DateTimeAxis.ToDouble(DateTime.Today);

            if (MessageGraph == null)
            {
                MessageGraph = new DatePlot(Id + "MessageGraph", "Date", "Characters sent", "dd-MMM", false);
                MessageGraph.AddValue("Value", 0, DateTime.Today.AddDays(-1));
                MessageGraph.AddValue("Value", 0, DateTime.Today.AddMilliseconds(-1));
                MessageGraph.AddValue("Value", value, DateTime.Today);
            }

            else
            {
                if (MessageGraph.PlotDataPoints.Last().Value.Key < dateValue)
                {
                    //Finalize block of the last date captured
                    var endOfLastDay = OxyPlot.Axes.DateTimeAxis.ToDouble(OxyPlot.Axes.DateTimeAxis.ToDateTime(MessageGraph.PlotDataPoints.Last().Value.Key).AddDays(1).AddMilliseconds(-2));
                    MessageGraph.PlotDataPoints.Add(new KeyValuePair <string, KeyValuePair <double, double> >("Value", new KeyValuePair <double, double>(endOfLastDay, MessageGraph.PlotDataPoints.Last().Value.Value)));
                    MessageGraph.PlotDataPoints.Add(new KeyValuePair <string, KeyValuePair <double, double> >("Value", new KeyValuePair <double, double>(endOfLastDay, 0)));

                    //Start new block for today
                    var startOfToday = OxyPlot.Axes.DateTimeAxis.ToDouble(DateTime.Today.AddMilliseconds(-1));
                    MessageGraph.PlotDataPoints.Add(new KeyValuePair <string, KeyValuePair <double, double> >("Value", new KeyValuePair <double, double>(startOfToday, 0)));
                    MessageGraph.PlotDataPoints.Add(new KeyValuePair <string, KeyValuePair <double, double> >("Value", new KeyValuePair <double, double>(dateValue, value)));
                }
                else
                {
                    MessageGraph.PlotDataPoints[MessageGraph.PlotDataPoints.Count - 1] = new KeyValuePair <string, KeyValuePair <double, double> >("Value", new KeyValuePair <double, double>(dateValue, MessageGraph.PlotDataPoints.Last().Value.Value + value));
                }
            }
        }
示例#2
0
        public void AddGraphValue(int value)
        {
            double dateValue = OxyPlot.Axes.DateTimeAxis.ToDouble(DateTime.Today);

            if (ActivityGraph == null)
            {
                ActivityGraph = new DatePlot(Id + "ExperienceGraph", "Date", "Characters sent", "dd-MMM", false);
                ActivityGraph.AddValue("Value", 0, DateTime.Today.AddDays(-1));
                ActivityGraph.AddValue("Value", 0, DateTime.Today.AddMilliseconds(-1));
                ActivityGraph.AddValue("Value", value, DateTime.Today);
            }

            else
            {
                if (ActivityGraph.PlotDataPoints.Last().Value.Key < dateValue)
                {
                    //Only show past year
                    ActivityGraph.PlotDataPoints = ActivityGraph.PlotDataPoints.SkipWhile(x => (DateTime.Today - OxyPlot.Axes.DateTimeAxis.ToDateTime(x.Value.Key)).Days >= 365).ToList();

                    //Finalize block of the last date captured
                    var endOfLastDay = OxyPlot.Axes.DateTimeAxis.ToDouble(OxyPlot.Axes.DateTimeAxis.ToDateTime(ActivityGraph.PlotDataPoints.Last().Value.Key).AddDays(1).AddMilliseconds(-2));
                    ActivityGraph.PlotDataPoints.Add(new KeyValuePair <string, KeyValuePair <double, double> >("Value", new KeyValuePair <double, double>(endOfLastDay, ActivityGraph.PlotDataPoints.Last().Value.Value)));
                    ActivityGraph.PlotDataPoints.Add(new KeyValuePair <string, KeyValuePair <double, double> >("Value", new KeyValuePair <double, double>(endOfLastDay, 0)));

                    //Start new block for today
                    var startOfToday = OxyPlot.Axes.DateTimeAxis.ToDouble(DateTime.Today.AddMilliseconds(-1));
                    ActivityGraph.PlotDataPoints.Add(new KeyValuePair <string, KeyValuePair <double, double> >("Value", new KeyValuePair <double, double>(startOfToday, 0)));
                    ActivityGraph.PlotDataPoints.Add(new KeyValuePair <string, KeyValuePair <double, double> >("Value", new KeyValuePair <double, double>(dateValue, value)));
                }
                else
                {
                    ActivityGraph.PlotDataPoints[ActivityGraph.PlotDataPoints.Count - 1] = new KeyValuePair <string, KeyValuePair <double, double> >("Value", new KeyValuePair <double, double>(dateValue, ActivityGraph.PlotDataPoints.Last().Value.Value + value));
                }
            }
        }
示例#3
0
 public override void Dispose()
 {
     base.Dispose(true);
     GC.SuppressFinalize(this);
     ViewerGraph?.Dispose();
     ViewerGraph = null;
     SubscribeWebhookAsync(false).Wait();
 }
示例#4
0
 public void InitPlot()
 {
     if (MessageGraph == null)
     {
         MessageGraph = new DatePlot(Id + "MessageGraph", "Date", "Characters sent", "dd-MMM", false);
     }
     else
     {
         MessageGraph.InitPlot("Date", "Characters sent", "dd-MMM", false);
     }
 }
示例#5
0
 public void InitPlot()
 {
     if (ActivityGraph == null)
     {
         ActivityGraph = new DatePlot(Id + "ExperienceGraph", "Date", "Characters sent", "dd-MMM", false);
     }
     else
     {
         ActivityGraph.InitPlot("Date", "Characters sent", "dd-MMM", false);
     }
 }
示例#6
0
        protected async override void CheckForChange_Elapsed(object stateinfo)
        {
            try
            {
                var match = await fetchData();

                if (!string.IsNullOrEmpty(match))
                {
                    bool isNumeric;

                    if (oldMatch == null)
                    {
                        oldMatch = match;
                        await UpdateTracker();
                    }

                    if ((isNumeric = Double.TryParse(oldMatch, out double value)) && DataGraph == null)
                    {
                        DataGraph = new DatePlot("HTML" + Name.GetHashCode(), "Date", "Value", "dd-MMM", false);
                        DataGraph.AddValue("Value", value, relative: false);
                    }

                    if (!match.Equals(oldMatch))
                    {
                        if (isNumeric)
                        {
                            DataGraph.AddValue("Value", value, relative: false);
                            var success = Double.TryParse(match, out value);
                            if (success)
                            {
                                DataGraph.AddValue("Value", value, relative: false);
                            }
                        }

                        foreach (var channel in ChannelConfig.Keys.ToList())
                        {
                            await OnMajorChangeTracked(channel, CreateChangeEmbed($"{oldMatch} -> {match}", isNumeric), (string)ChannelConfig[channel]["Notification"]);
                        }

                        oldMatch = match;
                        await UpdateTracker();
                    }
                }
            }
            catch (Exception e)
            {
                await Program.MopsLog(new LogMessage(LogSeverity.Error, "", $" error by {Name}", e));
            }
        }
示例#7
0
        public JSONTracker(string name) : base()
        {
            //name = name.Replace(" ", string.Empty);
            Name    = name;
            ToTrack = name.Split("|||")[1].Split("\n").ToList();

            //Check if name yields proper results.
            try
            {
                PastInformation = getResults().Result;
                var graphMembers = PastInformation.Where(x => x.Key.Contains("graph:"));
                foreach (var graphTest in graphMembers)
                {
                    if (!graphTest.Equals(default(KeyValuePair <string, string>)))
                    {
                        bool succeeded = double.TryParse(graphTest.Value, out double test);

                        if (succeeded)
                        {
                            var chosenName = graphTest.Key.Contains("as:") ? graphTest.Key.Split(":").Last() : graphTest.Key;
                            if (DataGraph == null)
                            {
                                DataGraph = new DatePlot("JSON" + Name.GetHashCode(), "Date", "Value", format: "dd-MMM", relativeTime: false, multipleLines: true);
                            }
                            DataGraph.AddValueSeperate(chosenName, test, relative: false);
                        }

                        else
                        {
                            throw new Exception("Graph value is not a number!");
                        }
                    }
                }
                SetTimer();
            }
            catch (Exception e)
            {
                Dispose();
                throw new Exception($"{Name} could not be resolved, using the given paths.", e);
            }
        }
        protected async override void CheckForChange_Elapsed(object stateinfo)
        {
            try
            {
                if (VideoId == null)
                {
                    VideoId = await scrapeLivestreamId(Name);

                    //Not live
                    if (VideoId == null)
                    {
                        return;
                    }

                    //New livestream
                    else
                    {
                        ViewerGraph = new DatePlot(Name, "Time since start", "Viewers");
                        liveStatus  = await fetchLiveVideoContent();

                        ViewerGraph.AddValue("Viewers", 0, liveStatus.liveStreamingDetails.actualStartTime);

                        foreach (ulong channel in ChannelConfig.Keys.Where(x => (bool)ChannelConfig[x][ONLINE]).ToList())
                        {
                            await OnMinorChangeTracked(channel, (string)ChannelConfig[channel]["Notification"]);
                        }

                        SetTimer(60000, 60000);

                        IconUrl = (await fetchChannel()).snippet.thumbnails.medium.url;
                    }
                }

                liveStatus = await fetchLiveVideoContent();

                bool isStreaming = liveStatus?.snippet?.liveBroadcastContent?.Equals("live") ?? false;

                if (!isStreaming)
                {
                    VideoId = null;
                    SetTimer(600000);
                    ViewerGraph.Dispose();
                    ViewerGraph = null;

                    foreach (var channelMessage in ToUpdate)
                    {
                        await Program.ReactionHandler.ClearHandler((IUserMessage)await ((ITextChannel)Program.Client.GetChannel(channelMessage.Key)).GetMessageAsync(channelMessage.Value));
                    }

                    ToUpdate = new Dictionary <ulong, ulong>();

                    foreach (ulong channel in ChannelConfig.Keys.Where(x => (bool)ChannelConfig[x][OFFLINE]).ToList())
                    {
                        await OnMinorChangeTracked(channel, $"{liveStatus.snippet.channelTitle} went Offline!");
                    }
                }
                else
                {
                    ViewerGraph.AddValue("Viewers", double.Parse(liveStatus.liveStreamingDetails.concurrentViewers));

                    foreach (ulong channel in ChannelConfig.Keys.Where(x => (bool)ChannelConfig[x][SHOWEMBED]).ToList())
                    {
                        await OnMajorChangeTracked(channel, await createEmbed((bool)ChannelConfig[channel][THUMBNAIL], (bool)ChannelConfig[channel][SHOWCHAT]));
                    }
                }

                await UpdateTracker();
            }
            catch (Exception e)
            {
                await Program.MopsLog(new LogMessage(LogSeverity.Error, "", $" error by {Name}", e));
            }
        }
        /// <summary>
        /// Event for the Timer, to check for changed stats
        /// </summary>
        /// <param Name="stateinfo"></param>
        public async override void CheckForChange_Elapsed(object stateinfo)
        {
            try
            {
                OStatsResult newInformation;

                lock (APILock)
                {
                    newInformation = FetchJSONDataAsync <OStatsResult>($"https://owapi.net/api/v3/u/{Name}/blob").Result;
                    Task.Delay(2500).Wait();
                }

                //OWAPI or PlayOverwatch messed up
                if (newInformation.getNotNull() == null)
                {
                    return;
                }

                if (StatGraph == null)
                {
                    StatGraph = new DatePlot(Name, "Date", "Level", "dd-MMM", false);
                    StatGraph.AddValue("Level", await OverallStats.GetLevelAsync(Name));
                    await UpdateTracker();
                }

                if (information == null)
                {
                    information = newInformation;
                }

                if (newInformation == null)
                {
                    return;
                }

                var changedStats = await getChangedStatsAsync(information, newInformation);

                if (changedStats.Count != 0)
                {
                    StatGraph.AddValue("Level", StatGraph.PlotDataPoints.Last().Value.Value);
                    StatGraph.AddValue("Level", await OverallStats.GetLevelAsync(Name));

                    foreach (ulong channel in ChannelConfig.Keys.ToList())
                    {
                        await OnMajorChangeTracked(channel, createEmbed(newInformation, changedStats, getSessionMostPlayed(information.getNotNull().heroes.playtime, newInformation.getNotNull().heroes.playtime)), (string)ChannelConfig[channel]["Notification"]);
                    }

                    information = newInformation;
                    await UpdateTracker();
                }
            }
            catch (Exception e)
            {
                await Program.MopsLog(new LogMessage(LogSeverity.Error, "", $" error by {Name}", e));

                if (e.Message.Contains("TOO MANY REQUESTS"))
                {
                    //var nextElapse = StaticBase.ran.Next(10000, 300000);
                    //checkForChange.Change(nextElapse, 300000);
                    await Program.MopsLog(new LogMessage(LogSeverity.Info, "", $"Trying again next cycle", e));
                }
            }
        }
示例#10
0
        public async Task CheckStreamerInfoAsync()
        {
            try
            {
                StreamerStatus = await streamerInformation();

                bool isStreaming = StreamerStatus.Stream.Channel != null && (StreamerStatus.Stream.BroadcastPlatform.Contains("other") ? ChannelConfig.Any(x => (bool)x.Value[TRACKRERUN]) : true);
                bool isRerun     = StreamerStatus.Stream?.BroadcastPlatform?.Contains("other") ?? false;

                if (!timerChanged && !IsOnline && (WebhookExpire - DateTime.Now).TotalMinutes >= 60)
                {
                    //SetTimer(3600000, StaticBase.ran.Next(5000, 3600000));
                    timerChanged = true;
                }

                if (IsOnline != isStreaming)
                {
                    if (IsOnline)
                    {
                        if (++TimeoutCount >= 3)
                        {
                            TimeoutCount = 0;
                            IsOnline     = false;

                            try
                            {
                                var pdf = ViewerGraph.DrawPlot(true, $"{Name}-{DateTime.UtcNow.ToString("MM-dd-yy_hh-mm")}");
                                foreach (ulong channel in ChannelConfig.Keys.Where(x => (bool)ChannelConfig[x][SENDPDF]).ToList())
                                {
                                    await(Program.Client.GetChannel(channel) as SocketTextChannel)?.SendFileAsync(pdf, "Graph PDF for personal use:");
                                }
                                File.Delete(pdf);
                            }
                            catch (Exception e)
                            {
                                await Program.MopsLog(new LogMessage(LogSeverity.Error, "", $" error sending graph by {Name}", e));
                            }

                            ViewerGraph?.Dispose();
                            ViewerGraph = null;
                            VodUrl      = null;

                            foreach (var channelMessage in ToUpdate)
                            {
                                await Program.ReactionHandler.ClearHandler((IUserMessage)await ((ITextChannel)Program.Client.GetChannel(channelMessage.Key)).GetMessageAsync(channelMessage.Value));
                            }

                            ToUpdate    = new Dictionary <ulong, ulong>();
                            GameChanges = new List <Tuple <string, DateTime> >();

                            if (OnOffline != null)
                            {
                                await OnOffline.Invoke(this);
                            }
                            foreach (ulong channel in ChannelConfig.Keys.Where(x => (bool)ChannelConfig[x][OFFLINE] && (isRerun ? (bool)ChannelConfig[x][TRACKRERUN] : true)).ToList())
                            {
                                await OnMinorChangeTracked(channel, $"{Name} went Offline!");
                            }

                            //SetTimer(3600000, 3600000);
                        }
                        else if (!IsHosting)
                        {
                            var host = (await hostInformation()).hosts.First();
                            if (host.IsHosting())
                            {
                                if (OnHosting != null)
                                {
                                    await OnHosting.Invoke(host.host_display_name, host.target_display_name, (int)ViewerGraph.PlotDataPoints.LastOrDefault().Value.Value);
                                }

                                foreach (ulong channel in ChannelConfig.Keys.Where(x => (bool)ChannelConfig[x][HOST] && (isRerun ? (bool)ChannelConfig[x][TRACKRERUN] : true)).ToList())
                                {
                                    await OnMinorChangeTracked(channel, $"{Name} is now hosting {host.target_display_name} for {(int)ViewerGraph.PlotDataPoints.LastOrDefault().Value.Value} viewers!");
                                }

                                IsHosting = true;
                            }
                        }
                    }
                    else
                    {
                        ViewerGraph = new DatePlot(Name, "Time since start", "Viewers");
                        IsOnline    = true;
                        IsHosting   = false;
                        CurGame     = StreamerStatus.Stream.Game;
                        ViewerGraph.AddValue(CurGame, 0, StreamerStatus.Stream.CreatedAt.UtcDateTime);
                        GameChanges.Add(Tuple.Create(StreamerStatus.Stream.Game, StreamerStatus.Stream.CreatedAt.UtcDateTime));

                        if (OnLive != null)
                        {
                            await OnLive.Invoke(this);
                        }
                        foreach (ulong channel in ChannelConfig.Keys.Where(x => (bool)ChannelConfig[x][ONLINE] && (isRerun ? (bool)ChannelConfig[x][TRACKRERUN] : true)).ToList())
                        {
                            await OnMinorChangeTracked(channel, (string)ChannelConfig[channel]["Notification"]);
                        }

                        //SetTimer(120000, 120000);
                    }
                    await UpdateTracker();
                }
                else
                {
                    TimeoutCount = 0;
                }

                if (isStreaming)
                {
                    if (VodUrl == null)
                    {
                        VodUrl = await GetVodAsync();
                    }

                    if (CurGame.ToLower().CompareTo(StreamerStatus.Stream.Game.ToLower()) != 0)
                    {
                        CurGame = StreamerStatus.Stream.Game;
                        GameChanges.Add(Tuple.Create(StreamerStatus.Stream.Game, DateTime.UtcNow));
                        await UpdateTracker();

                        foreach (ulong channel in ChannelConfig.Keys.Where(x => (bool)ChannelConfig[x][GAMECHANGE] && (isRerun ? (bool)ChannelConfig[x][TRACKRERUN] : true)).ToList())
                        {
                            await OnMinorChangeTracked(channel, $"{Name} switched games to **{CurGame}**");
                        }
                    }

                    if (ChannelConfig.Any(x => (bool)x.Value[SHOWGRAPH]))
                    {
                        await ModifyAsync(x => x.ViewerGraph.AddValue(CurGame, StreamerStatus.Stream.Viewers));
                    }

                    foreach (ulong channel in ChannelConfig.Keys.Where(x => (bool)ChannelConfig[x][SHOWEMBED] && (isRerun ? (bool)ChannelConfig[x][TRACKRERUN] : true)).ToList())
                    {
                        await OnMajorChangeTracked(channel, createEmbed((bool)ChannelConfig[channel][THUMBNAIL], (bool)ChannelConfig[channel][SHOWCHAT], (bool)ChannelConfig[channel][SHOWVOD], (bool)ChannelConfig[channel][SHOWGRAPH]));
                    }
                }
            }
            catch (Exception e)
            {
                await Program.MopsLog(new LogMessage(LogSeverity.Error, "", $" error by {Name}", e));
            }
        }
示例#11
0
        protected async override void CheckForChange_Elapsed(object stateinfo)
        {
            try
            {
                if (ChannelConfig.Any(x => (bool)x.Value[TRACKLEVEL]))
                {
                    if (PastInformation.character == null)
                    {
                        PastInformation.character = await GetCharacterEndpoint(CharacterName, APIKey);

                        LevelGraph = new DatePlot($"{CharacterName.Replace(" ", "")}Level", "Date", "Level", "dd-MMM", false, true);
                        LevelGraph.AddValueSeperate("Level", PastInformation.character.level, relative: false);
                        LevelGraph.AddValueSeperate("M-Level", PastInformation.character.masteryLevel, relative: false);
                        await UpdateTracker();
                    }

                    else
                    {
                        Character pastInfo    = PastInformation.character;
                        Character currentInfo = await GetCharacterEndpoint(CharacterName, APIKey);

                        if (currentInfo.level != pastInfo.level || currentInfo.masteryLevel != pastInfo.masteryLevel)
                        {
                            LevelGraph.AddValueSeperate("Level", pastInfo.level, relative: false);
                            LevelGraph.AddValueSeperate("M-Level", pastInfo.masteryLevel, relative: false);
                            LevelGraph.AddValueSeperate("Level", currentInfo.level, relative: false);
                            LevelGraph.AddValueSeperate("M-Level", currentInfo.masteryLevel, relative: false);
                            foreach (var channel in ChannelConfig.Where(x => (bool)x.Value[TRACKLEVEL]))
                            {
                                await OnMajorChangeTracked(channel.Key, createLevelEmbed(pastInfo, currentInfo));
                            }

                            PastInformation.character = currentInfo;
                            await UpdateTracker();
                        }
                    }
                }

                if (ChannelConfig.Any(x => (bool)x.Value[TRACKACHIEVEMENTS]))
                {
                    //ToDo
                }

                if (ChannelConfig.Any(x => (bool)x.Value[TRACKWEALTH]))
                {
                    if (PastInformation.wallet == null)
                    {
                        PastInformation.wallet = (await GetWealth(APIKey)).FirstOrDefault();
                        MoneyGraph             = new DatePlot($"{CharacterName.Replace(" ", "")}Gold", "Date", "Gold", "dd-MMM", false);
                        MoneyGraph.AddValue("Gold", PastInformation.wallet.value, relative: false);
                        await UpdateTracker();
                    }

                    else
                    {
                        Wallet pastInfo    = PastInformation.wallet;
                        Wallet currentInfo = (await GetWealth(APIKey)).FirstOrDefault();

                        if (currentInfo.value != pastInfo.value)
                        {
                            MoneyGraph.AddValue("Gold", pastInfo.value, relative: false);
                            MoneyGraph.AddValue("Gold", currentInfo.value, relative: false);
                            foreach (var channel in ChannelConfig.Where(x => (bool)x.Value[TRACKWEALTH]))
                            {
                                await OnMajorChangeTracked(channel.Key, createWealthEmbed(pastInfo, currentInfo));
                            }

                            PastInformation.wallet = currentInfo;
                            await UpdateTracker();
                        }
                    }
                }

                if (ChannelConfig.Any(x => (bool)x.Value[TRACKTPBUYS]))
                {
                    if (PastInformation.buy == null)
                    {
                        PastInformation.buy = (await GetTPBuys(APIKey)).FirstOrDefault();
                        await UpdateTracker();
                    }

                    else
                    {
                        TPTransaction        pastInfo    = PastInformation.buy;
                        List <TPTransaction> currentInfo = (await GetTPBuys(APIKey)).TakeWhile(x => x.purchased > pastInfo.purchased).ToList();
                        currentInfo.Reverse();

                        foreach (var transaction in currentInfo)
                        {
                            foreach (var channel in ChannelConfig.Where(x => (bool)x.Value[TRACKTPBUYS]))
                            {
                                await OnMajorChangeTracked(channel.Key, await CreateTPBuyEmbed(transaction));
                            }
                        }

                        if (currentInfo.Count > 0)
                        {
                            PastInformation.buy = currentInfo.LastOrDefault();
                            await UpdateTracker();
                        }
                    }
                }

                if (ChannelConfig.Any(x => (bool)x.Value[TRACKTPSELLS]))
                {
                    if (PastInformation.sell == null)
                    {
                        PastInformation.sell = (await GetTPSells(APIKey)).FirstOrDefault();
                        await UpdateTracker();
                    }

                    else
                    {
                        TPTransaction        pastInfo    = PastInformation.sell;
                        List <TPTransaction> currentInfo = (await GetTPSells(APIKey)).TakeWhile(x => x.purchased > pastInfo.purchased).ToList();
                        currentInfo.Reverse();

                        foreach (var transaction in currentInfo)
                        {
                            foreach (var channel in ChannelConfig.Where(x => (bool)x.Value[TRACKTPSELLS]))
                            {
                                await OnMajorChangeTracked(channel.Key, await CreateTPSellEmbed(transaction));
                            }
                        }

                        if (currentInfo.Count > 0)
                        {
                            PastInformation.sell = currentInfo.LastOrDefault();
                            await UpdateTracker();
                        }
                    }
                }

                if (ChannelConfig.Any(x => (bool)x.Value[TRACKTPDELIVERY]))
                {
                    if (PastInformation.delivery == null)
                    {
                        PastInformation.delivery = await GetTPInbox(APIKey);
                        await UpdateTracker();
                    }

                    else
                    {
                        TPInbox pastInfo    = PastInformation.delivery;
                        TPInbox currentInfo = await GetTPInbox(APIKey);

                        if (currentInfo.items.Count != pastInfo.items.Count || currentInfo.coins != pastInfo.coins)
                        {
                            foreach (var channel in ChannelConfig.Where(x => (bool)x.Value[TRACKTPDELIVERY]))
                            {
                                await OnMajorChangeTracked(channel.Key, CreateTPInboxEmbed(pastInfo, currentInfo));
                            }

                            PastInformation.delivery = currentInfo;
                            await UpdateTracker();
                        }
                    }
                }

                if (ChannelConfig.Any(x => (bool)x.Value[TRACKEQUIPMENT]))
                {
                }
            }
            catch (Exception e)
            {
                await Program.MopsLog(new LogMessage(LogSeverity.Error, "", $" error by {Name}", e));
            }
        }
示例#12
0
        public async Task CheckStreamerInfoAsync()
        {
            try
            {
                StreamerStatus = await streamerInformation();

                bool isStreaming = StreamerStatus.online;

                if (IsOnline != isStreaming)
                {
                    if (IsOnline)
                    {
                        if (++TimeoutCount >= 3)
                        {
                            TimeoutCount = 0;
                            IsOnline     = false;

                            ViewerGraph?.Dispose();
                            ViewerGraph = null;

                            ToUpdate    = new Dictionary <ulong, ulong>();
                            GameChanges = new List <Tuple <string, DateTime> >();

                            if (OnOffline != null)
                            {
                                await OnOffline.Invoke(this);
                            }
                            foreach (ulong channel in ChannelConfig.Keys.Where(x => (bool)ChannelConfig[x][OFFLINE]).ToList())
                            {
                                await OnMinorChangeTracked(channel, $"{Name} went Offline!");
                            }

                            //SetTimer(600000, 600000);
                        }
                    }
                    else
                    {
                        ViewerGraph = new DatePlot(Name + "Mixer", "Time since start", "Viewers");
                        IsOnline    = true;
                        CurGame     = StreamerStatus.type?.name ?? "Nothing";
                        GameChanges.Add(Tuple.Create(CurGame, DateTime.UtcNow));
                        ViewerGraph.AddValue(CurGame, 0, (await GetBroadcastStartTime()).AddHours(-2));

                        if (OnLive != null)
                        {
                            await OnLive.Invoke(this);
                        }
                        foreach (ulong channel in ChannelConfig.Keys.Where(x => (bool)ChannelConfig[x][ONLINE]).ToList())
                        {
                            await OnMinorChangeTracked(channel, (string)ChannelConfig[channel]["Notification"]);
                        }

                        //SetTimer(60000, 60000);
                    }
                    await UpdateTracker();
                }
                else
                {
                    TimeoutCount = 0;
                }

                if (isStreaming)
                {
                    if (CurGame.CompareTo(StreamerStatus.type?.name ?? "Nothing") != 0)
                    {
                        CurGame = StreamerStatus.type?.name ?? "Nothing";
                        GameChanges.Add(Tuple.Create(CurGame, DateTime.UtcNow));
                        await UpdateTracker();

                        foreach (ulong channel in ChannelConfig.Keys.Where(x => (bool)ChannelConfig[x][GAMECHANGE]).ToList())
                        {
                            await OnMinorChangeTracked(channel, $"{Name} switched games to **{CurGame}**");
                        }
                    }

                    if (ChannelConfig.Any(x => (bool)x.Value[SHOWGRAPH]))
                    {
                        await ModifyAsync(x => x.ViewerGraph.AddValue(CurGame, StreamerStatus.viewersCurrent));
                    }

                    foreach (ulong channel in ChannelConfig.Keys.Where(x => (bool)ChannelConfig[x][SHOWEMBED]).ToList())
                    {
                        await OnMajorChangeTracked(channel, createEmbed(StreamerStatus, (bool)ChannelConfig[channel][THUMBNAIL], (bool)ChannelConfig[channel][SHOWTIMESTAMPS], (bool)ChannelConfig[channel][SHOWGRAPH]));
                    }
                }
            }
            catch (Exception e)
            {
                await Program.MopsLog(new LogMessage(LogSeverity.Error, "", $" error by {Name}", e));
            }
        }
示例#13
0
        public async override void CheckForChange_Elapsed(object stateinfo)
        {
            try
            {
                var newInformation = await getResults();

                if (PastInformation == null)
                {
                    PastInformation = newInformation;
                }

                var embed = createEmbed(newInformation, PastInformation, out bool changed);
                if (changed)
                {
                    var graphMembers = newInformation.Where(x => x.Key.Contains("graph:"));

                    foreach (var graphValue in graphMembers)
                    {
                        if (DataGraph == null)
                        {
                            foreach (var graphTest in graphMembers)
                            {
                                if (!graphTest.Equals(default(KeyValuePair <string, string>)))
                                {
                                    bool succeeded = double.TryParse(graphTest.Value, out double test);
                                    var  format    = graphTest.Key.Split("->").First().Split(":").First();
                                    if (format.Contains("graph"))
                                    {
                                        format = "dd-MMM|false";
                                    }
                                    var relative = Boolean.Parse(format.Split("|").Last());
                                    if (succeeded)
                                    {
                                        var chosenName = graphTest.Key.Contains("as:") ? graphTest.Key.Split(":").Last() : graphTest.Key;
                                        if (DataGraph == null)
                                        {
                                            DataGraph = new DatePlot("JSON" + Name.GetHashCode(), "Date", "Value", format: format.Split("|").First(), relativeTime: relative, multipleLines: true);
                                        }
                                    }

                                    else
                                    {
                                        throw new Exception("Graph value is not a number!");
                                    }
                                }
                            }
                        }
                        var name = graphValue.Key.Contains("as:") ? graphValue.Key.Split(":").Last() : graphValue.Key;
                        if (!graphValue.Equals(default(KeyValuePair <string, string>)))
                        {
                            DataGraph.AddValueSeperate(name, double.Parse(PastInformation[graphValue.Key]));
                            DataGraph.AddValueSeperate(name, double.Parse(graphValue.Value));
                        }
                    }

                    foreach (var channel in ChannelConfig.Keys.ToList())
                    {
                        await OnMajorChangeTracked(channel, DataGraph == null?embed : createEmbed(newInformation, PastInformation, out changed), (string)ChannelConfig[channel]["Notification"]);
                    }
                    if (!ChannelConfig.Any(x => (bool)x.Value[UPDATEUNTILNULL]))
                    {
                        ToUpdate = new Dictionary <ulong, ulong>();
                    }

                    PastInformation = newInformation;
                    await UpdateTracker();
                }
            }
            catch (Exception e)
            {
                if (ChannelConfig.Any(x => (bool)x.Value[UPDATEUNTILNULL]) && e.Message.Contains("access child value"))
                {
                    ToUpdate  = new Dictionary <ulong, ulong>();
                    DataGraph = null;
                    await UpdateTracker();
                }
                await Program.MopsLog(new LogMessage(LogSeverity.Error, "", $" error by {Name}", e));
            }
        }
示例#14
0
        public async override void CheckForChange_Elapsed(object stateinfo)
        {
            try
            {
                if (VideoId == null)
                {
                    VideoId = await scrapeLivestreamId(Name);

                    //Not live
                    if (VideoId == null)
                    {
                        return;
                    }

                    //New livestream
                    else
                    {
                        while (StreamInfo == null)
                        {
                            await Task.Delay(60000);
                        }

                        ViewerGraph = new DatePlot(Name, "Time since start", "Viewers");

                        ViewerGraph.AddValue("Viewers", 0, StreamInfo.liveStreamingDetails.actualStartTime);

                        foreach (ulong channel in ChannelConfig.Keys.Where(x => (bool)ChannelConfig[x][ONLINE]).ToList())
                        {
                            await OnMinorChangeTracked(channel, (string)ChannelConfig[channel]["Notification"]);
                        }

                        //SetTimer(120000, 120000);

                        IconUrl = (await fetchChannel()).snippet.thumbnails.medium.url;

                        await UpdateTracker();
                    }
                }

                if (StreamInfo == null)
                {
                    await Task.Delay(120000);
                }
                bool isStreaming = StreamInfo?.snippet?.liveBroadcastContent?.Equals("live") ?? false;

                if (!isStreaming)
                {
                    await Program.MopsLog(new LogMessage(LogSeverity.Verbose, "", $"Stream went offline for {Name}, investigate please:\n{(StreamInfo != null ? JsonConvert.SerializeObject(StreamInfo) :  "Was null")}"));

                    VideoId = null;
                    //SetTimer(900000);
                    try{
                        if (ChannelConfig.Any(x => (bool)x.Value[SENDGRAPH]))
                        {
                            var png = ViewerGraph.DrawPlot(false, $"{Name}-{DateTime.UtcNow.ToString("MM-dd-yy_hh-mm")}", true);
                            foreach (ulong channel in ChannelConfig.Keys.Where(x => (bool)ChannelConfig[x][SENDGRAPH]).ToList())
                            {
                                await(Program.Client.GetChannel(channel) as SocketTextChannel)?.SendFileAsync(png, "Graph for personal use:");
                            }
                            File.Delete(png);
                        }
                    } catch (Exception e) {
                        await Program.MopsLog(new LogMessage(LogSeverity.Error, "", $" error sending graph by {Name}", e));
                    }

                    ViewerGraph?.Dispose();
                    ViewerGraph = null;

                    ToUpdate = new Dictionary <ulong, ulong>();

                    foreach (ulong channel in ChannelConfig.Keys.Where(x => (bool)ChannelConfig[x][OFFLINE]).ToList())
                    {
                        await OnMinorChangeTracked(channel, $"{StreamInfo?.snippet?.channelTitle ?? "Streamer"} went Offline!");
                    }

                    StreamInfo = null;

                    await UpdateTracker();
                }
                else
                {
                    if (ChannelConfig.Any(x => (bool)x.Value[SHOWGRAPH]))
                    {
                        if (StreamInfo.liveStreamingDetails?.concurrentViewers != null)
                        {
                            ViewerGraph.AddValue("Viewers", double.Parse(StreamInfo.liveStreamingDetails.concurrentViewers));
                        }
                        else
                        {
                            ViewerGraph.AddValue("Viewers", 0);
                        }
                        await UpdateTracker();
                    }

                    foreach (ulong channel in ChannelConfig.Keys.Where(x => (bool)ChannelConfig[x][SHOWEMBED]).ToList())
                    {
                        await OnMajorChangeTracked(channel, await createEmbed((bool)ChannelConfig[channel][THUMBNAIL], (bool)ChannelConfig[channel][SHOWCHAT], (bool)ChannelConfig[channel][SHOWGRAPH]));
                    }
                }
            }
            catch (Exception e)
            {
                await Program.MopsLog(new LogMessage(LogSeverity.Error, "", $" error by {Name}", e));
            }
        }