Ejemplo n.º 1
0
        /// <summary>
        /// Sets the current appearance of the given character as its default appearance.
        /// </summary>
        /// <param name="character">The character to set the default appearance of.</param>
        /// <returns>An entity modification result which may or may not have succeeded.</returns>
        public async Task <ModifyEntityResult> SetCurrentAppearanceAsDefaultForCharacterAsync
        (
            Character character
        )
        {
            // First, erase the existing default
            var getExistingDefaultAppearance = await GetOrCreateDefaultAppearanceAsync(character);

            if (getExistingDefaultAppearance.IsSuccess)
            {
                var existingDefault = getExistingDefaultAppearance.Entity;

                _database.Appearances.Remove(existingDefault);
            }

            // Then, get the existing current appearance
            var getCurrentAppearance = await GetOrCreateCurrentAppearanceAsync(character);

            if (!getCurrentAppearance.IsSuccess)
            {
                return(ModifyEntityResult.FromError(getCurrentAppearance));
            }

            var existingCurrentAppearance = getCurrentAppearance.Entity;

            // Flip the flags. Note that we don't create a new current appearance right away, because one will
            // automatically be created if one is requested.
            existingCurrentAppearance.IsDefault = true;
            existingCurrentAppearance.IsCurrent = false;

            await _database.SaveChangesAsync();

            return(ModifyEntityResult.FromSuccess());
        }
        /// <summary>
        /// Sets the public status of the roleplay, updating channel permissions if necessary.
        /// </summary>
        /// <param name="roleplay">The roleplay.</param>
        /// <param name="isPublic">Whether the roleplay is public.</param>
        /// <returns>A modification result which may or may not have succeeded.</returns>
        public async Task <ModifyEntityResult> SetRoleplayIsPublicAsync(Roleplay roleplay, bool isPublic)
        {
            var setPublic = await _roleplays.SetRoleplayIsPublicAsync(roleplay, isPublic);

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

            if (!roleplay.DedicatedChannelID.HasValue)
            {
                return(setPublic);
            }

            var guild = await _client.GetGuildAsync((ulong)roleplay.Server.DiscordID);

            if (guild is null)
            {
                return(ModifyEntityResult.FromError("Failed to get a valid guild"));
            }

            var updatePermissions = await _dedicatedChannels.UpdateParticipantPermissionsAsync(guild, roleplay);

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

            return(ModifyEntityResult.FromSuccess());
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Sets the channel category to use for dedicated roleplay channels.
        /// </summary>
        /// <param name="server">The server.</param>
        /// <param name="category">The category to use.</param>
        /// <returns>A modification result which may or may not have succeeded.</returns>
        public async Task <ModifyEntityResult> SetDedicatedChannelCategoryAsync
        (
            Server server,
            ICategoryChannel?category
        )
        {
            var getSettingsResult = await GetOrCreateServerRoleplaySettingsAsync(server);

            if (!getSettingsResult.IsSuccess)
            {
                return(ModifyEntityResult.FromError(getSettingsResult));
            }

            var settings = getSettingsResult.Entity;

            long?categoryId;

            if (category?.Id is null)
            {
                categoryId = null;
            }
            else
            {
                categoryId = (long)category.Id;
            }

            settings.DedicatedRoleplayChannelsCategory = categoryId;
            await _database.SaveChangesAsync();

            return(ModifyEntityResult.FromSuccess());
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Sets the affirmation notification channel for the given guild.
        /// </summary>
        /// <param name="guild">The guild.</param>
        /// <param name="textChannel">The channel.</param>
        /// <returns>A modification result which may or may not have succeeded.</returns>
        public async Task <ModifyEntityResult> SetAffirmationNotificationChannelAsync
        (
            IGuild guild,
            ITextChannel textChannel
        )
        {
            var getSettings = await GetOrCreateServerSettingsAsync(guild);

            if (!getSettings.IsSuccess)
            {
                return(ModifyEntityResult.FromError(getSettings));
            }

            var settings = getSettings.Entity;

            if (settings.AffirmationRequiredNotificationChannelID == (decimal?)textChannel.Id)
            {
                return(ModifyEntityResult.FromError("That's already the affirmation notification channel."));
            }

            settings.AffirmationRequiredNotificationChannelID = (long)textChannel.Id;
            await _database.SaveChangesAsync();

            return(ModifyEntityResult.FromSuccess());
        }
        /// <summary>
        /// Stops the given roleplay, disabling its dedicated channel if one exists.
        /// </summary>
        /// <param name="roleplay">The roleplay.</param>
        /// <returns>A modification result which may or may not have succeeded.</returns>
        public async Task <ModifyEntityResult> StopRoleplayAsync(Roleplay roleplay)
        {
            var stop = await _roleplays.StopRoleplayAsync(roleplay);

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

            // If the channel in question is the roleplay's dedicated channel, disable it
            if (!roleplay.DedicatedChannelID.HasValue)
            {
                return(ModifyEntityResult.FromSuccess());
            }

            var guild = await _client.GetGuildAsync((ulong)roleplay.Server.DiscordID);

            if (guild is null)
            {
                return(ModifyEntityResult.FromError("Failed to get a valid guild for the roleplay."));
            }

            var enableChannel = await _dedicatedChannels.UpdateParticipantPermissionsAsync(guild, roleplay);

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

            return(ModifyEntityResult.FromSuccess());
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Clears the affirmation notification channel for the given guild.
        /// </summary>
        /// <param name="guild">The guild.</param>
        /// <param name="ct">The cancellation token in use.</param>
        /// <returns>A modification result which may or may not have succeeded.</returns>
        public async Task <ModifyEntityResult> ClearAffirmationNotificationChannelAsync
        (
            IGuild guild,
            CancellationToken ct = default
        )
        {
            var getSettings = await GetOrCreateServerSettingsAsync(guild, ct);

            if (!getSettings.IsSuccess)
            {
                return(ModifyEntityResult.FromError(getSettings));
            }

            var settings = getSettings.Entity;

            if (settings.AffirmationRequiredNotificationChannelID is null)
            {
                return(ModifyEntityResult.FromError("There's no affirmation notification channel set."));
            }

            settings.AffirmationRequiredNotificationChannelID = null;
            await _database.SaveChangesAsync(ct);

            return(ModifyEntityResult.FromSuccess());
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Sets the contents of the given note.
        /// </summary>
        /// <param name="note">The note.</param>
        /// <param name="content">The content.</param>
        /// <returns>A modification result which may or may not have succeeded.</returns>
        public async Task <ModifyEntityResult> SetNoteContentsAsync(UserNote note, string content)
        {
            if (content.IsNullOrWhitespace())
            {
                return(ModifyEntityResult.FromError("You must provide some content for the note."));
            }

            if (content.Length > 1024)
            {
                return(ModifyEntityResult.FromError
                       (
                           "The note is too long. It can be at most 1024 characters."
                       ));
            }

            if (note.Content == content)
            {
                return(ModifyEntityResult.FromError("That's already the note's contents."));
            }

            note.Content = content;
            note.NotifyUpdate();

            await _database.SaveChangesAsync();

            return(ModifyEntityResult.FromSuccess());
        }
        /// <inheritdoc />
        public async Task <ModifyEntityResult> ClearCurrentCharacterAsync
        (
            User user,
            Server server,
            CancellationToken ct = default
        )
        {
            user   = _database.NormalizeReference(user);
            server = _database.NormalizeReference(server);

            var getCurrentCharacter = await GetCurrentCharacterAsync(user, server, ct);

            if (!getCurrentCharacter.IsSuccess)
            {
                return(ModifyEntityResult.FromError(getCurrentCharacter));
            }

            var currentCharacter = getCurrentCharacter.Entity;

            currentCharacter.IsCurrent = false;

            await _database.SaveChangesAsync(ct);

            return(ModifyEntityResult.FromSuccess());
        }
        /// <inheritdoc />
        public async Task <ModifyEntityResult> SetDefaultCharacterAsync
        (
            User user,
            Server server,
            Character character,
            CancellationToken ct = default
        )
        {
            user   = _database.NormalizeReference(user);
            server = _database.NormalizeReference(server);

            if (character.Owner != user)
            {
                return(ModifyEntityResult.FromError("The user doesn't own that character."));
            }

            var getDefaultCharacterResult = await GetDefaultCharacterAsync(user, server, ct);

            if (getDefaultCharacterResult.IsSuccess)
            {
                var currentDefault = getDefaultCharacterResult.Entity;
                if (currentDefault == character)
                {
                    return(ModifyEntityResult.FromError("That's already the user's default character."));
                }

                currentDefault.IsDefault = false;
            }

            character.IsDefault = true;
            await _database.SaveChangesAsync(ct);

            return(ModifyEntityResult.FromSuccess());
        }
        /// <summary>
        /// Sets the nickname of the given character.
        /// </summary>
        /// <param name="guildUser">The owner of the character.</param>
        /// <param name="character">The character.</param>
        /// <param name="nickname">The new nickname.</param>
        /// <param name="ct">The cancellation token in use.</param>
        /// <returns>A modification result which may or may not have succeeded.</returns>
        public async Task <ModifyEntityResult> SetCharacterNicknameAsync
        (
            IGuildUser guildUser,
            Character character,
            string nickname,
            CancellationToken ct = default
        )
        {
            var setNickname = await _characterEditor.SetCharacterNicknameAsync(character, nickname, ct);

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

            var getCurrentCharacter = await GetCurrentCharacterAsync(guildUser, ct);

            if (!getCurrentCharacter.IsSuccess)
            {
                return(ModifyEntityResult.FromSuccess());
            }

            var currentCharacter = getCurrentCharacter.Entity;

            if (currentCharacter != character)
            {
                return(ModifyEntityResult.FromSuccess());
            }

            return(await UpdateUserNickname(guildUser, ct));
        }
        /// <summary>
        /// Transfers ownership of the given character to the specified user.
        /// </summary>
        /// <param name="newOwner">The new owner.</param>
        /// <param name="character">The character to transfer.</param>
        /// <param name="ct">The cancellation token in use.</param>
        /// <returns>A modification result which may or may not have succeeded.</returns>
        public async Task <ModifyEntityResult> TransferCharacterOwnershipAsync
        (
            IGuildUser newOwner,
            Character character,
            CancellationToken ct = default
        )
        {
            var getUser = await _users.GetOrRegisterUserAsync(newOwner, ct);

            if (!getUser.IsSuccess)
            {
                return(ModifyEntityResult.FromError(getUser));
            }

            var getServer = await _servers.GetOrRegisterServerAsync(newOwner.Guild, ct);

            if (!getServer.IsSuccess)
            {
                return(ModifyEntityResult.FromError(getServer));
            }

            var user   = getUser.Entity;
            var server = getServer.Entity;

            return(await _characters.TransferCharacterOwnershipAsync(user, server, character, ct));
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Sets the warning threshold for the given server.
        /// </summary>
        /// <param name="guild">The server.</param>
        /// <param name="warningThreshold">The warning threshold.</param>
        /// <returns>A modification result which may or may not have succeeded.</returns>
        public async Task <ModifyEntityResult> SetWarningThresholdAsync
        (
            IGuild guild,
            int warningThreshold
        )
        {
            var getSettings = await GetOrCreateServerSettingsAsync(guild);

            if (!getSettings.IsSuccess)
            {
                return(ModifyEntityResult.FromError(getSettings));
            }

            var settings = getSettings.Entity;

            if (settings.WarningThreshold == warningThreshold)
            {
                return(ModifyEntityResult.FromError($"The warning threshold is already {warningThreshold}."));
            }

            settings.WarningThreshold = warningThreshold;
            await _database.SaveChangesAsync();

            return(ModifyEntityResult.FromSuccess());
        }
Ejemplo n.º 13
0
        /// <summary>
        /// Sets the monitoring channel for the given server.
        /// </summary>
        /// <param name="guild">The server.</param>
        /// <param name="channel">The channel.</param>
        /// <returns>A modification result which may or may not have succeeded.</returns>
        public async Task <ModifyEntityResult> SetMonitoringChannelAsync
        (
            IGuild guild,
            ITextChannel channel
        )
        {
            var getSettings = await GetOrCreateServerSettingsAsync(guild);

            if (!getSettings.IsSuccess)
            {
                return(ModifyEntityResult.FromError(getSettings));
            }

            var settings = getSettings.Entity;

            if (settings.MonitoringChannel == (long)channel.Id)
            {
                return(ModifyEntityResult.FromError("That's already the monitoring channel."));
            }

            settings.MonitoringChannel = (long)channel.Id;
            await _database.SaveChangesAsync();

            return(ModifyEntityResult.FromSuccess());
        }
Ejemplo n.º 14
0
        /// <summary>
        /// Sets the protection type that the user has for transformations on the given server.
        /// </summary>
        /// <param name="discordUser">The user to set the protection for.</param>
        /// <param name="discordServer">The server to set the protection on.</param>
        /// <param name="protectionType">The protection type to set.</param>
        /// <returns>An entity modification result which may or may not have succeeded.</returns>
        public async Task <ModifyEntityResult> SetServerProtectionTypeAsync
        (
            IUser discordUser,
            IGuild discordServer,
            ProtectionType protectionType
        )
        {
            var getServerProtectionResult = await GetOrCreateServerUserProtectionAsync(discordUser, discordServer);

            if (!getServerProtectionResult.IsSuccess)
            {
                return(ModifyEntityResult.FromError(getServerProtectionResult));
            }

            var protection = getServerProtectionResult.Entity;

            if (protection.Type == protectionType)
            {
                return(ModifyEntityResult.FromError($"{protectionType.Humanize()} is already your current setting."));
            }

            protection.Type = protectionType;
            await _database.SaveChangesAsync();

            return(ModifyEntityResult.FromSuccess());
        }
Ejemplo n.º 15
0
        /// <summary>
        /// Explicitly affirms an autorole assignment.
        /// </summary>
        /// <param name="autorole">The autorole.</param>
        /// <param name="discordUser">The user.</param>
        /// <param name="ct">The cancellation token in use.</param>
        /// <returns>A modification result which may or may not have succeeded.</returns>
        public async Task <ModifyEntityResult> AffirmAutoroleAsync
        (
            AutoroleConfiguration autorole,
            IUser discordUser,
            CancellationToken ct = default
        )
        {
            if (!autorole.RequiresConfirmation)
            {
                return(ModifyEntityResult.FromError("The autorole doesn't require explicit affirmation."));
            }

            var getCondition = await GetOrCreateAutoroleConfirmationAsync(autorole, discordUser, ct);

            if (!getCondition.IsSuccess)
            {
                return(ModifyEntityResult.FromError(getCondition));
            }

            var condition = getCondition.Entity;

            if (condition.IsConfirmed)
            {
                return(ModifyEntityResult.FromError("The autorole assignment has already been affirmed."));
            }

            condition.IsConfirmed = true;
            await _database.SaveChangesAsync(ct);

            return(ModifyEntityResult.FromSuccess());
        }
Ejemplo n.º 16
0
        /// <inheritdoc />
        public async Task <ModifyEntityResult> SetCharacterNameAsync
        (
            Character character,
            string name,
            CancellationToken ct = default
        )
        {
            if (string.IsNullOrWhiteSpace(name))
            {
                return(ModifyEntityResult.FromError("You need to provide a name."));
            }

            if (string.Equals(character.Name, name, StringComparison.OrdinalIgnoreCase))
            {
                return(ModifyEntityResult.FromError("The character already has that name."));
            }

            if (name.Contains("\""))
            {
                return(ModifyEntityResult.FromError("The name may not contain double quotes."));
            }

            if (!await IsNameUniqueForUserAsync(character.Owner, character.Server, name, ct))
            {
                return(ModifyEntityResult.FromError("The user already has a character with that name."));
            }

            character.Name = name;
            await _database.SaveChangesAsync(ct);

            return(ModifyEntityResult.FromSuccess());
        }
Ejemplo n.º 17
0
        /// <summary>
        /// Explicitly affirms an autorole assignment for all currently qualifying users for the role.
        /// </summary>
        /// <param name="autorole">The autorole.</param>
        /// <param name="ct">The cancellation token in use.</param>
        /// <returns>A modification result which may or may not have succeeded.</returns>
        public async Task <ModifyEntityResult> AffirmAutoroleForAllAsync
        (
            AutoroleConfiguration autorole,
            CancellationToken ct = default
        )
        {
            if (!autorole.RequiresConfirmation)
            {
                return(ModifyEntityResult.FromError("The autorole doesn't require explicit affirmation."));
            }

            var qualifyingUsers = await _database.AutoroleConfirmations.ServersideQueryAsync
                                  (
                q => q
                .Where(a => a.Autorole == autorole)
                .Where(a => !a.IsConfirmed),
                ct
                                  );

            foreach (var qualifyingUser in qualifyingUsers)
            {
                qualifyingUser.IsConfirmed = true;
            }

            await _database.SaveChangesAsync(ct);

            return(ModifyEntityResult.FromSuccess());
        }
Ejemplo n.º 18
0
        /// <inheritdoc />
        public async Task <ModifyEntityResult> SetCharacterAvatarAsync
        (
            Character character,
            string avatarUrl,
            CancellationToken ct = default
        )
        {
            avatarUrl = avatarUrl.Unquote(new[] { '<', '>' });

            if (string.IsNullOrWhiteSpace(avatarUrl))
            {
                return(ModifyEntityResult.FromError("You need to provide a new avatar url."));
            }

            if (!Uri.TryCreate(avatarUrl, UriKind.Absolute, out _))
            {
                return(ModifyEntityResult.FromError("The given image URL wasn't valid."));
            }

            if (character.AvatarUrl == avatarUrl)
            {
                return(ModifyEntityResult.FromError("The character's avatar is already set to that URL."));
            }

            character.AvatarUrl = avatarUrl;
            await _database.SaveChangesAsync(ct);

            return(ModifyEntityResult.FromSuccess());
        }
Ejemplo n.º 19
0
        /// <summary>
        /// Sets the user's bio.
        /// </summary>
        /// <param name="user">The user.</param>
        /// <param name="bio">The bio.</param>
        /// <param name="ct">The cancellation token in use.</param>
        /// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
        public async Task <ModifyEntityResult> SetUserBioAsync
        (
            User user,
            string bio,
            CancellationToken ct = default
        )
        {
            if (bio.IsNullOrWhitespace())
            {
                return(ModifyEntityResult.FromError("You must provide a bio."));
            }

            if (bio.Length > 1024)
            {
                return(ModifyEntityResult.FromError("Your bio may not be longer than 1024 characters."));
            }

            if (user.Bio == bio)
            {
                return(ModifyEntityResult.FromError("That's already your bio."));
            }

            user.Bio = bio;
            await _database.SaveChangesAsync(ct);

            return(ModifyEntityResult.FromSuccess());
        }
Ejemplo n.º 20
0
        /// <inheritdoc />
        public async Task <ModifyEntityResult> SetCharacterNicknameAsync
        (
            Character character,
            string nickname,
            CancellationToken ct = default
        )
        {
            if (string.IsNullOrWhiteSpace(nickname))
            {
                return(ModifyEntityResult.FromError("You need to provide a new nickname."));
            }

            if (character.Nickname == nickname)
            {
                return(ModifyEntityResult.FromError("The character already has that nickname."));
            }

            if (nickname.Length > 32)
            {
                return(ModifyEntityResult.FromError("The nickname is too long. It can be at most 32 characters."));
            }

            character.Nickname = nickname;
            await _database.SaveChangesAsync(ct);

            return(ModifyEntityResult.FromSuccess());
        }
Ejemplo n.º 21
0
        /// <summary>
        /// Explicitly denies an autorole assignment.
        /// </summary>
        /// <param name="autorole">The autorole.</param>
        /// <param name="discordUser">The user.</param>
        /// <returns>A modification result which may or may not have succeeded.</returns>
        public async Task <ModifyEntityResult> DenyAutoroleAsync
        (
            AutoroleConfiguration autorole,
            IUser discordUser
        )
        {
            if (!autorole.RequiresConfirmation)
            {
                return(ModifyEntityResult.FromError("The autorole doesn't require explicit affirmation."));
            }

            var getCondition = await GetOrCreateAutoroleConfirmationAsync(autorole, discordUser);

            if (!getCondition.IsSuccess)
            {
                return(ModifyEntityResult.FromError(getCondition));
            }

            var condition = getCondition.Entity;

            if (condition.IsConfirmed)
            {
                return(ModifyEntityResult.FromError
                       (
                           "The autorole assignment has already been denied, or has never been affirmed."
                       ));
            }

            condition.IsConfirmed = false;
            await _database.SaveChangesAsync();

            return(ModifyEntityResult.FromSuccess());
        }
Ejemplo n.º 22
0
        /// <inheritdoc />
        public async Task <ModifyEntityResult> SetCharacterSummaryAsync
        (
            Character character,
            string summary,
            CancellationToken ct = default
        )
        {
            if (string.IsNullOrWhiteSpace(summary))
            {
                return(ModifyEntityResult.FromError("You need to provide a new summary."));
            }

            if (character.Summary == summary)
            {
                return(ModifyEntityResult.FromError("That's already the character's summary."));
            }

            if (summary.Length > 240)
            {
                return(ModifyEntityResult.FromError("The summary is too long. It can be at most 240 characters."));
            }

            character.Summary = summary;
            await _database.SaveChangesAsync(ct);

            return(ModifyEntityResult.FromSuccess());
        }
        /// <summary>
        /// Kicks the given user from the given roleplay, preventing them from joining again.
        /// </summary>
        /// <param name="roleplay">The roleplay.</param>
        /// <param name="discordUser">The user.</param>
        /// <returns>A modification result which may or may not have succeeded.</returns>
        public async Task <ModifyEntityResult> KickUserFromRoleplayAsync(Roleplay roleplay, IGuildUser discordUser)
        {
            var getUser = await _users.GetOrRegisterUserAsync(discordUser);

            if (!getUser.IsSuccess)
            {
                return(ModifyEntityResult.FromError(getUser));
            }

            var user = getUser.Entity;

            var removeUserAsync = await _roleplays.KickUserFromRoleplayAsync(roleplay, user);

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

            if (!roleplay.DedicatedChannelID.HasValue)
            {
                return(removeUserAsync);
            }

            var revoke = await _dedicatedChannels.RevokeUserAccessAsync(roleplay, discordUser);

            if (!revoke.IsSuccess)
            {
                return(ModifyEntityResult.FromError(revoke));
            }

            return(ModifyEntityResult.FromSuccess());
        }
Ejemplo n.º 24
0
        /// <inheritdoc />
        public async Task <ModifyEntityResult> SetCharacterDescriptionAsync
        (
            Character character,
            string description,
            CancellationToken ct = default
        )
        {
            if (string.IsNullOrWhiteSpace(description))
            {
                return(ModifyEntityResult.FromError("You need to provide a new description."));
            }

            if (character.Description == description)
            {
                return(ModifyEntityResult.FromError("The character already has that description."));
            }

            if (description.Length > 1000)
            {
                return(ModifyEntityResult.FromError("The description is too long. It can be at most 1000 characters."));
            }
            character.Description = description;
            await _database.SaveChangesAsync(ct);

            return(ModifyEntityResult.FromSuccess());
        }
        /// <summary>
        /// Sets the name of the roleplay, updating the name of the dedicated channel (if one exists).
        /// </summary>
        /// <param name="roleplay">The roleplay.</param>
        /// <param name="name">The new name.</param>
        /// <returns>A modification result which may or may not have succeeded.</returns>
        public async Task <ModifyEntityResult> SetRoleplayNameAsync(Roleplay roleplay, string name)
        {
            var commandModule   = _commands.Modules.First(m => m.Name == "roleplay");
            var validNameResult = _ownedEntities.IsEntityNameValid(commandModule.GetAllCommandNames(), name);

            if (!validNameResult.IsSuccess)
            {
                return(ModifyEntityResult.FromError(validNameResult));
            }

            var setName = await _roleplays.SetRoleplayNameAsync(roleplay, name);

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

            if (!roleplay.DedicatedChannelID.HasValue)
            {
                return(ModifyEntityResult.FromSuccess());
            }

            var setChannelName = await _dedicatedChannels.UpdateChannelNameAsync(roleplay);

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

            return(ModifyEntityResult.FromSuccess());
        }
Ejemplo n.º 26
0
        /// <inheritdoc />
        public async Task <ModifyEntityResult> SetCharacterPronounsAsync
        (
            Character character,
            string pronounFamily,
            CancellationToken ct = default
        )
        {
            if (pronounFamily.IsNullOrWhitespace())
            {
                return(ModifyEntityResult.FromError("You need to provide a pronoun family."));
            }

            if (character.PronounProviderFamily == pronounFamily)
            {
                return(ModifyEntityResult.FromError("The character is already using that pronoun set."));
            }

            var getPronounProviderResult = _pronouns.GetPronounProvider(pronounFamily);

            if (!getPronounProviderResult.IsSuccess)
            {
                return(ModifyEntityResult.FromError(getPronounProviderResult));
            }

            var pronounProvider = getPronounProviderResult.Entity;

            character.PronounProviderFamily = pronounProvider.Family;
            await _database.SaveChangesAsync(ct);

            return(ModifyEntityResult.FromSuccess());
        }
Ejemplo n.º 27
0
        private async Task <ModifyEntityResult> OpenCategory(string categoryName)
        {
            var getCategoryResult = _categories.Select(c => c.ToString()).BestLevenshteinMatch(categoryName, 0.75);

            if (!getCategoryResult.IsSuccess)
            {
                return(ModifyEntityResult.FromError(getCategoryResult));
            }

            if (!Enum.TryParse <KinkCategory>(getCategoryResult.Entity, true, out var category))
            {
                return(ModifyEntityResult.FromError("Could not parse kink category."));
            }

            var getKinkResult = await _kinks.GetFirstKinkWithoutPreferenceInCategoryAsync(_targetUser, category);

            if (!getKinkResult.IsSuccess)
            {
                getKinkResult = await _kinks.GetFirstKinkInCategoryAsync(category);
            }

            if (!getKinkResult.IsSuccess)
            {
                return(ModifyEntityResult.FromError(getKinkResult));
            }

            var kink = getKinkResult.Entity;

            _currentFListKinkID = (int)kink.FListID;

            _state = KinkWizardState.KinkPreference;

            return(ModifyEntityResult.FromSuccess());
        }
Ejemplo n.º 28
0
        /// <summary>
        /// Removes a condition with the given ID from the given autorole.
        /// </summary>
        /// <param name="autorole">The autorole.</param>
        /// <param name="conditionID">The ID of the condition.</param>
        /// <param name="ct">The cancellation token in use.</param>
        /// <returns>A modification which may or may not have succeeded.</returns>
        public async Task <ModifyEntityResult> RemoveConditionAsync
        (
            AutoroleConfiguration autorole,
            long conditionID,
            CancellationToken ct = default
        )
        {
            var condition = autorole.Conditions.FirstOrDefault(c => c.ID == conditionID);

            if (condition is null)
            {
                return(ModifyEntityResult.FromError("The autorole doesn't have any condition with that ID."));
            }

            if (autorole.Conditions.Count == 1 && autorole.IsEnabled)
            {
                return(ModifyEntityResult.FromError
                       (
                           "The autorole is still enabled, so it requires at least one condition to be present. " +
                           "Either disable the role, or add more conditions."
                       ));
            }

            autorole.Conditions.Remove(condition);
            await _database.SaveChangesAsync(ct);

            return(ModifyEntityResult.FromSuccess());
        }
Ejemplo n.º 29
0
        /// <summary>
        /// Sets the channel to use for archived roleplays.
        /// </summary>
        /// <param name="server">The server.</param>
        /// <param name="channel">The channel to use.</param>
        /// <returns>A modification result which may or may not have succeeded.</returns>
        public async Task <ModifyEntityResult> SetArchiveChannelAsync
        (
            Server server,
            ITextChannel?channel
        )
        {
            var getSettingsResult = await GetOrCreateServerRoleplaySettingsAsync(server);

            if (!getSettingsResult.IsSuccess)
            {
                return(ModifyEntityResult.FromError(getSettingsResult));
            }

            var settings = getSettingsResult.Entity;

            long?channelId;

            if (channel?.Id is null)
            {
                channelId = null;
            }
            else
            {
                channelId = (long)channel.Id;
            }

            settings.ArchiveChannel = channelId;
            await _database.SaveChangesAsync();

            return(ModifyEntityResult.FromSuccess());
        }
Ejemplo n.º 30
0
        /// <summary>
        /// Resets the given character's appearance to its default state.
        /// </summary>
        /// <param name="character">The character to reset.</param>
        /// <returns>An entity modification result which may or may not have succeeded.</returns>
        public async Task <ModifyEntityResult> ResetCharacterFormAsync(Character character)
        {
            var getDefaultAppearanceResult = await GetOrCreateDefaultAppearanceAsync(character);

            if (!getDefaultAppearanceResult.IsSuccess)
            {
                return(ModifyEntityResult.FromError(getDefaultAppearanceResult));
            }

            var getCurrentAppearance = await GetCurrentAppearanceAsync(character);

            if (getCurrentAppearance.IsSuccess)
            {
                // Delete the existing current appearance
                _database.Appearances.Remove(getCurrentAppearance.Entity);
            }

            // Piggyback on the get/create method to clone the default appearance
            var createNewCurrentResult = await GetOrCreateCurrentAppearanceAsync(character);

            if (!createNewCurrentResult.IsSuccess)
            {
                return(ModifyEntityResult.FromError(createNewCurrentResult));
            }

            await _database.SaveChangesAsync();

            return(ModifyEntityResult.FromSuccess());
        }