Exemple #1
0
    void TryOnJoinedRoomAct(OnOffline ooline)
    {
        if (ooline != OnOffline.Online)
        {
            Debug.Log($"[TokenHandler] TryOnJoinedRoomAct NotInOnlineRoom");
            return;
        }

        OnJoinedOnlineRoomAct();
    }
Exemple #2
0
    public bool IsInRoom(OnOffline ooline = OnOffline.Any, string requestedRoomName = "")
    {
        if (!PhotonNetwork.InRoom)
        {
            Debug.LogWarning($"{scriptName} IsInRoom NotInRoom");
            return(false);
        }

        if (!string.IsNullOrWhiteSpace(requestedRoomName) && PhotonNetwork.CurrentRoom.Name != requestedRoomName)
        {
            Debug.LogWarning($"{scriptName} IsInRoom NotInSpecificSoom:{requestedRoomName}");
            return(false);
        }

        switch (ooline)
        {
        case OnOffline.Offline:
            if (!PhotonNetwork.OfflineMode)
            {
                Debug.LogWarning($"{scriptName} IsInRoom NotOffline");
                return(false);
            }
            break;

        case OnOffline.Online:
            if (PhotonNetwork.OfflineMode)
            {
                Debug.LogWarning($"{scriptName} IsInRoom NotOnline");
                return(false);
            }
            break;

        case OnOffline.Any:
        default:
            break;
        }

        return(true);
    }
Exemple #3
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));
            }
        }
Exemple #4
0
 //处理掉线、强制登出
 private static void HandleOffiline(ResultHead head)
 {
     SetStatus(ClientStatus.Stopped);
     OnOffline?.Invoke(head);
 }
        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));
            }
        }