/// <summary>
        /// Creates a new template character with a given appearance.
        /// </summary>
        /// <param name="db">The database.</param>
        /// <param name="context">The context of the command.</param>
        /// <param name="characterName">The name of the new character.</param>
        /// <param name="appearance">The appearance that the new character should have.</param>
        /// <returns>A creation result which may or may not have succeeded.</returns>
        public async Task <CreateEntityResult <Character> > CreateCharacterFromAppearanceAsync
        (
            [NotNull] GlobalInfoContext db,
            [NotNull] ICommandContext context,
            [NotNull] string characterName,
            [NotNull] Appearance appearance
        )
        {
            var createCharacterResult = await CreateCharacterAsync(db, context, characterName);

            if (!createCharacterResult.IsSuccess)
            {
                return(createCharacterResult);
            }

            var newCharacter = createCharacterResult.Entity;

            newCharacter.DefaultAppearance = appearance;

            await db.SaveChangesAsync();

            var getCharacterResult = await GetUserCharacterByNameAsync(db, context, context.Message.Author, characterName);

            if (!getCharacterResult.IsSuccess)
            {
                return(CreateEntityResult <Character> .FromError(getCharacterResult));
            }

            return(CreateEntityResult <Character> .FromSuccess(getCharacterResult.Entity));
        }
        /// <summary>
        /// Creates a new dossier with the given title, summary, and data.
        /// </summary>
        /// <param name="db">The database where the dossier should be stored.</param>
        /// <param name="title">The title of the dossier.</param>
        /// <param name="summary">The summary of the dossier.</param>
        /// <returns>A creation task which may or may not have succeeded.</returns>
        public async Task <CreateEntityResult <Dossier> > CreateDossierAsync
        (
            [NotNull] GlobalInfoContext db,
            [NotNull] string title,
            [NotNull] string summary
        )
        {
            var dossier        = new Dossier();
            var setTitleResult = await SetDossierTitleAsync(db, dossier, title);

            if (!setTitleResult.IsSuccess)
            {
                return(CreateEntityResult <Dossier> .FromError(setTitleResult));
            }

            var setSummary = await SetDossierSummaryAsync(db, dossier, summary);

            if (!setSummary.IsSuccess)
            {
                return(CreateEntityResult <Dossier> .FromError(setSummary));
            }

            await db.Dossiers.AddAsync(dossier);

            await db.SaveChangesAsync();

            return(CreateEntityResult <Dossier> .FromSuccess((await GetDossierByTitleAsync(db, title)).Entity));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Adds a kink to a user's preference list.
        /// </summary>
        /// <param name="db">The database.</param>
        /// <param name="discordUser">The user.</param>
        /// <param name="kink">The kink.</param>
        /// <returns>A creation result which may or may not have succeeded.</returns>
        public async Task <CreateEntityResult <UserKink> > AddUserKinkAsync([NotNull] GlobalInfoContext db, [NotNull] IUser discordUser, Kink kink)
        {
            var user = await db.GetOrRegisterUserAsync(discordUser);

            if (user.Kinks.Any(k => k.Kink.FListID == kink.FListID))
            {
                return(CreateEntityResult <UserKink> .FromError(CommandError.MultipleMatches, "The user already has a preference for that kink."));
            }

            var userKink = UserKink.CreateFrom(kink);

            user.Kinks.Add(userKink);

            await db.SaveChangesAsync();

            return(CreateEntityResult <UserKink> .FromSuccess(userKink));
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Creates a roleplay with the given parameters.
        /// </summary>
        /// <param name="db">The database where the roleplays are stored.</param>
        /// <param name="context">The context of the command.</param>
        /// <param name="roleplayName">The name of the roleplay.</param>
        /// <param name="roleplaySummary">The summary of the roleplay.</param>
        /// <param name="isNSFW">Whether or not the roleplay is NSFW.</param>
        /// <param name="isPublic">Whether or not the roleplay is public.</param>
        /// <returns>A creation result which may or may not have been successful.</returns>
        public async Task <CreateEntityResult <Roleplay> > CreateRoleplayAsync
        (
            [NotNull] GlobalInfoContext db,
            [NotNull] SocketCommandContext context,
            [NotNull] string roleplayName,
            [NotNull] string roleplaySummary,
            bool isNSFW,
            bool isPublic)
        {
            var owner = await db.GetOrRegisterUserAsync(context.Message.Author);

            var roleplay = new Roleplay
            {
                Owner              = owner,
                ServerID           = (long)context.Guild.Id,
                IsActive           = false,
                ActiveChannelID    = (long)context.Channel.Id,
                ParticipatingUsers = new List <RoleplayParticipant>(),
                Messages           = new List <UserMessage>()
            };

            roleplay.ParticipatingUsers.Add(new RoleplayParticipant(roleplay, owner, ParticipantStatus.Joined));

            var setNameResult = await SetRoleplayNameAsync(db, context, roleplay, roleplayName);

            if (!setNameResult.IsSuccess)
            {
                return(CreateEntityResult <Roleplay> .FromError(setNameResult));
            }

            var setSummaryResult = await SetRoleplaySummaryAsync(db, roleplay, roleplaySummary);

            if (!setSummaryResult.IsSuccess)
            {
                return(CreateEntityResult <Roleplay> .FromError(setSummaryResult));
            }

            var setIsNSFWResult = await SetRoleplayIsNSFWAsync(db, roleplay, isNSFW);

            if (!setIsNSFWResult.IsSuccess)
            {
                return(CreateEntityResult <Roleplay> .FromError(setIsNSFWResult));
            }

            var setIsPublicResult = await SetRoleplayIsPublicAsync(db, roleplay, isPublic);

            if (!setIsPublicResult.IsSuccess)
            {
                return(CreateEntityResult <Roleplay> .FromError(setIsPublicResult));
            }

            await db.Roleplays.AddAsync(roleplay);

            await db.SaveChangesAsync();

            var roleplayResult = await GetUserRoleplayByNameAsync(db, context, context.Message.Author, roleplayName);

            if (!roleplayResult.IsSuccess)
            {
                return(CreateEntityResult <Roleplay> .FromError(roleplayResult));
            }

            return(CreateEntityResult <Roleplay> .FromSuccess(roleplayResult.Entity));
        }
        /// <summary>
        /// Creates a character with the given parameters.
        /// </summary>
        /// <param name="db">The database where the characters are stored.</param>
        /// <param name="context">The context of the command.</param>
        /// <param name="characterName">The name of the character.</param>
        /// <param name="characterAvatarUrl">The character's avatar url.</param>
        /// <param name="characterNickname">The nicknme that should be applied to the user when the character is active.</param>
        /// <param name="characterSummary">The summary of the character.</param>
        /// <param name="characterDescription">The full description of the character.</param>
        /// <returns>A creation result which may or may not have been successful.</returns>
        public async Task <CreateEntityResult <Character> > CreateCharacterAsync
        (
            [NotNull] GlobalInfoContext db,
            [NotNull] ICommandContext context,
            [NotNull] string characterName,
            [NotNull] string characterAvatarUrl,
            [CanBeNull] string characterNickname,
            [CanBeNull] string characterSummary,
            [CanBeNull] string characterDescription
        )
        {
            var owner = await db.GetOrRegisterUserAsync(context.Message.Author);

            var character = new Character
            {
                Owner    = owner,
                ServerID = (long)context.Guild.Id
            };

            var modifyEntityResult = await SetCharacterNameAsync(db, context, character, characterName);

            if (!modifyEntityResult.IsSuccess)
            {
                return(CreateEntityResult <Character> .FromError(modifyEntityResult));
            }

            modifyEntityResult = await SetCharacterAvatarAsync(db, character, characterAvatarUrl);

            if (!modifyEntityResult.IsSuccess)
            {
                return(CreateEntityResult <Character> .FromError(modifyEntityResult));
            }

            if (!(characterNickname is null))
            {
                modifyEntityResult = await SetCharacterNicknameAsync(db, character, characterNickname);

                if (!modifyEntityResult.IsSuccess)
                {
                    return(CreateEntityResult <Character> .FromError(modifyEntityResult));
                }
            }

            characterSummary   = characterSummary ?? "No summary set.";
            modifyEntityResult = await SetCharacterSummaryAsync(db, character, characterSummary);

            if (!modifyEntityResult.IsSuccess)
            {
                return(CreateEntityResult <Character> .FromError(modifyEntityResult));
            }

            characterDescription = characterDescription ?? "No description set.";
            modifyEntityResult   = await SetCharacterDescriptionAsync(db, character, characterDescription);

            if (!modifyEntityResult.IsSuccess)
            {
                return(CreateEntityResult <Character> .FromError(modifyEntityResult));
            }

            var defaultPronounFamilyName = this.PronounProviders.FirstOrDefault(p => p.Value is TheyPronounProvider).Value?.Family ?? new TheyPronounProvider().Family;

            modifyEntityResult = await SetCharacterPronounAsync(db, character, defaultPronounFamilyName);

            if (!modifyEntityResult.IsSuccess)
            {
                return(CreateEntityResult <Character> .FromError(modifyEntityResult));
            }

            var getDefaultAppearanceResult = await Appearance.CreateDefaultAsync(db, this.Transformations);

            if (!getDefaultAppearanceResult.IsSuccess)
            {
                return(CreateEntityResult <Character> .FromError(getDefaultAppearanceResult));
            }

            var defaultAppearance = getDefaultAppearanceResult.Entity;

            character.DefaultAppearance = defaultAppearance;
            character.CurrentAppearance = defaultAppearance;

            owner.Characters.Add(character);
            await db.Characters.AddAsync(character);

            await db.SaveChangesAsync();

            var getCharacterResult = await GetUserCharacterByNameAsync(db, context, context.Message.Author, characterName);

            if (!getCharacterResult.IsSuccess)
            {
                return(CreateEntityResult <Character> .FromError(getCharacterResult));
            }

            return(CreateEntityResult <Character> .FromSuccess(getCharacterResult.Entity));
        }