Beispiel #1
0
        private void RedeliverOverdue()
        {
            DateTime now      = DateTime.UtcNow;
            DateTime deadline = now - RedeliverInterval;
            var      warnings = new List <UnconfirmedDelivery>();

            foreach (
                var entry in _unconfirmed.Where(e => e.Value.Timestamp <= deadline).Take(RedeliveryBurstLimit).ToArray()
                )
            {
                long     deliveryId          = entry.Key;
                Delivery unconfirmedDelivery = entry.Value;

                Send(deliveryId, unconfirmedDelivery, now);

                if (unconfirmedDelivery.Attempt == WarnAfterNumberOfUnconfirmedAttempts)
                {
                    warnings.Add(new UnconfirmedDelivery(deliveryId, unconfirmedDelivery.Destination,
                                                         unconfirmedDelivery.Message));
                }
            }

            if (warnings.Count != 0)
            {
                _context.Self.Tell(new UnconfirmedWarning(warnings.ToArray()));
            }
        }
        private void RedeliverOverdue()
        {
            var now      = DateTime.UtcNow;
            var deadline = now - RedeliverInterval;
            var warnings = new List <UnconfirmedDelivery>();

            // TODO: do we really need to turn this into an array first? Why won't an iterator work
            foreach (
                var entry in _unconfirmed.Where(e => e.Value.Timestamp <= deadline).Take(RedeliveryBurstLimit).ToArray()
                )
            {
                var deliveryId          = entry.Key;
                var unconfirmedDelivery = entry.Value;

                Send(deliveryId, unconfirmedDelivery, now);

                if (unconfirmedDelivery.Attempt == WarnAfterNumberOfUnconfirmedAttempts)
                {
                    warnings.Add(new UnconfirmedDelivery(deliveryId, unconfirmedDelivery.Destination,
                                                         unconfirmedDelivery.Message));
                }
            }

            if (warnings.Count != 0)
            {
                _context.Self.Tell(new UnconfirmedWarning(warnings.ToArray()));
            }
        }
 private ImmutableSortedDictionary <long, IReplicatedData> DeltaEntriesAfter(
     ImmutableSortedDictionary <long, IReplicatedData> entries, long version) =>
 entries.Where(e => e.Key > version).ToImmutableSortedDictionary();
Beispiel #4
0
 public void Migrate(SettingsRootStorageModel model)
 {
     _migrations.Where(p => p.Key > model.Version)
     .ForEach(p => p.Value.Invoke(model));
 }
Beispiel #5
0
        public async Task <CommandResult> Pokedex(CommandContext context)
        {
            (Optional <User> optionalUser, Optional <string> optionalMode, Optional <User> optionalCompareUser) =
                await context.ParseArgs <Optional <User>, Optional <string>, Optional <User> >();

            User user   = optionalUser.OrElse(context.Message.User);
            bool isSelf = user == context.Message.User;

            if (!optionalMode.IsPresent)
            {
                int numUniqueSpecies = (await _badgeRepo.CountByUserPerSpecies(user.Id)).Count;
                return(new CommandResult
                {
                    Response = isSelf
                        ? $"You have collected {numUniqueSpecies} distinct Pokémon badge(s)"
                        : $"{user.Name} has collected {numUniqueSpecies} distinct Pokémon badge(s)"
                });
            }

            string mode = optionalMode.Value;
            ImmutableSortedDictionary <PkmnSpecies, int> numBadgesPerSpecies =
                await _badgeRepo.CountByUserPerSpecies(user.Id);

            if (mode.Equals(PokedexModeMissing))
            {
                IEnumerable <PkmnSpecies> missingList     = _knownSpecies.Except(numBadgesPerSpecies.Keys);
                IEnumerable <string>      badgesFormatted = missingList.Select(entry => $"{entry}");
                return(new CommandResult
                {
                    Response = isSelf
                        ? $"You are currently missing the following badge(s): {string.Join(", ", badgesFormatted)}"
                        : $"{user.Name} is currently missing the following badge(s): {string.Join(", ", badgesFormatted)}",
                    ResponseTarget = ResponseTarget.WhisperIfLong
                });
            }
            else if (mode.Equals(PokedexModeDupes))
            {
                var dupeList = numBadgesPerSpecies.Where(kvp => kvp.Value > 1).ToList();
                if (!dupeList.Any())
                {
                    return(new CommandResult
                    {
                        Response = isSelf
                            ? $"You do not own any duplicate Pokémon badges"
                            : $"{user.Name} does not own any duplicate Pokémon badges"
                    });
                }
                IEnumerable <string> badgesFormatted = dupeList.Select(kvp => $"{kvp.Key}");
                return(new CommandResult
                {
                    Response = isSelf
                        ? $"You are owning duplicates of the following badge(s): {string.Join(", ", badgesFormatted)}"
                        : $"{user.Name} owns duplicates of the following badge(s): {string.Join(", ", badgesFormatted)}",
                    ResponseTarget = ResponseTarget.WhisperIfLong
                });
            }
            else if (mode.Equals(PokedexModeComplementFromDupes))
            {
                if (!optionalCompareUser.IsPresent)
                {
                    return(new CommandResult
                    {
                        Response = $"Mode {PokedexModeComplementFromDupes} requires a second user argument"
                    });
                }
                ImmutableSortedDictionary <PkmnSpecies, int> compareUser =
                    await _badgeRepo.CountByUserPerSpecies(optionalCompareUser.Value.Id);

                var compareUserDupeList = compareUser.Where(kvp => kvp.Value > 1).Select(kvp => kvp.Key);

                var differenceList = compareUserDupeList.Except(numBadgesPerSpecies.Keys).ToList();
                if (!differenceList.Any())
                {
                    return(new CommandResult
                    {
                        Response = $"{optionalCompareUser.Value.Name} does not own any duplicate Pokémon badges {user.Name} is missing"
                    });
                }
                IEnumerable <string> badgesFormatted = differenceList.Select(entry => $"{entry}");
                return(new CommandResult
                {
                    Response = $"{optionalCompareUser.Value.Name} owns the following duplicate badge(s) {user.Name} is missing: {string.Join(", ", badgesFormatted)}",
                    ResponseTarget = ResponseTarget.WhisperIfLong
                });
            }
            else if (mode.Equals(PokedexModeComplementFrom))
            {
                if (!optionalCompareUser.IsPresent)
                {
                    return(new CommandResult
                    {
                        Response = $"Mode {PokedexModeComplementFrom} requires a second user argument"
                    });
                }
                ImmutableSortedDictionary <PkmnSpecies, int> compareUser =
                    await _badgeRepo.CountByUserPerSpecies(optionalCompareUser.Value.Id);

                var differenceList = compareUser.Keys.Except(numBadgesPerSpecies.Keys).ToList();
                if (!differenceList.Any())
                {
                    return(new CommandResult
                    {
                        Response = $"{optionalCompareUser.Value.Name} does not own any Pokémon badges {user.Name} is missing"
                    });
                }
                IEnumerable <string> badgesFormatted = differenceList.Select(entry => $"{entry}");
                return(new CommandResult
                {
                    Response = $"{optionalCompareUser.Value.Name} owns the following badge(s) {user.Name} is missing: {string.Join(", ", badgesFormatted)}",
                    ResponseTarget = ResponseTarget.WhisperIfLong
                });
            }
            else if (mode.Equals(PokedexModeModes))
            {
                return(new CommandResult
                {
                    Response = $"Supported modes are '{PokedexModeDupes}': Show duplicate badges, '{PokedexModeMissing}': Show missing badges, "
                               + $"'{PokedexModeComplementFrom}' Compares missing badges from User A with owned badges from User B, "
                               + $"'{PokedexModeComplementFromDupes}' Compares missing badges from User A with owned duplicate badges from User B"
                });
            }
            return(new CommandResult
            {
                Response = $"Unsupported mode '{mode}'. Current modes supported: {PokedexModeModes}, {PokedexModeDupes}, {PokedexModeMissing}, {PokedexModeComplementFromDupes}, {PokedexModeComplementFrom}"
            });
        }
        public async Task <CommandResult> Pokedex(CommandContext context)
        {
            (Optional <User> optionalUser, Optional <string> optionalMode, Optional <User> optionalCompareUser) =
                await context.ParseArgs <Optional <User>, Optional <string>, Optional <User> >();

            User user   = optionalUser.OrElse(context.Message.User);
            bool isSelf = user == context.Message.User;

            if (!optionalMode.IsPresent)
            {
                int numUniqueSpecies = (await _badgeRepo.CountByUserPerSpecies(user.Id)).Count;
                return(new CommandResult
                {
                    Response = isSelf
                        ? $"You have collected {numUniqueSpecies} distinct Pokémon badge(s)"
                        : $"{user.Name} has collected {numUniqueSpecies} distinct Pokémon badge(s)"
                });
            }

            string mode = optionalMode.Value.ToLower();
            ImmutableSortedDictionary <PkmnSpecies, int> numBadgesPerSpecies =
                await _badgeRepo.CountByUserPerSpecies(user.Id);

            if (mode.Equals(PokedexModeMissing))
            {
                IEnumerable <PkmnSpecies> missingList     = _knownSpecies.Except(numBadgesPerSpecies.Keys);
                IEnumerable <string>      badgesFormatted = missingList.Select(entry => $"{entry}");
                return(new CommandResult
                {
                    Response = isSelf
                        ? $"You are currently missing the following badge(s): {string.Join(", ", badgesFormatted)}"
                        : $"{user.Name} is currently missing the following badge(s): {string.Join(", ", badgesFormatted)}",
                    ResponseTarget = ResponseTarget.WhisperIfLong
                });
            }
            else if (mode.Equals(PokedexModeDupes))
            {
                var dupeList = numBadgesPerSpecies.Where(kvp => kvp.Value > 1).ToList();
                if (!dupeList.Any())
                {
                    return(new CommandResult
                    {
                        Response = isSelf
                            ? $"You do not own any duplicate Pokémon badges"
                            : $"{user.Name} does not own any duplicate Pokémon badges"
                    });
                }
                IEnumerable <string> badgesFormatted = dupeList.Select(kvp => $"{kvp.Key}");
                return(new CommandResult
                {
                    Response = isSelf
                        ? $"You are owning duplicates of the following badge(s): {string.Join(", ", badgesFormatted)}"
                        : $"{user.Name} owns duplicates of the following badge(s): {string.Join(", ", badgesFormatted)}",
                    ResponseTarget = ResponseTarget.WhisperIfLong
                });
            }
            else if (mode.Equals(PokedexModeComplementFromDupes))
            {
                if (!optionalCompareUser.IsPresent)
                {
                    return(new CommandResult
                    {
                        Response = $"Mode {PokedexModeComplementFromDupes} requires a second user argument"
                    });
                }
                ImmutableSortedDictionary <PkmnSpecies, int> compareUser =
                    await _badgeRepo.CountByUserPerSpecies(optionalCompareUser.Value.Id);

                var compareUserDupeList = compareUser.Where(kvp => kvp.Value > 1).Select(kvp => kvp.Key);

                var differenceList = compareUserDupeList.Except(numBadgesPerSpecies.Keys).ToList();
                if (!differenceList.Any())
                {
                    return(new CommandResult
                    {
                        Response = $"{optionalCompareUser.Value.Name} does not own any duplicate Pokémon badges {user.Name} is missing"
                    });
                }
                IEnumerable <string> badgesFormatted = differenceList.Select(entry => $"{entry}");
                return(new CommandResult
                {
                    Response = $"{optionalCompareUser.Value.Name} owns the following duplicate badge(s) {user.Name} is missing: {string.Join(", ", badgesFormatted)}",
                    ResponseTarget = ResponseTarget.WhisperIfLong
                });
            }
            else if (mode.Equals(PokedexModeComplementFrom))
            {
                if (!optionalCompareUser.IsPresent)
                {
                    return(new CommandResult
                    {
                        Response = $"Mode {PokedexModeComplementFrom} requires a second user argument"
                    });
                }
                ImmutableSortedDictionary <PkmnSpecies, int> compareUser =
                    await _badgeRepo.CountByUserPerSpecies(optionalCompareUser.Value.Id);

                var differenceList = compareUser.Keys.Except(numBadgesPerSpecies.Keys).ToList();
                if (!differenceList.Any())
                {
                    return(new CommandResult
                    {
                        Response = $"{optionalCompareUser.Value.Name} does not own any Pokémon badges {user.Name} is missing"
                    });
                }
                IEnumerable <string> badgesFormatted = differenceList.Select(entry => $"{entry}");
                return(new CommandResult
                {
                    Response = $"{optionalCompareUser.Value.Name} owns the following badge(s) {user.Name} is missing: {string.Join(", ", badgesFormatted)}",
                    ResponseTarget = ResponseTarget.WhisperIfLong
                });
            }
            else if (_pokedexModeRegions.ContainsKey(mode))
            {
                RegionInformation regionInformation = _pokedexModeRegions[mode];
                ImmutableSortedDictionary <PkmnSpecies, int> ownedPokemons = (await _badgeRepo.CountByUserPerSpecies(user.Id));
                int userOwnedRegionCount = mode.Equals(PokedexModeNational)
                    ? ownedPokemons.Count(ownedPokemon => ownedPokemon.Key.GetGeneration() != regionInformation.Generation)
                    : ownedPokemons.Count(ownedPokemon => ownedPokemon.Key.GetGeneration() == regionInformation.Generation);
                return(new CommandResult
                {
                    Response = isSelf
                        ? $"You have collected {userOwnedRegionCount}/{regionInformation.TotalRegionCount} "
                               + $"distinct {mode[0].ToString().ToUpper() + mode[1..].ToLower()} badge(s)"