/// <summary> /// Adds the given user to the given roleplay. /// </summary> /// <param name="roleplay">The roleplay.</param> /// <param name="userID">The ID of the user.</param> /// <returns>A creation result which may or may not have succeeded.</returns> public async Task <Result <RoleplayParticipant> > AddUserToRoleplayAsync ( Roleplay roleplay, Snowflake userID ) { var getUser = await _users.GetOrRegisterUserAsync(userID); if (!getUser.IsSuccess) { return(Result <RoleplayParticipant> .FromError(getUser)); } var user = getUser.Entity; var addUserAsync = await _roleplays.AddUserToRoleplayAsync(roleplay, user); if (!addUserAsync.IsSuccess) { return(addUserAsync); } if (!roleplay.DedicatedChannelID.HasValue) { return(addUserAsync); } var updatePermissions = await _dedicatedChannels.UpdateParticipantPermissionsAsync(roleplay); return(!updatePermissions.IsSuccess ? Result <RoleplayParticipant> .FromError(updatePermissions) : addUserAsync); }
public async Task JoinRoleplayAsync([NotNull] Roleplay roleplay) { var addUserResult = await _roleplays.AddUserToRoleplayAsync(this.Context, roleplay, this.Context.Message.Author); if (!addUserResult.IsSuccess) { await _feedback.SendErrorAsync(this.Context, addUserResult.ErrorReason); return; } // Ensure the user has the correct permissions for the dedicated channel var getDedicatedChannelResult = await _roleplays.GetDedicatedRoleplayChannelAsync(this.Context.Guild, roleplay); if (getDedicatedChannelResult.IsSuccess) { var dedicatedChannel = getDedicatedChannelResult.Entity; if (roleplay.IsActive) { await _roleplays.SetDedicatedChannelWritabilityForUserAsync ( dedicatedChannel, this.Context.User, true ); await _roleplays.SetDedicatedChannelVisibilityForUserAsync ( dedicatedChannel, this.Context.User, true ); } } var roleplayOwnerUser = await this.Context.Guild.GetUserAsync((ulong)roleplay.Owner.DiscordID); await _feedback.SendConfirmationAsync(this.Context, $"Joined {roleplayOwnerUser.Mention}'s roleplay \"{roleplay.Name}\""); }