Exemple #1
0
        public override object CommandHandler(SocketMessage socketMessage, string input, CommandArguments arguments)
        {
            if (string.IsNullOrEmpty(input) || input.Length <= 3)
            {
                return("Please enter a username to connect to");
            }

            OsuUser osuUser = OsuApi.GetUser(input);

            if (osuUser == null)
            {
                return("Unable to find any user with this username");
            }

            InternalUser internalUser = DatabaseManager.Instance.GetUser(socketMessage.Author.Id);

            if (string.IsNullOrEmpty(internalUser.OsuUserID))
            {
                internalUser.OsuUserID = osuUser.ID.ToString();
                return("Registered '" + osuUser.Name + "' to your profile, " + socketMessage.Author.Mention);
            }
            else
            {
                internalUser.OsuUserID = osuUser.ID.ToString();
                return("Changed connection to '" + osuUser.Name + "' on your profile, " + socketMessage.Author.Mention);
            }
        }
        //Prepare a new session
        public void PrepareSession(Session session = null)
        {
            SessionThread?.Join();

            if (session == null)
            {
                CurrentSession = new Session
                {
                    Username = SettingsManager.Instance.Settings["api"]["user"]
                };
            }
            else
            {
                CurrentSession = session;
            }

            if (CurrentSession.ReadOnly)
            {
                OsuUser currentUserData = null;
                try
                {
                    currentUserData = OsuApi.GetUser(CurrentSession.Username, (OsuMode)Enum.Parse(typeof(OsuMode), SettingsManager.Instance.Settings["api"]["gamemode"]));
                }
                catch (Exception)
                {
                    BrowserViewModel.Instance.SendNotification(NotificationType.Danger, StringStorage.Get("Message.UserDataError"));
                    return;
                }
                BrowserViewModel.Instance.ApplySession(CurrentSession);
                BrowserViewModel.Instance.ApplyUser(currentUserData);

                StopProgressHandler();
                BrowserViewModel.Instance.AttachedJavascriptWrapper.Hide("#sessionProgressTime");
                BrowserViewModel.Instance.AttachedJavascriptWrapper.Show("#sessionProgressReadonly");

                string startDate = DateTimeOffset.FromUnixTimeSeconds(CurrentSession.SessionDate).ToString("MMMM dd yyyy HH:mm:ss");
                string endDate   = DateTimeOffset.FromUnixTimeSeconds(CurrentSession.SessionEndDate).ToString("MMMM dd yyyy HH:mm:ss");

                BrowserViewModel.Instance.AttachedJavascriptWrapper.SetHtml("#sessionProgressReadonlyText", startDate + " to " + endDate);
            }
            else
            {
                SessionThread = new ExtendedThread(() => OnUpdate(), Convert.ToInt32(SettingsManager.Instance.Settings["api"]["updateRate"]));

                lastIteration = DateTimeOffset.Now.ToUnixTimeSeconds();
                nextIteration = DateTimeOffset.Now.ToUnixTimeSeconds() + SessionThread.SleepTime;

                StartProgressHandler();
                SessionThread.Start();

                BrowserViewModel.Instance.AttachedJavascriptWrapper.Hide("#sessionProgressReadonly");

                if (SettingsManager.Instance.Settings["display"]["showTimer"] == "true")
                {
                    BrowserViewModel.Instance.AttachedJavascriptWrapper.Show("#sessionProgressTime");
                }
            }
        }
        protected void ApplyPlayer(ulong DiscordID, string input)
        {
            _osuUser = null;
            if (string.IsNullOrEmpty(input))
            {
                InternalUser internalUser = DatabaseManager.Instance.GetUser(DiscordID);
                if (!string.IsNullOrEmpty(internalUser.OsuUserID))
                {
                    _osuUser = OsuApi.GetUser(internalUser.OsuUserID, _osuMode);
                }
            }

            if (_osuUser == null)
            {
                string username = HttpUtility.HtmlEncode(input); // Test value
                _osuUser = OsuApi.GetUser(username, _osuMode);
            }
        }
        private void OnUpdate()
        {
            if (!NetworkManager.Instance.HasConnection())
            {
                BrowserViewModel.Instance.SendNotification(NotificationType.Warning, StringStorage.Get("Message.NoInternet"));
                return;
            }

            //BrowserViewModel.Instance.SendNotification(NotificationType.Success, "Test: session iteration");
            OsuUser currentUserData = null;

            try
            {
                currentUserData = OsuApi.GetUser(CurrentSession.Username, (OsuMode)Enum.Parse(typeof(OsuMode), SettingsManager.Instance.Settings["api"]["gamemode"]));
            }
            catch (Exception)
            {
                BrowserViewModel.Instance.SendNotification(NotificationType.Danger, StringStorage.Get("Message.UserDataError"));
            }

            if (currentUserData != null)
            {
                if (CurrentSession.InitialData == null)
                {
                    CurrentSession.InitialData = SessionData.FromUser(currentUserData);
                }

                CurrentSession.CurrentData    = SessionData.FromUser(currentUserData);
                CurrentSession.DifferenceData = CurrentSession.CurrentData - CurrentSession.InitialData;

                BrowserViewModel.Instance.ApplySession(CurrentSession);
                BrowserViewModel.Instance.ApplyUser(currentUserData);

                int updateRate = Convert.ToInt32(SettingsManager.Instance.Settings["api"]["updateRate"]);
                if (updateRate != SessionThread.SleepTime)
                {
                    SessionThread.SleepTime = updateRate;
                }
            }

            lastIteration = DateTimeOffset.Now.ToUnixTimeSeconds();
            nextIteration = DateTimeOffset.Now.ToUnixTimeSeconds() + SessionThread.SleepTime;
        }
Exemple #5
0
 public OsuUser FindUser(string query)
 {
     return(OsuApi.GetUser(query));
 }