Exemple #1
0
        /// <summary>
        /// Executes the specified command asynchronously.
        /// </summary>
        /// <param name="c">The command argument information.</param>
        /// <returns><c>true</c> if the command was successfully executed, otherwise <c>false</c>.</returns>
        /// <remarks>Helpers.GetArgVal(c, 1) if specified: user to check</remarks>
        public async Task <bool> ExecAsync(Cmd c)
        {
            // DB
            var date = _registrationDb.GetRegistrationDate(Helpers.GetArgVal(c, 1));

            if (date == default(DateTime))
            {
                // Not in DB, so retrieve from QL website
                var qlDateChecker = new QlAccountDateChecker();
                date = await qlDateChecker.GetUserRegistrationDate(Helpers.GetArgVal(c, 1));
            }
            // Display
            if (date == default(DateTime))
            {
                StatusMessage = string.Format(
                    "^1[ERROR]^7 Unable to retrieve {0}'s account registration date.",
                    Helpers.GetArgVal(c, 1));
                await SendServerTell(c, StatusMessage);

                Log.Write(string.Format("Could not retrieve account registration date for player {0}",
                                        Helpers.GetArgVal(c, 1)), _logClassType, _logPrefix);

                return(false);
            }
            var daysAgo = Math.Truncate((DateTime.Now - date).TotalDays * 100) / 100;

            StatusMessage = string.Format(
                "^5[DATE]^7 {0}'s account was registered on:^5 {1}^7 (^3{2} ^7days old)",
                Helpers.GetArgVal(c, 1), date.ToString("d"), daysAgo);
            await SendServerSay(c, StatusMessage);

            return(true);
        }
Exemple #2
0
        /// <summary>
        /// Gets the user's registration date.
        /// </summary>
        /// <param name="user">The user.</param>
        /// <returns>The user's registration date as a DateTime object.</returns>
        public async Task <DateTime> GetUserRegistrationDate(string user)
        {
            // See if the user already exists in internal database
            var registeredDate = _regDateDb.GetRegistrationDate(user);

            if (registeredDate != default(DateTime))
            {
                return(registeredDate);
            }

            // User doesn't exist in our db, retrieve from QL.
            registeredDate = await GetUserRegistrationDateFromQl(user);

            if (registeredDate != default(DateTime))
            {
                _regDateDb.AddUserToDb(user, registeredDate);
            }
            return(registeredDate);
        }