Beispiel #1
0
        public async Task HandleAsync(string rawName, string rawGender)
        {
            if (string.IsNullOrWhiteSpace(rawName) || string.IsNullOrWhiteSpace(rawGender))
            {
                await ReplyAsync(Messages.InvalidCommand);

                return;
            }

            var name = rawName.Trim();

            // Check if the cat already exists
            var existingCat = await _repository.FindByNameAsync(name);

            if (existingCat != null)
            {
                await ReplyAsync(string.Format(Messages.CatNameExistsFormat, name));

                return;
            }

            if (!Enum.TryParse(rawGender.Trim(), true, out Gender gender) || gender == Gender.None)
            {
                await ReplyAsync($"Valid genders are '{Gender.Male}' and '{Gender.Female}'");

                return;
            }

            // Check if the current owner already has a cat
            if (_currentOwner.Cat != null)
            {
                await ReplyAsync(Messages.CatAlreadyOwned);

                return;
            }

            // If there is no owner yet, generate one
            if (_currentOwner.Owner == null)
            {
                var owner = await CreateOwnerAsync(Context.Message.Author);

                await((IOwnerService)_currentOwner).SetCurrentOwner(owner);
            }

            // Generate the new cat
            var newCat = new Cat(_currentOwner.Owner.Id, name, gender);

            // Store the new cat
            _repository.Add(newCat);
            await _repository.SaveChangesAsync();

            // Track event
            _telemetryService.TrackCreateCommand(_currentOwner, newCat);

            var message  = $"{newCat.Name} happily meets {newCat.Posessive} new master\n";
            var catSheet = CatSheet.GetSheet(_currentOwner, newCat, message);

            await ReplyAsync(string.Empty, embed : catSheet);
        }
        public async Task <ResultMessage> GetOverviewAsync(ICurrentOwner currentOwner, Cat cat)
        {
            Embed embed;

            var adventureEntry = await _adventureEntryRepository.FindByCatIdAsync(cat.Id);

            if (adventureEntry != null)
            {
                var adventure = _adventureRepository.FindByAdventureRef(adventureEntry.AdventureRef);

                embed = CatSheet.GetSheet(currentOwner, cat, string.Empty, adventure, adventureEntry.End);
            }
            else
            {
                embed = CatSheet.GetSheet(currentOwner, cat);
            }

            return(new ResultMessage(string.Empty, embed));
        }