Exemplo n.º 1
0
        public async Task<MojangProfileModel> GetMojangProfileModel(string username)
        {
            var profileModel = new MojangProfileModel { Name = username };

            // Username is taken
            var profile = await GetProfile(username);
            if (profile != null)
            {
                profileModel.Id = profile.Id;
                return profileModel;
            }

            // Username not created
            profile = await GetProfileInitial(username);
            if (profile?.Id == null)
            {
                return profileModel;
            }

            // Username is or will be available
            var profileHistory = await GetMostRecentUsedUsernameProfile(profile, username);
            var usernameChangedAt = GetLastTimeUsernameChangedTime(profileHistory, username);

            profileModel.AvailableSince = usernameChangedAt.GetUsernameAvailableSince();
            profileModel.AvailableIn = GetUsernameAvailableIn((DateTime)profileModel.AvailableSince);

            return profileModel;
        }
Exemplo n.º 2
0
        public bool SendNotificationEmail(UserDto user, MojangProfileModel model, NotificationDto notification)
        {
            var username = model.Name;

            try
            {
                string availableBody;
                string subject;

                switch (notification.Type)
                {
                    case NotificationType.AvailableSoon:
                        availableBody = $"Username '{username}' will be available in {model.AvailableIn}.\n" +
                                        $"We will notify you again if username will be released on {model.AvailableSince.Value.Subtract(TimeSpan.FromDays(7))} (UTC).";
                        subject = $"{username} will be available soon!";
                        break;
                    case NotificationType.ReleasedSoon:
                        availableBody = $"Username '{username}' will be released in {model.AvailableIn}.\n" +
                                        $"We will notify you again on {model.AvailableSince} (UTC).";
                        subject = $"{username} will be released soon!";
                        break;
                    case NotificationType.Available:
                        availableBody =
                            $"Username '{username}' is now available! Change now on https://account.mojang.com/";
                        subject = $"{username} is now available!";
                        break;
                    default:
                        throw new ArgumentOutOfRangeException();
                }

                var body = "Hi!\n" +
                           "\n" +
                           "MCNotifier is happy to notify you about some changes in your watchlist.\n" +
                           $"{availableBody}\n" +
                           "\n" +
                           "Regards,\n" +
                           "The MCNotifier Team.";

                var message = BuildMessage(user.Email, subject, body);
                SendEmail(message);
                notification.LastStatus = true;
            }
            catch (Exception e)
            {
                //log me
                notification.Retries--;
                return false;
            }
            finally
            {
                notification.Modified = DateTime.UtcNow;
            }

            return true;
        }
Exemplo n.º 3
0
 public UsernameDto MapFromMojangProfileModel(MojangProfileModel model)
 {
     return _mapper.Map<UsernameDto>(model);
 }